| 1 |
c@HEADER |
| 2 |
c *********************************************************************** |
| 3 |
c |
| 4 |
c AztecOO: An Object-Oriented Aztec Linear Solver Package |
| 5 |
c Copyright (2002) Sandia Corporation |
| 6 |
c |
| 7 |
c Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive |
| 8 |
c license for use of this work by or on behalf of the U.S. Government. |
| 9 |
c |
| 10 |
c Redistribution and use in source and binary forms, with or without |
| 11 |
c modification, are permitted provided that the following conditions are |
| 12 |
c met: |
| 13 |
c |
| 14 |
c 1. Redistributions of source code must retain the above copyright |
| 15 |
c notice, this list of conditions and the following disclaimer. |
| 16 |
c |
| 17 |
c 2. Redistributions in binary form must reproduce the above copyright |
| 18 |
c notice, this list of conditions and the following disclaimer in the |
| 19 |
c documentation and/or other materials provided with the distribution. |
| 20 |
c |
| 21 |
c 3. Neither the name of the Corporation nor the names of the |
| 22 |
c contributors may be used to endorse or promote products derived from |
| 23 |
c this software without specific prior written permission. |
| 24 |
c |
| 25 |
c THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY |
| 26 |
c EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 27 |
c IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 28 |
c PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE |
| 29 |
c CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 30 |
c EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 31 |
c PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 32 |
c PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 |
c LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 |
c NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 |
c SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 |
c |
| 37 |
c Questions? Contact Michael A. Heroux ([email protected]) |
| 38 |
c |
| 39 |
c *********************************************************************** |
| 40 |
c@HEADER |
| 41 |
c |
| 42 |
c----------------------------------------------------------------------c |
| 43 |
c S P A R S K I T c |
| 44 |
c----------------------------------------------------------------------c |
| 45 |
c BASIC LINEAR ALGEBRA FOR SPARSE MATRICES. BLASSM MODULE c |
| 46 |
c----------------------------------------------------------------------c |
| 47 |
c amub : computes C = A*B c |
| 48 |
c aplb : computes C = A+B c |
| 49 |
c aplb1 : computes C = A+B [Sorted version: A, B, C sorted] c |
| 50 |
c aplsb : computes C = A + s B c |
| 51 |
c aplsb1 : computes C = A+sB [Sorted version: A, B, C sorted] c |
| 52 |
c apmbt : Computes C = A +/- transp(B) c |
| 53 |
c aplsbt : Computes C = A + s * transp(B) c |
| 54 |
c diamua : Computes C = Diag * A c |
| 55 |
c amudia : Computes C = A* Diag c |
| 56 |
c aplsca : Computes A:= A + s I (s = scalar) c |
| 57 |
c apldia : Computes C = A + Diag. c |
| 58 |
c----------------------------------------------------------------------c |
| 59 |
c Note: this module still incomplete. c |
| 60 |
c----------------------------------------------------------------------c |
| 61 |
subroutine amub (nrow,ncol,job,a,ja,ia,b,jb,ib, |
| 62 |
* c,jc,ic,nzmax,iw,ierr) |
| 63 |
real*8 a(*), b(*), c(*) |
| 64 |
integer ja(*),jb(*),jc(*),ia(nrow+1),ib(*),ic(*),iw(ncol) |
| 65 |
c----------------------------------------------------------------------- |
| 66 |
c performs the matrix by matrix product C = A B |
| 67 |
c----------------------------------------------------------------------- |
| 68 |
c on entry: |
| 69 |
c --------- |
| 70 |
c nrow = integer. The row dimension of A = row dimension of C |
| 71 |
c ncol = integer. The column dimension of B = column dimension of C |
| 72 |
c job = integer. Job indicator. When job = 0, only the structure |
| 73 |
c (i.e. the arrays jc, ic) is computed and the |
| 74 |
c real values are ignored. |
| 75 |
c |
| 76 |
c a, |
| 77 |
c ja, |
| 78 |
c ia = Matrix A in compressed sparse row format. |
| 79 |
c |
| 80 |
c b, |
| 81 |
c jb, |
| 82 |
c ib = Matrix B in compressed sparse row format. |
| 83 |
c |
| 84 |
c nzmax = integer. The length of the arrays c and jc. |
| 85 |
c amub will stop if the result matrix C has a number |
| 86 |
c of elements that exceeds exceeds nzmax. See ierr. |
| 87 |
c |
| 88 |
c on return: |
| 89 |
c---------- |
| 90 |
c c, |
| 91 |
c jc, |
| 92 |
c ic = resulting matrix C in compressed sparse row sparse format. |
| 93 |
c |
| 94 |
c ierr = integer. serving as error message. |
| 95 |
c ierr = 0 means normal return, |
| 96 |
c ierr .gt. 0 means that amub stopped while computing the |
| 97 |
c i-th row of C with i=ierr, because the number |
| 98 |
c of elements in C exceeds nzmax. |
| 99 |
c |
| 100 |
c work arrays: |
| 101 |
c------------ |
| 102 |
c iw = integer work array of length equal to the number of |
| 103 |
c columns in A. |
| 104 |
c Note: |
| 105 |
c------- |
| 106 |
c The row dimension of B is not needed. However there is no checking |
| 107 |
c on the condition that ncol(A) = nrow(B). |
| 108 |
c |
| 109 |
c----------------------------------------------------------------------- |
| 110 |
real*8 scal |
| 111 |
logical values |
| 112 |
values = (job .ne. 0) |
| 113 |
len = 0 |
| 114 |
ic(1) = 1 |
| 115 |
ierr = 0 |
| 116 |
c initialize array iw. |
| 117 |
do 1 j=1, ncol |
| 118 |
iw(j) = 0 |
| 119 |
1 continue |
| 120 |
c |
| 121 |
do 500 ii=1, nrow |
| 122 |
c row i |
| 123 |
do 200 ka=ia(ii), ia(ii+1)-1 |
| 124 |
if (values) scal = a(ka) |
| 125 |
jj = ja(ka) |
| 126 |
do 100 kb=ib(jj),ib(jj+1)-1 |
| 127 |
jcol = jb(kb) |
| 128 |
jpos = iw(jcol) |
| 129 |
if (jpos .eq. 0) then |
| 130 |
len = len+1 |
| 131 |
if (len .gt. nzmax) then |
| 132 |
ierr = ii |
| 133 |
return |
| 134 |
endif |
| 135 |
jc(len) = jcol |
| 136 |
iw(jcol)= len |
| 137 |
if (values) c(len) = scal*b(kb) |
| 138 |
else |
| 139 |
if (values) c(jpos) = c(jpos) + scal*b(kb) |
| 140 |
endif |
| 141 |
100 continue |
| 142 |
200 continue |
| 143 |
do 201 k=ic(ii), len |
| 144 |
iw(jc(k)) = 0 |
| 145 |
201 continue |
| 146 |
ic(ii+1) = len+1 |
| 147 |
500 continue |
| 148 |
return |
| 149 |
c-------------end-of-amub----------------------------------------------- |
| 150 |
c----------------------------------------------------------------------- |
| 151 |
end |
| 152 |
c----------------------------------------------------------------------- |
| 153 |
subroutine aplb (nrow,ncol,job,a,ja,ia,b,jb,ib, |
| 154 |
* c,jc,ic,nzmax,iw,ierr) |
| 155 |
real*8 a(*), b(*), c(*) |
| 156 |
integer ja(*),jb(*),jc(*),ia(nrow+1),ib(nrow+1),ic(nrow+1), |
| 157 |
* iw(ncol) |
| 158 |
c----------------------------------------------------------------------- |
| 159 |
c performs the matrix sum C = A+B. |
| 160 |
c----------------------------------------------------------------------- |
| 161 |
c on entry: |
| 162 |
c --------- |
| 163 |
c nrow = integer. The row dimension of A and B |
| 164 |
c ncol = integer. The column dimension of A and B. |
| 165 |
c job = integer. Job indicator. When job = 0, only the structure |
| 166 |
c (i.e. the arrays jc, ic) is computed and the |
| 167 |
c real values are ignored. |
| 168 |
c |
| 169 |
c a, |
| 170 |
c ja, |
| 171 |
c ia = Matrix A in compressed sparse row format. |
| 172 |
c |
| 173 |
c b, |
| 174 |
c jb, |
| 175 |
c ib = Matrix B in compressed sparse row format. |
| 176 |
c |
| 177 |
c nzmax = integer. The length of the arrays c and jc. |
| 178 |
c amub will stop if the result matrix C has a number |
| 179 |
c of elements that exceeds exceeds nzmax. See ierr. |
| 180 |
c |
| 181 |
c on return: |
| 182 |
c---------- |
| 183 |
c c, |
| 184 |
c jc, |
| 185 |
c ic = resulting matrix C in compressed sparse row sparse format. |
| 186 |
c |
| 187 |
c ierr = integer. serving as error message. |
| 188 |
c ierr = 0 means normal return, |
| 189 |
c ierr .gt. 0 means that amub stopped while computing the |
| 190 |
c i-th row of C with i=ierr, because the number |
| 191 |
c of elements in C exceeds nzmax. |
| 192 |
c |
| 193 |
c work arrays: |
| 194 |
c------------ |
| 195 |
c iw = integer work array of length equal to the number of |
| 196 |
c columns in A. |
| 197 |
c |
| 198 |
c----------------------------------------------------------------------- |
| 199 |
logical values |
| 200 |
values = (job .ne. 0) |
| 201 |
ierr = 0 |
| 202 |
len = 0 |
| 203 |
ic(1) = 1 |
| 204 |
do 1 j=1, ncol |
| 205 |
iw(j) = 0 |
| 206 |
1 continue |
| 207 |
c |
| 208 |
do 500 ii=1, nrow |
| 209 |
c row i |
| 210 |
do 200 ka=ia(ii), ia(ii+1)-1 |
| 211 |
len = len+1 |
| 212 |
jcol = ja(ka) |
| 213 |
if (len .gt. nzmax) goto 999 |
| 214 |
jc(len) = jcol |
| 215 |
if (values) c(len) = a(ka) |
| 216 |
iw(jcol)= len |
| 217 |
200 continue |
| 218 |
c |
| 219 |
do 300 kb=ib(ii),ib(ii+1)-1 |
| 220 |
jcol = jb(kb) |
| 221 |
jpos = iw(jcol) |
| 222 |
if (jpos .eq. 0) then |
| 223 |
len = len+1 |
| 224 |
if (len .gt. nzmax) goto 999 |
| 225 |
jc(len) = jcol |
| 226 |
if (values) c(len) = b(kb) |
| 227 |
iw(jcol)= len |
| 228 |
else |
| 229 |
if (values) c(jpos) = c(jpos) + b(kb) |
| 230 |
endif |
| 231 |
300 continue |
| 232 |
do 301 k=ic(ii), len |
| 233 |
iw(jc(k)) = 0 |
| 234 |
301 continue |
| 235 |
ic(ii+1) = len+1 |
| 236 |
500 continue |
| 237 |
return |
| 238 |
999 ierr = ii |
| 239 |
return |
| 240 |
c------------end of aplb ----------------------------------------------- |
| 241 |
c----------------------------------------------------------------------- |
| 242 |
end |
| 243 |
c----------------------------------------------------------------------- |
| 244 |
subroutine aplb1(nrow,ncol,job,a,ja,ia,b,jb,ib,c,jc,ic,nzmax,ierr) |
| 245 |
real*8 a(*), b(*), c(*) |
| 246 |
integer ja(*),jb(*),jc(*),ia(nrow+1),ib(nrow+1),ic(nrow+1) |
| 247 |
c----------------------------------------------------------------------- |
| 248 |
c performs the matrix sum C = A+B for matrices in sorted CSR format. |
| 249 |
c the difference with aplb is that the resulting matrix is such that |
| 250 |
c the elements of each row are sorted with increasing column indices in |
| 251 |
c each row, provided the original matrices are sorted in the same way. |
| 252 |
c----------------------------------------------------------------------- |
| 253 |
c on entry: |
| 254 |
c --------- |
| 255 |
c nrow = integer. The row dimension of A and B |
| 256 |
c ncol = integer. The column dimension of A and B. |
| 257 |
c job = integer. Job indicator. When job = 0, only the structure |
| 258 |
c (i.e. the arrays jc, ic) is computed and the |
| 259 |
c real values are ignored. |
| 260 |
c |
| 261 |
c a, |
| 262 |
c ja, |
| 263 |
c ia = Matrix A in compressed sparse row format with entries sorted |
| 264 |
c |
| 265 |
c b, |
| 266 |
c jb, |
| 267 |
c ib = Matrix B in compressed sparse row format with entries sorted |
| 268 |
c ascendly in each row |
| 269 |
c |
| 270 |
c nzmax = integer. The length of the arrays c and jc. |
| 271 |
c amub will stop if the result matrix C has a number |
| 272 |
c of elements that exceeds exceeds nzmax. See ierr. |
| 273 |
c |
| 274 |
c on return: |
| 275 |
c---------- |
| 276 |
c c, |
| 277 |
c jc, |
| 278 |
c ic = resulting matrix C in compressed sparse row sparse format |
| 279 |
c with entries sorted ascendly in each row. |
| 280 |
c |
| 281 |
c ierr = integer. serving as error message. |
| 282 |
c ierr = 0 means normal return, |
| 283 |
c ierr .gt. 0 means that amub stopped while computing the |
| 284 |
c i-th row of C with i=ierr, because the number |
| 285 |
c of elements in C exceeds nzmax. |
| 286 |
c |
| 287 |
c Notes: |
| 288 |
c------- |
| 289 |
c this will not work if any of the two input matrices is not sorted |
| 290 |
c----------------------------------------------------------------------- |
| 291 |
logical values |
| 292 |
values = (job .ne. 0) |
| 293 |
ierr = 0 |
| 294 |
kc = 1 |
| 295 |
ic(1) = kc |
| 296 |
c |
| 297 |
do 6 i=1, nrow |
| 298 |
ka = ia(i) |
| 299 |
kb = ib(i) |
| 300 |
kamax = ia(i+1)-1 |
| 301 |
kbmax = ib(i+1)-1 |
| 302 |
5 continue |
| 303 |
if (ka .le. kamax) then |
| 304 |
j1 = ja(ka) |
| 305 |
else |
| 306 |
j1 = ncol+1 |
| 307 |
endif |
| 308 |
if (kb .le. kbmax) then |
| 309 |
j2 = jb(kb) |
| 310 |
else |
| 311 |
j2 = ncol+1 |
| 312 |
endif |
| 313 |
c |
| 314 |
c three cases |
| 315 |
c |
| 316 |
if (j1 .eq. j2) then |
| 317 |
if (values) c(kc) = a(ka)+b(kb) |
| 318 |
jc(kc) = j1 |
| 319 |
ka = ka+1 |
| 320 |
kb = kb+1 |
| 321 |
kc = kc+1 |
| 322 |
else if (j1 .lt. j2) then |
| 323 |
jc(kc) = j1 |
| 324 |
if (values) c(kc) = a(ka) |
| 325 |
ka = ka+1 |
| 326 |
kc = kc+1 |
| 327 |
else if (j1 .gt. j2) then |
| 328 |
jc(kc) = j2 |
| 329 |
if (values) c(kc) = b(kb) |
| 330 |
kb = kb+1 |
| 331 |
kc = kc+1 |
| 332 |
endif |
| 333 |
if (kc .gt. nzmax) goto 999 |
| 334 |
if (ka .le. kamax .or. kb .le. kbmax) goto 5 |
| 335 |
ic(i+1) = kc |
| 336 |
6 continue |
| 337 |
return |
| 338 |
999 ierr = i |
| 339 |
return |
| 340 |
c------------end-of-aplb1----------------------------------------------- |
| 341 |
c----------------------------------------------------------------------- |
| 342 |
end |
| 343 |
c----------------------------------------------------------------------- |
| 344 |
subroutine aplsb (nrow,ncol,a,ja,ia,s,b,jb,ib,c,jc,ic, |
| 345 |
* nzmax,ierr) |
| 346 |
real*8 a(*), b(*), c(*), s |
| 347 |
integer ja(*),jb(*),jc(*),ia(nrow+1),ib(nrow+1),ic(nrow+1) |
| 348 |
c----------------------------------------------------------------------- |
| 349 |
c performs the operation C = A+s B for matrices in sorted CSR format. |
| 350 |
c the difference with aplsb is that the resulting matrix is such that |
| 351 |
c the elements of each row are sorted with increasing column indices in |
| 352 |
c each row, provided the original matrices are sorted in the same way. |
| 353 |
c----------------------------------------------------------------------- |
| 354 |
c on entry: |
| 355 |
c --------- |
| 356 |
c nrow = integer. The row dimension of A and B |
| 357 |
c ncol = integer. The column dimension of A and B. |
| 358 |
c |
| 359 |
c a, |
| 360 |
c ja, |
| 361 |
c ia = Matrix A in compressed sparse row format with entries sorted |
| 362 |
c |
| 363 |
c s = real. scalar factor for B. |
| 364 |
c |
| 365 |
c b, |
| 366 |
c jb, |
| 367 |
c ib = Matrix B in compressed sparse row format with entries sorted |
| 368 |
c ascendly in each row |
| 369 |
c |
| 370 |
c nzmax = integer. The length of the arrays c and jc. |
| 371 |
c amub will stop if the result matrix C has a number |
| 372 |
c of elements that exceeds exceeds nzmax. See ierr. |
| 373 |
c |
| 374 |
c on return: |
| 375 |
c---------- |
| 376 |
c c, |
| 377 |
c jc, |
| 378 |
c ic = resulting matrix C in compressed sparse row sparse format |
| 379 |
c with entries sorted ascendly in each row. |
| 380 |
c |
| 381 |
c ierr = integer. serving as error message. |
| 382 |
c ierr = 0 means normal return, |
| 383 |
c ierr .gt. 0 means that amub stopped while computing the |
| 384 |
c i-th row of C with i=ierr, because the number |
| 385 |
c of elements in C exceeds nzmax. |
| 386 |
c |
| 387 |
c Notes: |
| 388 |
c------- |
| 389 |
c this will not work if any of the two input matrices is not sorted |
| 390 |
c----------------------------------------------------------------------- |
| 391 |
ierr = 0 |
| 392 |
kc = 1 |
| 393 |
ic(1) = kc |
| 394 |
c |
| 395 |
c the following loop does a merge of two sparse rows + adds them. |
| 396 |
c |
| 397 |
do 6 i=1, nrow |
| 398 |
ka = ia(i) |
| 399 |
kb = ib(i) |
| 400 |
kamax = ia(i+1)-1 |
| 401 |
kbmax = ib(i+1)-1 |
| 402 |
5 continue |
| 403 |
c |
| 404 |
c this is a while -- do loop -- |
| 405 |
c |
| 406 |
if (ka .le. kamax .or. kb .le. kbmax) then |
| 407 |
c |
| 408 |
if (ka .le. kamax) then |
| 409 |
j1 = ja(ka) |
| 410 |
else |
| 411 |
c take j1 large enough that always j2 .lt. j1 |
| 412 |
j1 = ncol+1 |
| 413 |
endif |
| 414 |
if (kb .le. kbmax) then |
| 415 |
j2 = jb(kb) |
| 416 |
else |
| 417 |
c similarly take j2 large enough that always j1 .lt. j2 |
| 418 |
j2 = ncol+1 |
| 419 |
endif |
| 420 |
c |
| 421 |
c three cases |
| 422 |
c |
| 423 |
if (j1 .eq. j2) then |
| 424 |
c(kc) = a(ka)+s*b(kb) |
| 425 |
jc(kc) = j1 |
| 426 |
ka = ka+1 |
| 427 |
kb = kb+1 |
| 428 |
kc = kc+1 |
| 429 |
else if (j1 .lt. j2) then |
| 430 |
jc(kc) = j1 |
| 431 |
c(kc) = a(ka) |
| 432 |
ka = ka+1 |
| 433 |
kc = kc+1 |
| 434 |
else if (j1 .gt. j2) then |
| 435 |
jc(kc) = j2 |
| 436 |
c(kc) = s*b(kb) |
| 437 |
kb = kb+1 |
| 438 |
kc = kc+1 |
| 439 |
endif |
| 440 |
if (kc .gt. nzmax) goto 999 |
| 441 |
goto 5 |
| 442 |
c |
| 443 |
c end while loop |
| 444 |
c |
| 445 |
endif |
| 446 |
ic(i+1) = kc |
| 447 |
6 continue |
| 448 |
return |
| 449 |
999 ierr = i |
| 450 |
return |
| 451 |
c------------end-of-aplsb --------------------------------------------- |
| 452 |
c----------------------------------------------------------------------- |
| 453 |
end |
| 454 |
c----------------------------------------------------------------------- |
| 455 |
subroutine aplsb1 (nrow,ncol,a,ja,ia,s,b,jb,ib,c,jc,ic, |
| 456 |
* nzmax,ierr) |
| 457 |
real*8 a(*), b(*), c(*), s |
| 458 |
integer ja(*),jb(*),jc(*),ia(nrow+1),ib(nrow+1),ic(nrow+1) |
| 459 |
c----------------------------------------------------------------------- |
| 460 |
c performs the operation C = A+s B for matrices in sorted CSR format. |
| 461 |
c the difference with aplsb is that the resulting matrix is such that |
| 462 |
c the elements of each row are sorted with increasing column indices in |
| 463 |
c each row, provided the original matrices are sorted in the same way. |
| 464 |
c----------------------------------------------------------------------- |
| 465 |
c on entry: |
| 466 |
c --------- |
| 467 |
c nrow = integer. The row dimension of A and B |
| 468 |
c ncol = integer. The column dimension of A and B. |
| 469 |
c |
| 470 |
c a, |
| 471 |
c ja, |
| 472 |
c ia = Matrix A in compressed sparse row format with entries sorted |
| 473 |
c |
| 474 |
c s = real. scalar factor for B. |
| 475 |
c |
| 476 |
c b, |
| 477 |
c jb, |
| 478 |
c ib = Matrix B in compressed sparse row format with entries sorted |
| 479 |
c ascendly in each row |
| 480 |
c |
| 481 |
c nzmax = integer. The length of the arrays c and jc. |
| 482 |
c amub will stop if the result matrix C has a number |
| 483 |
c of elements that exceeds exceeds nzmax. See ierr. |
| 484 |
c |
| 485 |
c on return: |
| 486 |
c---------- |
| 487 |
c c, |
| 488 |
c jc, |
| 489 |
c ic = resulting matrix C in compressed sparse row sparse format |
| 490 |
c with entries sorted ascendly in each row. |
| 491 |
c |
| 492 |
c ierr = integer. serving as error message. |
| 493 |
c ierr = 0 means normal return, |
| 494 |
c ierr .gt. 0 means that amub stopped while computing the |
| 495 |
c i-th row of C with i=ierr, because the number |
| 496 |
c of elements in C exceeds nzmax. |
| 497 |
c |
| 498 |
c Notes: |
| 499 |
c------- |
| 500 |
c this will not work if any of the two input matrices is not sorted |
| 501 |
c----------------------------------------------------------------------- |
| 502 |
ierr = 0 |
| 503 |
kc = 1 |
| 504 |
ic(1) = kc |
| 505 |
c |
| 506 |
c the following loop does a merge of two sparse rows + adds them. |
| 507 |
c |
| 508 |
do 6 i=1, nrow |
| 509 |
ka = ia(i) |
| 510 |
kb = ib(i) |
| 511 |
kamax = ia(i+1)-1 |
| 512 |
kbmax = ib(i+1)-1 |
| 513 |
5 continue |
| 514 |
c |
| 515 |
c this is a while -- do loop -- |
| 516 |
c |
| 517 |
if (ka .le. kamax .or. kb .le. kbmax) then |
| 518 |
c |
| 519 |
if (ka .le. kamax) then |
| 520 |
j1 = ja(ka) |
| 521 |
else |
| 522 |
c take j1 large enough that always j2 .lt. j1 |
| 523 |
j1 = ncol+1 |
| 524 |
endif |
| 525 |
if (kb .le. kbmax) then |
| 526 |
j2 = jb(kb) |
| 527 |
else |
| 528 |
c similarly take j2 large enough that always j1 .lt. j2 |
| 529 |
j2 = ncol+1 |
| 530 |
endif |
| 531 |
c |
| 532 |
c three cases |
| 533 |
c |
| 534 |
if (j1 .eq. j2) then |
| 535 |
c(kc) = a(ka)+s*b(kb) |
| 536 |
jc(kc) = j1 |
| 537 |
ka = ka+1 |
| 538 |
kb = kb+1 |
| 539 |
kc = kc+1 |
| 540 |
else if (j1 .lt. j2) then |
| 541 |
jc(kc) = j1 |
| 542 |
c(kc) = a(ka) |
| 543 |
ka = ka+1 |
| 544 |
kc = kc+1 |
| 545 |
else if (j1 .gt. j2) then |
| 546 |
jc(kc) = j2 |
| 547 |
c(kc) = s*b(kb) |
| 548 |
kb = kb+1 |
| 549 |
kc = kc+1 |
| 550 |
endif |
| 551 |
if (kc .gt. nzmax) goto 999 |
| 552 |
goto 5 |
| 553 |
c |
| 554 |
c end while loop |
| 555 |
c |
| 556 |
endif |
| 557 |
ic(i+1) = kc |
| 558 |
6 continue |
| 559 |
return |
| 560 |
999 ierr = i |
| 561 |
return |
| 562 |
c------------end-of-aplsb1 --------------------------------------------- |
| 563 |
c----------------------------------------------------------------------- |
| 564 |
end |
| 565 |
c----------------------------------------------------------------------- |
| 566 |
subroutine apmbt (nrow,ncol,job,a,ja,ia,b,jb,ib, |
| 567 |
* c,jc,ic,nzmax,iw,ierr) |
| 568 |
real*8 a(*), b(*), c(*) |
| 569 |
integer ja(*),jb(*),jc(*),ia(nrow+1),ib(ncol+1),ic(*),iw(*) |
| 570 |
c----------------------------------------------------------------------- |
| 571 |
c performs the matrix sum C = A + transp(B) or C = A - transp(B) |
| 572 |
c----------------------------------------------------------------------- |
| 573 |
c on entry: |
| 574 |
c --------- |
| 575 |
c nrow = integer. The row dimension of A and transp(B) |
| 576 |
c ncol = integer. The column dimension of A. Also the row |
| 577 |
c dimension of B. |
| 578 |
c |
| 579 |
c job = integer. if job = -1, apmbt will compute C= A - transp(B) |
| 580 |
c (structure + values) |
| 581 |
c if (job .eq. 1) it will compute C=A+transp(A) |
| 582 |
c (structure+ values) |
| 583 |
c if (job .eq. 0) it will compute the structure of |
| 584 |
c C= A+/-transp(B) only (ignoring all real values). |
| 585 |
c any other value of job will be treated as job=1 |
| 586 |
c a, |
| 587 |
c ja, |
| 588 |
c ia = Matrix A in compressed sparse row format. |
| 589 |
c |
| 590 |
c b, |
| 591 |
c jb, |
| 592 |
c ib = Matrix B in compressed sparse row format. |
| 593 |
c |
| 594 |
c nzmax = integer. The length of the arrays c, jc, and ic. |
| 595 |
c amub will stop if the result matrix C has a number |
| 596 |
c of elements that exceeds exceeds nzmax. See ierr. |
| 597 |
c |
| 598 |
c on return: |
| 599 |
c---------- |
| 600 |
c c, |
| 601 |
c jc, |
| 602 |
c ic = resulting matrix C in compressed sparse row format. |
| 603 |
c |
| 604 |
c ierr = integer. serving as error message. |
| 605 |
c ierr = 0 means normal return. |
| 606 |
c ierr = -1 means that nzmax was .lt. either the number of |
| 607 |
c nonzero elements of A or the number of nonzero elements in B. |
| 608 |
c ierr .gt. 0 means that amub stopped while computing the |
| 609 |
c i-th row of C with i=ierr, because the number |
| 610 |
c of elements in C exceeds nzmax. |
| 611 |
c |
| 612 |
c work arrays: |
| 613 |
c------------ |
| 614 |
c iw = integer work array of length at least max(ncol,nrow) |
| 615 |
c |
| 616 |
c Notes: |
| 617 |
c------- It is important to note that here all of three arrays c, ic, |
| 618 |
c and jc are assumed to be of length nnz(c). This is because |
| 619 |
c the matrix is internally converted in coordinate format. |
| 620 |
c |
| 621 |
c----------------------------------------------------------------------- |
| 622 |
logical values |
| 623 |
values = (job .ne. 0) |
| 624 |
c |
| 625 |
ierr = 0 |
| 626 |
do 1 j=1, ncol |
| 627 |
iw(j) = 0 |
| 628 |
1 continue |
| 629 |
c |
| 630 |
nnza = ia(nrow+1)-1 |
| 631 |
nnzb = ib(ncol+1)-1 |
| 632 |
len = nnzb |
| 633 |
if (nzmax .lt. nnzb .or. nzmax .lt. nnza) then |
| 634 |
ierr = -1 |
| 635 |
return |
| 636 |
endif |
| 637 |
c |
| 638 |
c trasnpose matrix b into c |
| 639 |
c |
| 640 |
ljob = 0 |
| 641 |
if (values) ljob = 1 |
| 642 |
ipos = 1 |
| 643 |
call csrcsc (ncol,ljob,ipos,b,jb,ib,c,jc,ic) |
| 644 |
c----------------------------------------------------------------------- |
| 645 |
if (job .eq. -1) then |
| 646 |
do 2 k=1,len |
| 647 |
c(k) = -c(k) |
| 648 |
2 continue |
| 649 |
endif |
| 650 |
c |
| 651 |
c--------------- main loop -------------------------------------------- |
| 652 |
c |
| 653 |
do 500 ii=1, nrow |
| 654 |
do 200 k = ic(ii),ic(ii+1)-1 |
| 655 |
iw(jc(k)) = k |
| 656 |
200 continue |
| 657 |
c----------------------------------------------------------------------- |
| 658 |
do 300 ka = ia(ii), ia(ii+1)-1 |
| 659 |
jcol = ja(ka) |
| 660 |
jpos = iw(jcol) |
| 661 |
if (jpos .eq. 0) then |
| 662 |
c |
| 663 |
c if fill-in append in coordinate format to matrix. |
| 664 |
c |
| 665 |
len = len+1 |
| 666 |
if (len .gt. nzmax) goto 999 |
| 667 |
jc(len) = jcol |
| 668 |
|
| 669 |
ic(len) = ii |
| 670 |
if (values) c(len) = a(ka) |
| 671 |
else |
| 672 |
c else do addition. |
| 673 |
if (values) c(jpos) = c(jpos) + a(ka) |
| 674 |
endif |
| 675 |
300 continue |
| 676 |
do 301 k=ic(ii), ic(ii+1)-1 |
| 677 |
iw(jc(k)) = 0 |
| 678 |
301 continue |
| 679 |
500 continue |
| 680 |
c |
| 681 |
c convert first part of matrix (without fill-ins) into coo format |
| 682 |
c |
| 683 |
ljob = 2 |
| 684 |
if (values) ljob = 3 |
| 685 |
do 501 i=1, nrow+1 |
| 686 |
iw(i) = ic(i) |
| 687 |
501 continue |
| 688 |
call csrcoo (nrow,ljob,nnzb,c,jc,iw,nnzb,c,ic,jc,ierr) |
| 689 |
c |
| 690 |
c convert the whole thing back to csr format. |
| 691 |
c |
| 692 |
ljob = 0 |
| 693 |
if (values) ljob = 1 |
| 694 |
call coicsr (nrow,len,ljob,c,jc,ic,iw) |
| 695 |
return |
| 696 |
999 ierr = ii |
| 697 |
return |
| 698 |
c--------end-of-apmbt--------------------------------------------------- |
| 699 |
c----------------------------------------------------------------------- |
| 700 |
end |
| 701 |
c----------------------------------------------------------------------- |
| 702 |
subroutine aplsbt(nrow,ncol,a,ja,ia,s,b,jb,ib, |
| 703 |
* c,jc,ic,nzmax,iw,ierr) |
| 704 |
real*8 a(*), b(*), c(*), s |
| 705 |
integer ja(*),jb(*),jc(*),ia(nrow+1),ib(ncol+1),ic(*),iw(*) |
| 706 |
c----------------------------------------------------------------------- |
| 707 |
c performs the matrix sum C = A + transp(B). |
| 708 |
c----------------------------------------------------------------------- |
| 709 |
c on entry: |
| 710 |
c --------- |
| 711 |
c nrow = integer. The row dimension of A and transp(B) |
| 712 |
c ncol = integer. The column dimension of A. Also the row |
| 713 |
c dimension of B. |
| 714 |
c |
| 715 |
c a, |
| 716 |
c ja, |
| 717 |
c ia = Matrix A in compressed sparse row format. |
| 718 |
c |
| 719 |
c s = real. scalar factor for B. |
| 720 |
c |
| 721 |
c |
| 722 |
c b, |
| 723 |
c jb, |
| 724 |
c ib = Matrix B in compressed sparse row format. |
| 725 |
c |
| 726 |
c nzmax = integer. The length of the arrays c, jc, and ic. |
| 727 |
c amub will stop if the result matrix C has a number |
| 728 |
c of elements that exceeds exceeds nzmax. See ierr. |
| 729 |
c |
| 730 |
c on return: |
| 731 |
c---------- |
| 732 |
c c, |
| 733 |
c jc, |
| 734 |
c ic = resulting matrix C in compressed sparse row format. |
| 735 |
c |
| 736 |
c ierr = integer. serving as error message. |
| 737 |
c ierr = 0 means normal return. |
| 738 |
c ierr = -1 means that nzmax was .lt. either the number of |
| 739 |
c nonzero elements of A or the number of nonzero elements in B. |
| 740 |
c ierr .gt. 0 means that amub stopped while computing the |
| 741 |
c i-th row of C with i=ierr, because the number |
| 742 |
c of elements in C exceeds nzmax. |
| 743 |
c |
| 744 |
c work arrays: |
| 745 |
c------------ |
| 746 |
c iw = integer work array of length at least max(nrow,ncol) |
| 747 |
c |
| 748 |
c Notes: |
| 749 |
c------- It is important to note that here all of three arrays c, ic, |
| 750 |
c and jc are assumed to be of length nnz(c). This is because |
| 751 |
c the matrix is internally converted in coordinate format. |
| 752 |
c |
| 753 |
c----------------------------------------------------------------------- |
| 754 |
ierr = 0 |
| 755 |
do 1 j=1, ncol |
| 756 |
iw(j) = 0 |
| 757 |
1 continue |
| 758 |
c |
| 759 |
nnza = ia(nrow+1)-1 |
| 760 |
nnzb = ib(ncol+1)-1 |
| 761 |
len = nnzb |
| 762 |
if (nzmax .lt. nnzb .or. nzmax .lt. nnza) then |
| 763 |
ierr = -1 |
| 764 |
return |
| 765 |
endif |
| 766 |
c |
| 767 |
c transpose matrix b into c |
| 768 |
c |
| 769 |
ljob = 1 |
| 770 |
ipos = 1 |
| 771 |
call csrcsc (ncol,ljob,ipos,b,jb,ib,c,jc,ic) |
| 772 |
do 2 k=1,len |
| 773 |
2 c(k) = c(k)*s |
| 774 |
c |
| 775 |
c main loop. add rows from ii = 1 to nrow. |
| 776 |
c |
| 777 |
do 500 ii=1, nrow |
| 778 |
c iw is used as a system to recognize whether there |
| 779 |
c was a nonzero element in c. |
| 780 |
do 200 k = ic(ii),ic(ii+1)-1 |
| 781 |
iw(jc(k)) = k |
| 782 |
200 continue |
| 783 |
c |
| 784 |
do 300 ka = ia(ii), ia(ii+1)-1 |
| 785 |
jcol = ja(ka) |
| 786 |
jpos = iw(jcol) |
| 787 |
if (jpos .eq. 0) then |
| 788 |
c |
| 789 |
c if fill-in append in coordinate format to matrix. |
| 790 |
c |
| 791 |
len = len+1 |
| 792 |
if (len .gt. nzmax) goto 999 |
| 793 |
jc(len) = jcol |
| 794 |
ic(len) = ii |
| 795 |
c(len) = a(ka) |
| 796 |
else |
| 797 |
c else do addition. |
| 798 |
c(jpos) = c(jpos) + a(ka) |
| 799 |
endif |
| 800 |
300 continue |
| 801 |
do 301 k=ic(ii), ic(ii+1)-1 |
| 802 |
iw(jc(k)) = 0 |
| 803 |
301 continue |
| 804 |
500 continue |
| 805 |
c |
| 806 |
c convert first part of matrix (without fill-ins) into coo format |
| 807 |
c |
| 808 |
ljob = 3 |
| 809 |
do 501 i=1, nrow+1 |
| 810 |
iw(i) = ic(i) |
| 811 |
501 continue |
| 812 |
call csrcoo (nrow,ljob,nnzb,c,jc,iw,nnzb,c,ic,jc,ierr) |
| 813 |
c |
| 814 |
c convert the whole thing back to csr format. |
| 815 |
c |
| 816 |
ljob = 1 |
| 817 |
call coicsr (nrow,len,ljob,c,jc,ic,iw) |
| 818 |
return |
| 819 |
999 ierr = ii |
| 820 |
return |
| 821 |
c--------end-of-aplsbt-------------------------------------------------- |
| 822 |
c----------------------------------------------------------------------- |
| 823 |
end |
| 824 |
c----------------------------------------------------------------------- |
| 825 |
subroutine diamua (nrow,job, a, ja, ia, diag, b, jb, ib) |
| 826 |
real*8 a(*), b(*), diag(nrow), scal |
| 827 |
integer ja(*),jb(*), ia(nrow+1),ib(nrow+1) |
| 828 |
c----------------------------------------------------------------------- |
| 829 |
c performs the matrix by matrix product B = Diag * A (in place) |
| 830 |
c----------------------------------------------------------------------- |
| 831 |
c on entry: |
| 832 |
c --------- |
| 833 |
c nrow = integer. The row dimension of A |
| 834 |
c |
| 835 |
c job = integer. job indicator. Job=0 means get array b only |
| 836 |
c job = 1 means get b, and the integer arrays ib, jb. |
| 837 |
c |
| 838 |
c a, |
| 839 |
c ja, |
| 840 |
c ia = Matrix A in compressed sparse row format. |
| 841 |
c |
| 842 |
c diag = diagonal matrix stored as a vector dig(1:n) |
| 843 |
c |
| 844 |
c on return: |
| 845 |
c---------- |
| 846 |
c |
| 847 |
c b, |
| 848 |
c jb, |
| 849 |
c ib = resulting matrix B in compressed sparse row sparse format. |
| 850 |
c |
| 851 |
c Notes: |
| 852 |
c------- |
| 853 |
c 1) The column dimension of A is not needed. |
| 854 |
c 2) algorithm in place (B can take the place of A). |
| 855 |
c in this case use job=0. |
| 856 |
c----------------------------------------------------------------- |
| 857 |
do 1 ii=1,nrow |
| 858 |
c |
| 859 |
c normalize each row |
| 860 |
c |
| 861 |
k1 = ia(ii) |
| 862 |
k2 = ia(ii+1)-1 |
| 863 |
scal = diag(ii) |
| 864 |
do 2 k=k1, k2 |
| 865 |
b(k) = a(k)*scal |
| 866 |
2 continue |
| 867 |
1 continue |
| 868 |
c |
| 869 |
if (job .eq. 0) return |
| 870 |
c |
| 871 |
do 3 ii=1, nrow+1 |
| 872 |
ib(ii) = ia(ii) |
| 873 |
3 continue |
| 874 |
do 31 k=ia(1), ia(nrow+1) -1 |
| 875 |
jb(k) = ja(k) |
| 876 |
31 continue |
| 877 |
return |
| 878 |
c----------end-of-diamua------------------------------------------------ |
| 879 |
c----------------------------------------------------------------------- |
| 880 |
end |
| 881 |
c----------------------------------------------------------------------- |
| 882 |
subroutine amudia (nrow,job, a, ja, ia, diag, b, jb, ib) |
| 883 |
real*8 a(*), b(*), diag(nrow) |
| 884 |
integer ja(*),jb(*), ia(nrow+1),ib(nrow+1) |
| 885 |
c----------------------------------------------------------------------- |
| 886 |
c performs the matrix by matrix product B = A * Diag (in place) |
| 887 |
c----------------------------------------------------------------------- |
| 888 |
c on entry: |
| 889 |
c --------- |
| 890 |
c nrow = integer. The row dimension of A |
| 891 |
c |
| 892 |
c job = integer. job indicator. Job=0 means get array b only |
| 893 |
c job = 1 means get b, and the integer arrays ib, jb. |
| 894 |
c |
| 895 |
c a, |
| 896 |
c ja, |
| 897 |
c ia = Matrix A in compressed sparse row format. |
| 898 |
c |
| 899 |
c diag = diagonal matrix stored as a vector dig(1:n) |
| 900 |
c |
| 901 |
c on return: |
| 902 |
c---------- |
| 903 |
c |
| 904 |
c b, |
| 905 |
c jb, |
| 906 |
c ib = resulting matrix B in compressed sparse row sparse format. |
| 907 |
c |
| 908 |
c Notes: |
| 909 |
c------- |
| 910 |
c 1) The column dimension of A is not needed. |
| 911 |
c 2) algorithm in place (B can take the place of A). |
| 912 |
c----------------------------------------------------------------- |
| 913 |
do 1 ii=1,nrow |
| 914 |
c |
| 915 |
c scale each element |
| 916 |
c |
| 917 |
k1 = ia(ii) |
| 918 |
k2 = ia(ii+1)-1 |
| 919 |
do 2 k=k1, k2 |
| 920 |
b(k) = a(k)*diag(ja(k)) |
| 921 |
2 continue |
| 922 |
1 continue |
| 923 |
c |
| 924 |
if (job .eq. 0) return |
| 925 |
c |
| 926 |
do 3 ii=1, nrow+1 |
| 927 |
ib(ii) = ia(ii) |
| 928 |
3 continue |
| 929 |
do 31 k=ia(1), ia(nrow+1) -1 |
| 930 |
jb(k) = ja(k) |
| 931 |
31 continue |
| 932 |
return |
| 933 |
c----------------------------------------------------------------------- |
| 934 |
c-----------end-of-amudiag---------------------------------------------- |
| 935 |
end |
| 936 |
c----------------------------------------------------------------------- |
| 937 |
subroutine aplsca (nrow, a, ja, ia, scal,iw) |
| 938 |
real*8 a(*), scal |
| 939 |
integer ja(*), ia(nrow+1),iw(*) |
| 940 |
c----------------------------------------------------------------------- |
| 941 |
c Adds a scalar to the diagonal entries of a sparse matrix A :=A + s I |
| 942 |
c----------------------------------------------------------------------- |
| 943 |
c on entry: |
| 944 |
c --------- |
| 945 |
c nrow = integer. The row dimension of A |
| 946 |
c |
| 947 |
c a, |
| 948 |
c ja, |
| 949 |
c ia = Matrix A in compressed sparse row format. |
| 950 |
c |
| 951 |
c scal = real. scalar to add to the diagonal entries. |
| 952 |
c |
| 953 |
c on return: |
| 954 |
c---------- |
| 955 |
c |
| 956 |
c a, |
| 957 |
c ja, |
| 958 |
c ia = matrix A with diagonal elements shifted (or created). |
| 959 |
c |
| 960 |
c iw = integer work array of length n. On return iw will |
| 961 |
c contain the positions of the diagonal entries in the |
| 962 |
c output matrix. (i.e., a(iw(k)), ja(iw(k)), k=1,...n, |
| 963 |
c are the values/column indices of the diagonal elements |
| 964 |
c of the output matrix. ). |
| 965 |
c |
| 966 |
c Notes: |
| 967 |
c------- |
| 968 |
c The column dimension of A is not needed. |
| 969 |
c important: the matrix a may be expanded slightly to allow for |
| 970 |
c additions of nonzero elements to previously nonexisting diagonals. |
| 971 |
c The is no checking as to whether there is enough space appended |
| 972 |
c to the arrays a and ja. if not sure allow for n additional |
| 973 |
c elemnts. |
| 974 |
c coded by Y. Saad. Latest version July, 19, 1990 |
| 975 |
c----------------------------------------------------------------------- |
| 976 |
logical test |
| 977 |
c |
| 978 |
call diapos (nrow,ja,ia,iw) |
| 979 |
icount = 0 |
| 980 |
do 1 j=1, nrow |
| 981 |
if (iw(j) .eq. 0) then |
| 982 |
icount = icount+1 |
| 983 |
else |
| 984 |
a(iw(j)) = a(iw(j)) + scal |
| 985 |
endif |
| 986 |
1 continue |
| 987 |
c |
| 988 |
c if no diagonal elements to insert in data structure return. |
| 989 |
c |
| 990 |
if (icount .eq. 0) return |
| 991 |
c |
| 992 |
c shift the nonzero elements if needed, to allow for created |
| 993 |
c diagonal elements. |
| 994 |
c |
| 995 |
ko = ia(nrow+1)+icount |
| 996 |
c |
| 997 |
c copy rows backward |
| 998 |
c |
| 999 |
do 5 ii=nrow, 1, -1 |
| 1000 |
c |
| 1001 |
c go through row ii |
| 1002 |
c |
| 1003 |
k1 = ia(ii) |
| 1004 |
k2 = ia(ii+1)-1 |
| 1005 |
ia(ii+1) = ko |
| 1006 |
test = (iw(ii) .eq. 0) |
| 1007 |
do 4 k = k2,k1,-1 |
| 1008 |
j = ja(k) |
| 1009 |
if (test .and. (j .lt. ii)) then |
| 1010 |
test = .false. |
| 1011 |
ko = ko - 1 |
| 1012 |
a(ko) = scal |
| 1013 |
ja(ko) = ii |
| 1014 |
iw(ii) = ko |
| 1015 |
endif |
| 1016 |
ko = ko-1 |
| 1017 |
a(ko) = a(k) |
| 1018 |
ja(ko) = j |
| 1019 |
4 continue |
| 1020 |
c diagonal element has not been added yet. |
| 1021 |
if (test) then |
| 1022 |
ko = ko-1 |
| 1023 |
a(ko) = scal |
| 1024 |
ja(ko) = ii |
| 1025 |
iw(ii) = ko |
| 1026 |
endif |
| 1027 |
5 continue |
| 1028 |
ia(1) = ko |
| 1029 |
return |
| 1030 |
c----------------------------------------------------------------------- |
| 1031 |
c----------end-of-aplsca------------------------------------------------ |
| 1032 |
end |
| 1033 |
c----------------------------------------------------------------------- |
| 1034 |
subroutine apldia (nrow, job, a, ja, ia, diag, b, jb, ib, iw) |
| 1035 |
real*8 a(*), b(*), diag(nrow) |
| 1036 |
integer ja(*),jb(*), ia(nrow+1),ib(nrow+1), iw(*) |
| 1037 |
c----------------------------------------------------------------------- |
| 1038 |
c Adds a diagonal matrix to a general sparse matrix: B = A + Diag |
| 1039 |
c----------------------------------------------------------------------- |
| 1040 |
c on entry: |
| 1041 |
c --------- |
| 1042 |
c nrow = integer. The row dimension of A |
| 1043 |
c |
| 1044 |
c job = integer. job indicator. Job=0 means get array b only |
| 1045 |
c (i.e. assume that a has already been copied into array b, |
| 1046 |
c or that algorithm is used in place. ) For all practical |
| 1047 |
c purposes enter job=0 for an in-place call and job=1 otherwise |
| 1048 |
c |
| 1049 |
c Note: in case there are missing diagonal elements in A, |
| 1050 |
c then the option job =0 will be ignored, since the algorithm |
| 1051 |
c must modify the data structure (i.e. jb, ib) in this |
| 1052 |
c situation. |
| 1053 |
c |
| 1054 |
c a, |
| 1055 |
c ja, |
| 1056 |
c ia = Matrix A in compressed sparse row format. |
| 1057 |
c |
| 1058 |
c diag = diagonal matrix stored as a vector dig(1:n) |
| 1059 |
c |
| 1060 |
c on return: |
| 1061 |
c---------- |
| 1062 |
c |
| 1063 |
c b, |
| 1064 |
c jb, |
| 1065 |
c ib = resulting matrix B in compressed sparse row sparse format. |
| 1066 |
c |
| 1067 |
c |
| 1068 |
c iw = integer work array of length n. On return iw will |
| 1069 |
c contain the positions of the diagonal entries in the |
| 1070 |
c output matrix. (i.e., a(iw(k)), ja(iw(k)), k=1,...n, |
| 1071 |
c are the values/column indices of the diagonal elements |
| 1072 |
c of the output matrix. ). |
| 1073 |
c |
| 1074 |
c Notes: |
| 1075 |
c------- |
| 1076 |
c 1) The column dimension of A is not needed. |
| 1077 |
c 2) algorithm in place (b, jb, ib, can be the same as |
| 1078 |
c a, ja, ia, on entry). See comments for parameter job. |
| 1079 |
c |
| 1080 |
c coded by Y. Saad. Latest version July, 19, 1990 |
| 1081 |
c----------------------------------------------------------------- |
| 1082 |
logical test |
| 1083 |
c |
| 1084 |
c copy integer arrays into b's data structure if required |
| 1085 |
c |
| 1086 |
if (job .ne. 0) then |
| 1087 |
nnz = ia(nrow+1)-1 |
| 1088 |
do 2 k=1, nnz |
| 1089 |
jb(k) = ja(k) |
| 1090 |
b(k) = a(k) |
| 1091 |
2 continue |
| 1092 |
do 3 k=1, nrow+1 |
| 1093 |
ib(k) = ia(k) |
| 1094 |
3 continue |
| 1095 |
endif |
| 1096 |
c |
| 1097 |
c get positions of diagonal elements in data structure. |
| 1098 |
c |
| 1099 |
call diapos (nrow,ja,ia,iw) |
| 1100 |
c |
| 1101 |
c count number of holes in diagonal and add diag(*) elements to |
| 1102 |
c valid diagonal entries. |
| 1103 |
c |
| 1104 |
icount = 0 |
| 1105 |
do 1 j=1, nrow |
| 1106 |
if (iw(j) .eq. 0) then |
| 1107 |
icount = icount+1 |
| 1108 |
else |
| 1109 |
b(iw(j)) = a(iw(j)) + diag(j) |
| 1110 |
endif |
| 1111 |
1 continue |
| 1112 |
c |
| 1113 |
c if no diagonal elements to insert return |
| 1114 |
c |
| 1115 |
if (icount .eq. 0) return |
| 1116 |
c |
| 1117 |
c shift the nonzero elements if needed, to allow for created |
| 1118 |
c diagonal elements. |
| 1119 |
c |
| 1120 |
ko = ib(nrow+1)+icount |
| 1121 |
c |
| 1122 |
c copy rows backward |
| 1123 |
c |
| 1124 |
do 5 ii=nrow, 1, -1 |
| 1125 |
c |
| 1126 |
c go through row ii |
| 1127 |
c |
| 1128 |
k1 = ib(ii) |
| 1129 |
k2 = ib(ii+1)-1 |
| 1130 |
ib(ii+1) = ko |
| 1131 |
test = (iw(ii) .eq. 0) |
| 1132 |
do 4 k = k2,k1,-1 |
| 1133 |
j = jb(k) |
| 1134 |
if (test .and. (j .lt. ii)) then |
| 1135 |
test = .false. |
| 1136 |
ko = ko - 1 |
| 1137 |
b(ko) = diag(ii) |
| 1138 |
jb(ko) = ii |
| 1139 |
iw(ii) = ko |
| 1140 |
endif |
| 1141 |
ko = ko-1 |
| 1142 |
b(ko) = a(k) |
| 1143 |
jb(ko) = j |
| 1144 |
4 continue |
| 1145 |
c diagonal element has not been added yet. |
| 1146 |
if (test) then |
| 1147 |
ko = ko-1 |
| 1148 |
b(ko) = diag(ii) |
| 1149 |
jb(ko) = ii |
| 1150 |
iw(ii) = ko |
| 1151 |
endif |
| 1152 |
5 continue |
| 1153 |
ib(1) = ko |
| 1154 |
return |
| 1155 |
c----------------------------------------------------------------------- |
| 1156 |
c------------end-of-apldiag--------------------------------------------- |
| 1157 |
end |