| 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 FORMAT CONVERSION MODULE c |
| 46 |
c----------------------------------------------------------------------c |
| 47 |
c contents: c |
| 48 |
c---------- c |
| 49 |
c csrdns : converts a row-stored sparse matrix into the dense format. c |
| 50 |
c dnscsr : converts a dense matrix to a sparse storage format. c |
| 51 |
c coocsr : converts coordinate to to csr format c |
| 52 |
c coicsr : in-place conversion of coordinate to csr format c |
| 53 |
c csrcoo : converts compressed sparse row to coordinate. c |
| 54 |
c csrssr : converts compressed sparse row to symmetric sparse row c |
| 55 |
c ssrcsr : converts symmetric sparse row to compressed sparse row c |
| 56 |
c csrell : converts compressed sparse row to ellpack format c |
| 57 |
c ellcsr : converts ellpack format to compressed sparse row format c |
| 58 |
c csrmsr : converts compressed sparse row format to modified sparse c |
| 59 |
c row format c |
| 60 |
c msrcsr : converts modified sparse row format to compressed sparse c |
| 61 |
c row format. c |
| 62 |
c csrcsc : converts compressed sparse row format to compressed sparse c |
| 63 |
c column format (transposition) c |
| 64 |
c csrcsc2 : rectangular version of csrcsc c |
| 65 |
c csrlnk : converts compressed sparse row to linked list format c |
| 66 |
c lnkcsr : converts linked list format to compressed sparse row fmt c |
| 67 |
c csrdia : converts a compressed sparse row format into a diagonal c |
| 68 |
c format. c |
| 69 |
c diacsr : converts a diagonal format into a compressed sparse row c |
| 70 |
c format. c |
| 71 |
c bsrcsr : converts a block-row sparse format into a compressed c |
| 72 |
c sparse row format. c |
| 73 |
c csrbsr : converts a compressed sparse row format into a block-row c |
| 74 |
c sparse format. c |
| 75 |
c csrbnd : converts a compressed sparse row format into a banded c |
| 76 |
c format (linpack style). c |
| 77 |
c bndcsr : converts a banded format (linpack style) into a compressed c |
| 78 |
c sparse row storage. c |
| 79 |
c csrssk : converts the compressed sparse row format to the symmetric c |
| 80 |
c skyline format c |
| 81 |
c sskssr : converts symmetric skyline format to symmetric sparse row c |
| 82 |
c format. c |
| 83 |
c csrjad : converts the csr format into the jagged diagonal format c |
| 84 |
c jadcsr : converts the jagged-diagonal format into the csr format c |
| 85 |
c csruss : Compressed Sparse Row to Unsymmetric Sparse Skyline c |
| 86 |
c format c |
| 87 |
c usscsr : Unsymmetric Sparse Skyline format to Compressed Sparse Row c |
| 88 |
c csrsss : Compressed Sparse Row to Symmetric Sparse Skyline format c |
| 89 |
c ssscsr : Symmetric Sparse Skyline format to Compressed Sparse Row c |
| 90 |
c csrvbr : Converts compressed sparse row to var block row format c |
| 91 |
c vbrcsr : Converts var block row to compressed sparse row format c |
| 92 |
c csorted : Checks if matrix in CSR format is sorted by columns c |
| 93 |
c--------- miscalleneous additions not involving the csr format--------c |
| 94 |
c cooell : converts coordinate to Ellpack/Itpack format c |
| 95 |
c dcsort : sorting routine used by crsjad c |
| 96 |
c----------------------------------------------------------------------c |
| 97 |
subroutine csrdns(nrow,ncol,a,ja,ia,dns,ndns,ierr) |
| 98 |
real*8 dns(ndns,*),a(*) |
| 99 |
integer ja(*),ia(*) |
| 100 |
c----------------------------------------------------------------------- |
| 101 |
c Compressed Sparse Row to Dense |
| 102 |
c----------------------------------------------------------------------- |
| 103 |
c |
| 104 |
c converts a row-stored sparse matrix into a densely stored one |
| 105 |
c |
| 106 |
c On entry: |
| 107 |
c---------- |
| 108 |
c |
| 109 |
c nrow = row-dimension of a |
| 110 |
c ncol = column dimension of a |
| 111 |
c a, |
| 112 |
c ja, |
| 113 |
c ia = input matrix in compressed sparse row format. |
| 114 |
c (a=value array, ja=column array, ia=pointer array) |
| 115 |
c dns = array where to store dense matrix |
| 116 |
c ndns = first dimension of array dns |
| 117 |
c |
| 118 |
c on return: |
| 119 |
c----------- |
| 120 |
c dns = the sparse matrix a, ja, ia has been stored in dns(ndns,*) |
| 121 |
c |
| 122 |
c ierr = integer error indicator. |
| 123 |
c ierr .eq. 0 means normal return |
| 124 |
c ierr .eq. i means that the code has stopped when processing |
| 125 |
c row number i, because it found a column number .gt. ncol. |
| 126 |
c |
| 127 |
c----------------------------------------------------------------------- |
| 128 |
ierr = 0 |
| 129 |
do 1 i=1, nrow |
| 130 |
do 2 j=1,ncol |
| 131 |
dns(i,j) = 0.0d0 |
| 132 |
2 continue |
| 133 |
1 continue |
| 134 |
c |
| 135 |
do 4 i=1,nrow |
| 136 |
do 3 k=ia(i),ia(i+1)-1 |
| 137 |
j = ja(k) |
| 138 |
if (j .gt. ncol) then |
| 139 |
ierr = i |
| 140 |
return |
| 141 |
endif |
| 142 |
dns(i,j) = a(k) |
| 143 |
3 continue |
| 144 |
4 continue |
| 145 |
return |
| 146 |
c---- end of csrdns ---------------------------------------------------- |
| 147 |
c----------------------------------------------------------------------- |
| 148 |
end |
| 149 |
c----------------------------------------------------------------------- |
| 150 |
subroutine dnscsr(nrow,ncol,nzmax,dns,ndns,a,ja,ia,ierr) |
| 151 |
real*8 dns(ndns,*),a(*) |
| 152 |
integer ia(*),ja(*) |
| 153 |
c----------------------------------------------------------------------- |
| 154 |
c Dense to Compressed Row Sparse |
| 155 |
c----------------------------------------------------------------------- |
| 156 |
c |
| 157 |
c converts a densely stored matrix into a row orientied |
| 158 |
c compactly sparse matrix. ( reverse of csrdns ) |
| 159 |
c Note: this routine does not check whether an element |
| 160 |
c is small. It considers that a(i,j) is zero if it is exactly |
| 161 |
c equal to zero: see test below. |
| 162 |
c----------------------------------------------------------------------- |
| 163 |
c on entry: |
| 164 |
c--------- |
| 165 |
c |
| 166 |
c nrow = row-dimension of a |
| 167 |
c ncol = column dimension of a |
| 168 |
c nzmax = maximum number of nonzero elements allowed. This |
| 169 |
c should be set to be the lengths of the arrays a and ja. |
| 170 |
c dns = input nrow x ncol (dense) matrix. |
| 171 |
c ndns = first dimension of dns. |
| 172 |
c |
| 173 |
c on return: |
| 174 |
c---------- |
| 175 |
c |
| 176 |
c a, ja, ia = value, column, pointer arrays for output matrix |
| 177 |
c |
| 178 |
c ierr = integer error indicator: |
| 179 |
c ierr .eq. 0 means normal retur |
| 180 |
c ierr .eq. i means that the the code stopped while |
| 181 |
c processing row number i, because there was no space left in |
| 182 |
c a, and ja (as defined by parameter nzmax). |
| 183 |
c----------------------------------------------------------------------- |
| 184 |
ierr = 0 |
| 185 |
next = 1 |
| 186 |
ia(1) = 1 |
| 187 |
do 4 i=1,nrow |
| 188 |
do 3 j=1, ncol |
| 189 |
if (dns(i,j) .eq. 0.0d0) goto 3 |
| 190 |
if (next .gt. nzmax) then |
| 191 |
ierr = i |
| 192 |
return |
| 193 |
endif |
| 194 |
ja(next) = j |
| 195 |
a(next) = dns(i,j) |
| 196 |
next = next+1 |
| 197 |
3 continue |
| 198 |
ia(i+1) = next |
| 199 |
4 continue |
| 200 |
return |
| 201 |
c---- end of dnscsr ---------------------------------------------------- |
| 202 |
c----------------------------------------------------------------------- |
| 203 |
end |
| 204 |
c----------------------------------------------------------------------- |
| 205 |
subroutine coocsr(nrow,nnz,a,ir,jc,ao,jao,iao) |
| 206 |
c----------------------------------------------------------------------- |
| 207 |
real*8 a(*),ao(*),x |
| 208 |
integer ir(*),jc(*),jao(*),iao(*) |
| 209 |
c----------------------------------------------------------------------- |
| 210 |
c Coordinate to Compressed Sparse Row |
| 211 |
c----------------------------------------------------------------------- |
| 212 |
c converts a matrix that is stored in coordinate format |
| 213 |
c a, ir, jc into a row general sparse ao, jao, iao format. |
| 214 |
c |
| 215 |
c on entry: |
| 216 |
c--------- |
| 217 |
c nrow = dimension of the matrix |
| 218 |
c nnz = number of nonzero elements in matrix |
| 219 |
c a, |
| 220 |
c ir, |
| 221 |
c jc = matrix in coordinate format. a(k), ir(k), jc(k) store the nnz |
| 222 |
c nonzero elements of the matrix with a(k) = actual real value of |
| 223 |
c the elements, ir(k) = its row number and jc(k) = its column |
| 224 |
c number. The order of the elements is arbitrary. |
| 225 |
c |
| 226 |
c on return: |
| 227 |
c----------- |
| 228 |
c ir is destroyed |
| 229 |
c |
| 230 |
c ao, jao, iao = matrix in general sparse matrix format with ao |
| 231 |
c continung the real values, jao containing the column indices, |
| 232 |
c and iao being the pointer to the beginning of the row, |
| 233 |
c in arrays ao, jao. |
| 234 |
c |
| 235 |
c Notes: |
| 236 |
c------ This routine is NOT in place. See coicsr |
| 237 |
c |
| 238 |
c------------------------------------------------------------------------ |
| 239 |
do 1 k=1,nrow+1 |
| 240 |
iao(k) = 0 |
| 241 |
1 continue |
| 242 |
c determine row-lengths. |
| 243 |
do 2 k=1, nnz |
| 244 |
iao(ir(k)) = iao(ir(k))+1 |
| 245 |
2 continue |
| 246 |
c starting position of each row.. |
| 247 |
k = 1 |
| 248 |
do 3 j=1,nrow+1 |
| 249 |
k0 = iao(j) |
| 250 |
iao(j) = k |
| 251 |
k = k+k0 |
| 252 |
3 continue |
| 253 |
c go through the structure once more. Fill in output matrix. |
| 254 |
do 4 k=1, nnz |
| 255 |
i = ir(k) |
| 256 |
j = jc(k) |
| 257 |
x = a(k) |
| 258 |
iad = iao(i) |
| 259 |
ao(iad) = x |
| 260 |
jao(iad) = j |
| 261 |
iao(i) = iad+1 |
| 262 |
4 continue |
| 263 |
c shift back iao |
| 264 |
do 5 j=nrow,1,-1 |
| 265 |
iao(j+1) = iao(j) |
| 266 |
5 continue |
| 267 |
iao(1) = 1 |
| 268 |
return |
| 269 |
c------------- end of coocsr ------------------------------------------- |
| 270 |
c----------------------------------------------------------------------- |
| 271 |
end |
| 272 |
c----------------------------------------------------------------------- |
| 273 |
subroutine coicsr (n,nnz,job,a,ja,ia,iwk) |
| 274 |
integer ia(nnz),ja(nnz),iwk(n+1) |
| 275 |
real*8 a(*) |
| 276 |
c------------------------------------------------------------------------ |
| 277 |
c IN-PLACE coo-csr conversion routine. |
| 278 |
c------------------------------------------------------------------------ |
| 279 |
c this subroutine converts a matrix stored in coordinate format into |
| 280 |
c the csr format. The conversion is done in place in that the arrays |
| 281 |
c a,ja,ia of the result are overwritten onto the original arrays. |
| 282 |
c------------------------------------------------------------------------ |
| 283 |
c on entry: |
| 284 |
c--------- |
| 285 |
c n = integer. row dimension of A. |
| 286 |
c nnz = integer. number of nonzero elements in A. |
| 287 |
c job = integer. Job indicator. when job=1, the real values in a are |
| 288 |
c filled. Otherwise a is not touched and the structure of the |
| 289 |
c array only (i.e. ja, ia) is obtained. |
| 290 |
c a = real array of size nnz (number of nonzero elements in A) |
| 291 |
c containing the nonzero elements |
| 292 |
c ja = integer array of length nnz containing the column positions |
| 293 |
c of the corresponding elements in a. |
| 294 |
c ia = integer array of length nnz containing the row positions |
| 295 |
c of the corresponding elements in a. |
| 296 |
c iwk = integer work array of length n+1 |
| 297 |
c on return: |
| 298 |
c---------- |
| 299 |
c a |
| 300 |
c ja |
| 301 |
c ia = contains the compressed sparse row data structure for the |
| 302 |
c resulting matrix. |
| 303 |
c Note: |
| 304 |
c------- |
| 305 |
c the entries of the output matrix are not sorted (the column |
| 306 |
c indices in each are not in increasing order) use coocsr |
| 307 |
c if you want them sorted. |
| 308 |
c----------------------------------------------------------------------c |
| 309 |
c Coded by Y. Saad, Sep. 26 1989 c |
| 310 |
c----------------------------------------------------------------------c |
| 311 |
real*8 t,tnext |
| 312 |
logical values |
| 313 |
c----------------------------------------------------------------------- |
| 314 |
values = (job .eq. 1) |
| 315 |
c find pointer array for resulting matrix. |
| 316 |
do 35 i=1,n+1 |
| 317 |
iwk(i) = 0 |
| 318 |
35 continue |
| 319 |
do 4 k=1,nnz |
| 320 |
i = ia(k) |
| 321 |
iwk(i+1) = iwk(i+1)+1 |
| 322 |
4 continue |
| 323 |
c------------------------------------------------------------------------ |
| 324 |
iwk(1) = 1 |
| 325 |
do 44 i=2,n |
| 326 |
iwk(i) = iwk(i-1) + iwk(i) |
| 327 |
44 continue |
| 328 |
c |
| 329 |
c loop for a cycle in chasing process. |
| 330 |
c |
| 331 |
init = 1 |
| 332 |
k = 0 |
| 333 |
5 if (values) t = a(init) |
| 334 |
i = ia(init) |
| 335 |
j = ja(init) |
| 336 |
ia(init) = -1 |
| 337 |
c------------------------------------------------------------------------ |
| 338 |
6 k = k+1 |
| 339 |
c current row number is i. determine where to go. |
| 340 |
ipos = iwk(i) |
| 341 |
c save the chased element. |
| 342 |
if (values) tnext = a(ipos) |
| 343 |
inext = ia(ipos) |
| 344 |
jnext = ja(ipos) |
| 345 |
c then occupy its location. |
| 346 |
if (values) a(ipos) = t |
| 347 |
ja(ipos) = j |
| 348 |
c update pointer information for next element to come in row i. |
| 349 |
iwk(i) = ipos+1 |
| 350 |
c determine next element to be chased, |
| 351 |
if (ia(ipos) .lt. 0) goto 65 |
| 352 |
t = tnext |
| 353 |
i = inext |
| 354 |
j = jnext |
| 355 |
ia(ipos) = -1 |
| 356 |
if (k .lt. nnz) goto 6 |
| 357 |
goto 70 |
| 358 |
65 init = init+1 |
| 359 |
if (init .gt. nnz) goto 70 |
| 360 |
if (ia(init) .lt. 0) goto 65 |
| 361 |
c restart chasing -- |
| 362 |
goto 5 |
| 363 |
70 do 80 i=1,n |
| 364 |
ia(i+1) = iwk(i) |
| 365 |
80 continue |
| 366 |
ia(1) = 1 |
| 367 |
return |
| 368 |
c----------------- end of coicsr ---------------------------------------- |
| 369 |
c------------------------------------------------------------------------ |
| 370 |
end |
| 371 |
c----------------------------------------------------------------------- |
| 372 |
subroutine csrcoo (nrow,job,nzmax,a,ja,ia,nnz,ao,ir,jc,ierr) |
| 373 |
c----------------------------------------------------------------------- |
| 374 |
real*8 a(*),ao(*) |
| 375 |
integer ir(*),jc(*),ja(*),ia(nrow+1) |
| 376 |
c----------------------------------------------------------------------- |
| 377 |
c Compressed Sparse Row to Coordinate |
| 378 |
c----------------------------------------------------------------------- |
| 379 |
c converts a matrix that is stored in coordinate format |
| 380 |
c a, ir, jc into a row general sparse ao, jao, iao format. |
| 381 |
c |
| 382 |
c on entry: |
| 383 |
c--------- |
| 384 |
c nrow = dimension of the matrix. |
| 385 |
c job = integer serving as a job indicator. |
| 386 |
c if job = 1 fill in only the array ir, ignore jc, and ao. |
| 387 |
c if job = 2 fill in ir, and jc but not ao |
| 388 |
c if job = 3 fill in everything. |
| 389 |
c The reason why these options are provided is that on return |
| 390 |
c ao and jc are the same as a, ja. So when job = 3, a and ja are |
| 391 |
c simply copied into ao, jc. When job=2, only jc and ir are |
| 392 |
c returned. With job=1 only the array ir is returned. Moreover, |
| 393 |
c the algorithm is in place: |
| 394 |
c call csrcoo (nrow,1,nzmax,a,ja,ia,nnz,a,ia,ja,ierr) |
| 395 |
c will write the output matrix in coordinate format on a, ja,ia. |
| 396 |
c |
| 397 |
c a, |
| 398 |
c ja, |
| 399 |
c ia = matrix in compressed sparse row format. |
| 400 |
c nzmax = length of space available in ao, ir, jc. |
| 401 |
c the code will stop immediatly if the number of |
| 402 |
c nonzero elements found in input matrix exceeds nzmax. |
| 403 |
c |
| 404 |
c on return: |
| 405 |
c----------- |
| 406 |
c ao, ir, jc = matrix in coordinate format. |
| 407 |
c |
| 408 |
c nnz = number of nonzero elements in matrix. |
| 409 |
c ierr = integer error indicator. |
| 410 |
c ierr .eq. 0 means normal retur |
| 411 |
c ierr .eq. 1 means that the the code stopped |
| 412 |
c because there was no space in ao, ir, jc |
| 413 |
c (according to the value of nzmax). |
| 414 |
c |
| 415 |
c NOTES: 1)This routine is PARTIALLY in place: csrcoo can be called with |
| 416 |
c ao being the same array as as a, and jc the same array as ja. |
| 417 |
c but ir CANNOT be the same as ia. |
| 418 |
c 2) note the order in the output arrays, |
| 419 |
c------------------------------------------------------------------------ |
| 420 |
ierr = 0 |
| 421 |
nnz = ia(nrow+1)-1 |
| 422 |
if (nnz .gt. nzmax) then |
| 423 |
ierr = 1 |
| 424 |
return |
| 425 |
endif |
| 426 |
c------------------------------------------------------------------------ |
| 427 |
goto (3,2,1) job |
| 428 |
1 do 10 k=1,nnz |
| 429 |
ao(k) = a(k) |
| 430 |
10 continue |
| 431 |
2 do 11 k=1,nnz |
| 432 |
jc(k) = ja(k) |
| 433 |
11 continue |
| 434 |
c |
| 435 |
c copy backward to allow for in-place processing. |
| 436 |
c |
| 437 |
3 do 13 i=nrow,1,-1 |
| 438 |
k1 = ia(i+1)-1 |
| 439 |
k2 = ia(i) |
| 440 |
do 12 k=k1,k2,-1 |
| 441 |
ir(k) = i |
| 442 |
12 continue |
| 443 |
13 continue |
| 444 |
return |
| 445 |
c------------- end-of-csrcoo ------------------------------------------- |
| 446 |
c----------------------------------------------------------------------- |
| 447 |
end |
| 448 |
c----------------------------------------------------------------------- |
| 449 |
subroutine csrssr (nrow,a,ja,ia,nzmax,ao,jao,iao,ierr) |
| 450 |
real*8 a(*), ao(*), t |
| 451 |
integer ia(*), ja(*), iao(*), jao(*) |
| 452 |
c----------------------------------------------------------------------- |
| 453 |
c Compressed Sparse Row to Symmetric Sparse Row |
| 454 |
c----------------------------------------------------------------------- |
| 455 |
c this subroutine extracts the lower triangular part of a matrix. |
| 456 |
c It can used as a means for converting a symmetric matrix for |
| 457 |
c which all the entries are stored in sparse format into one |
| 458 |
c in which only the lower part is stored. The routine is in place in |
| 459 |
c that the output matrix ao, jao, iao can be overwritten on |
| 460 |
c the input matrix a, ja, ia if desired. Csrssr has been coded to |
| 461 |
c put the diagonal elements of the matrix in the last position in |
| 462 |
c each row (i.e. in position ao(ia(i+1)-1 of ao and jao) |
| 463 |
c----------------------------------------------------------------------- |
| 464 |
c On entry |
| 465 |
c----------- |
| 466 |
c nrow = dimension of the matrix a. |
| 467 |
c a, ja, |
| 468 |
c ia = matrix stored in compressed row sparse format |
| 469 |
c |
| 470 |
c nzmax = length of arrays ao, and jao. |
| 471 |
c |
| 472 |
c On return: |
| 473 |
c----------- |
| 474 |
c ao, jao, |
| 475 |
c iao = lower part of input matrix (a,ja,ia) stored in compressed sparse |
| 476 |
c row format format. |
| 477 |
c |
| 478 |
c ierr = integer error indicator. |
| 479 |
c ierr .eq. 0 means normal return |
| 480 |
c ierr .eq. i means that the code has stopped when processing |
| 481 |
c row number i, because there is not enough space in ao, jao |
| 482 |
c (according to the value of nzmax) |
| 483 |
c |
| 484 |
c----------------------------------------------------------------------- |
| 485 |
ierr = 0 |
| 486 |
ko = 0 |
| 487 |
c----------------------------------------------------------------------- |
| 488 |
do 7 i=1, nrow |
| 489 |
kold = ko |
| 490 |
kdiag = 0 |
| 491 |
do 71 k = ia(i), ia(i+1) -1 |
| 492 |
if (ja(k) .gt. i) goto 71 |
| 493 |
ko = ko+1 |
| 494 |
if (ko .gt. nzmax) then |
| 495 |
ierr = i |
| 496 |
return |
| 497 |
endif |
| 498 |
ao(ko) = a(k) |
| 499 |
jao(ko) = ja(k) |
| 500 |
if (ja(k) .eq. i) kdiag = ko |
| 501 |
71 continue |
| 502 |
if (kdiag .eq. 0 .or. kdiag .eq. ko) goto 72 |
| 503 |
c |
| 504 |
c exchange |
| 505 |
c |
| 506 |
t = ao(kdiag) |
| 507 |
ao(kdiag) = ao(ko) |
| 508 |
ao(ko) = t |
| 509 |
c |
| 510 |
k = jao(kdiag) |
| 511 |
jao(kdiag) = jao(ko) |
| 512 |
jao(ko) = k |
| 513 |
72 iao(i) = kold+1 |
| 514 |
7 continue |
| 515 |
c redefine iao(n+1) |
| 516 |
iao(nrow+1) = ko+1 |
| 517 |
return |
| 518 |
c--------- end of csrssr ----------------------------------------------- |
| 519 |
c----------------------------------------------------------------------- |
| 520 |
end |
| 521 |
c----------------------------------------------------------------------- |
| 522 |
subroutine ssrcsr(job, value2, nrow, a, ja, ia, nzmax, |
| 523 |
& ao, jao, iao, indu, iwk, ierr) |
| 524 |
c .. Scalar Arguments .. |
| 525 |
integer ierr, job, nrow, nzmax, value2 |
| 526 |
c .. |
| 527 |
c .. Array Arguments .. |
| 528 |
integer ia(nrow+1), iao(nrow+1), indu(nrow), |
| 529 |
& iwk(nrow+1), ja(*), jao(nzmax) |
| 530 |
real*8 a(*), ao(nzmax) |
| 531 |
c .. |
| 532 |
c----------------------------------------------------------------------- |
| 533 |
c Symmetric Sparse Row to Compressed Sparse Row format |
| 534 |
c----------------------------------------------------------------------- |
| 535 |
c This subroutine converts a given matrix in SSR format to regular |
| 536 |
c CSR format by computing Ao = A + A' - diag(A), where A' is A |
| 537 |
c transpose. |
| 538 |
c |
| 539 |
c Typically this routine is used to expand the SSR matrix of |
| 540 |
c Harwell Boeing matrices, or to obtain a symmetrized graph of |
| 541 |
c unsymmetric matrices. |
| 542 |
c |
| 543 |
c This routine is inplace, i.e., (Ao,jao,iao) may be same as |
| 544 |
c (a,ja,ia). |
| 545 |
c |
| 546 |
c It is possible to input an arbitrary CSR matrix to this routine, |
| 547 |
c since there is no syntactical difference between CSR and SSR |
| 548 |
c format. It also removes duplicate entries and perform a partial |
| 549 |
c ordering. The output matrix has an order of lower half, main |
| 550 |
c diagonal and upper half after the partial ordering. |
| 551 |
c----------------------------------------------------------------------- |
| 552 |
c on entry: |
| 553 |
c--------- |
| 554 |
c |
| 555 |
c job = options |
| 556 |
c 0 -- duplicate entries are not removed. If the input matrix is |
| 557 |
c SSR (not an arbitary CSR) matrix, no duplicate entry should |
| 558 |
c arise from this routine. |
| 559 |
c 1 -- eliminate duplicate entries, zero entries. |
| 560 |
c 2 -- eliminate duplicate entries and perform partial ordering. |
| 561 |
c 3 -- eliminate duplicate entries, sort the entries in the |
| 562 |
c increasing order of clumn indices. |
| 563 |
c |
| 564 |
c value2= will the values of A be copied? |
| 565 |
c 0 -- only expand the graph (a, ao are not touched) |
| 566 |
c 1 -- expand the matrix with the values. |
| 567 |
c |
| 568 |
c nrow = column dimension of inout matrix |
| 569 |
c a, |
| 570 |
c ia, |
| 571 |
c ja = matrix in compressed sparse row format. |
| 572 |
c |
| 573 |
c nzmax = size of arrays ao and jao. SSRCSR will abort if the storage |
| 574 |
c provided in ao, jao is not sufficient to store A. See ierr. |
| 575 |
c |
| 576 |
c on return: |
| 577 |
c---------- |
| 578 |
c ao, jao, iao |
| 579 |
c = output matrix in compressed sparse row format. The resulting |
| 580 |
c matrix is symmetric and is equal to A+A'-D. ao, jao, iao, |
| 581 |
c can be the same as a, ja, ia in the calling sequence. |
| 582 |
c |
| 583 |
c indu = integer array of length nrow. INDU will contain pointers |
| 584 |
c to the beginning of upper traigular part if job > 1. |
| 585 |
c Otherwise it is also used as a work array (size nrow). |
| 586 |
c |
| 587 |
c iwk = integer work space (size nrow+1). |
| 588 |
c |
| 589 |
c ierr = integer. Serving as error message. If the length of the arrays |
| 590 |
c ao, jao exceeds nzmax, ierr returns the minimum value |
| 591 |
c needed for nzmax. otherwise ierr=0 (normal return). |
| 592 |
c |
| 593 |
c----------------------------------------------------------------------- |
| 594 |
c .. Local Scalars .. |
| 595 |
integer i, ipos, j, k, kfirst, klast, ko, kosav, nnz |
| 596 |
real*8 tmp |
| 597 |
c .. |
| 598 |
c .. Executable Statements .. |
| 599 |
ierr = 0 |
| 600 |
do 10 i = 1, nrow |
| 601 |
indu(i) = 0 |
| 602 |
iwk(i) = 0 |
| 603 |
10 continue |
| 604 |
iwk(nrow+1) = 0 |
| 605 |
c |
| 606 |
c .. compute number of elements in each row of (A'-D) |
| 607 |
c put result in iwk(i+1) for row i. |
| 608 |
c |
| 609 |
do 30 i = 1, nrow |
| 610 |
do 20 k = ia(i), ia(i+1) - 1 |
| 611 |
j = ja(k) |
| 612 |
if (j.ne.i) |
| 613 |
& iwk(j+1) = iwk(j+1) + 1 |
| 614 |
20 continue |
| 615 |
30 continue |
| 616 |
c |
| 617 |
c .. find addresses of first elements of ouput matrix. result in iwk |
| 618 |
c |
| 619 |
iwk(1) = 1 |
| 620 |
do 40 i = 1, nrow |
| 621 |
indu(i) = iwk(i) + ia(i+1) - ia(i) |
| 622 |
iwk(i+1) = iwk(i+1) + indu(i) |
| 623 |
indu(i) = indu(i) - 1 |
| 624 |
40 continue |
| 625 |
c.....Have we been given enough storage in ao, jao ? |
| 626 |
nnz = iwk(nrow+1) - 1 |
| 627 |
if (nnz.gt.nzmax) then |
| 628 |
ierr = nnz |
| 629 |
return |
| 630 |
endif |
| 631 |
c |
| 632 |
c .. copy the existing matrix (backwards). |
| 633 |
c |
| 634 |
kosav = iwk(nrow+1) |
| 635 |
do 60 i = nrow, 1, -1 |
| 636 |
klast = ia(i+1) - 1 |
| 637 |
kfirst = ia(i) |
| 638 |
iao(i+1) = kosav |
| 639 |
kosav = iwk(i) |
| 640 |
ko = iwk(i) - kfirst |
| 641 |
iwk(i) = ko + klast + 1 |
| 642 |
do 50 k = klast, kfirst, -1 |
| 643 |
if (value2.ne.0) |
| 644 |
& ao(k+ko) = a(k) |
| 645 |
jao(k+ko) = ja(k) |
| 646 |
50 continue |
| 647 |
60 continue |
| 648 |
iao(1) = 1 |
| 649 |
c |
| 650 |
c now copy (A'-D). Go through the structure of ao, jao, iao |
| 651 |
c that has already been copied. iwk(i) is the address |
| 652 |
c of the next free location in row i for ao, jao. |
| 653 |
c |
| 654 |
do 80 i = 1, nrow |
| 655 |
do 70 k = iao(i), indu(i) |
| 656 |
j = jao(k) |
| 657 |
if (j.ne.i) then |
| 658 |
ipos = iwk(j) |
| 659 |
if (value2.ne.0) |
| 660 |
& ao(ipos) = ao(k) |
| 661 |
jao(ipos) = i |
| 662 |
iwk(j) = ipos + 1 |
| 663 |
endif |
| 664 |
70 continue |
| 665 |
80 continue |
| 666 |
if (job.le.0) return |
| 667 |
c |
| 668 |
c .. eliminate duplicate entries -- |
| 669 |
c array INDU is used as marker for existing indices, it is also the |
| 670 |
c location of the entry. |
| 671 |
c IWK is used to stored the old IAO array. |
| 672 |
c matrix is copied to squeeze out the space taken by the duplicated |
| 673 |
c entries. |
| 674 |
c |
| 675 |
do 90 i = 1, nrow |
| 676 |
indu(i) = 0 |
| 677 |
iwk(i) = iao(i) |
| 678 |
90 continue |
| 679 |
iwk(nrow+1) = iao(nrow+1) |
| 680 |
k = 1 |
| 681 |
do 120 i = 1, nrow |
| 682 |
iao(i) = k |
| 683 |
ipos = iwk(i) |
| 684 |
klast = iwk(i+1) |
| 685 |
100 if (ipos.lt.klast) then |
| 686 |
j = jao(ipos) |
| 687 |
if (indu(j).eq.0) then |
| 688 |
c .. new entry .. |
| 689 |
if (value2.ne.0) then |
| 690 |
if (ao(ipos) .ne. 0.0D0) then |
| 691 |
indu(j) = k |
| 692 |
jao(k) = jao(ipos) |
| 693 |
ao(k) = ao(ipos) |
| 694 |
k = k + 1 |
| 695 |
endif |
| 696 |
else |
| 697 |
indu(j) = k |
| 698 |
jao(k) = jao(ipos) |
| 699 |
k = k + 1 |
| 700 |
endif |
| 701 |
else if (value2.ne.0) then |
| 702 |
c .. duplicate entry .. |
| 703 |
ao(indu(j)) = ao(indu(j)) + ao(ipos) |
| 704 |
endif |
| 705 |
ipos = ipos + 1 |
| 706 |
go to 100 |
| 707 |
endif |
| 708 |
c .. remove marks before working on the next row .. |
| 709 |
do 110 ipos = iao(i), k - 1 |
| 710 |
indu(jao(ipos)) = 0 |
| 711 |
110 continue |
| 712 |
120 continue |
| 713 |
iao(nrow+1) = k |
| 714 |
if (job.le.1) return |
| 715 |
c |
| 716 |
c .. partial ordering .. |
| 717 |
c split the matrix into strict upper/lower triangular |
| 718 |
c parts, INDU points to the the beginning of the strict upper part. |
| 719 |
c |
| 720 |
do 140 i = 1, nrow |
| 721 |
klast = iao(i+1) - 1 |
| 722 |
kfirst = iao(i) |
| 723 |
130 if (klast.gt.kfirst) then |
| 724 |
if (jao(klast).lt.i .and. jao(kfirst).ge.i) then |
| 725 |
c .. swap klast with kfirst .. |
| 726 |
j = jao(klast) |
| 727 |
jao(klast) = jao(kfirst) |
| 728 |
jao(kfirst) = j |
| 729 |
if (value2.ne.0) then |
| 730 |
tmp = ao(klast) |
| 731 |
ao(klast) = ao(kfirst) |
| 732 |
ao(kfirst) = tmp |
| 733 |
endif |
| 734 |
endif |
| 735 |
if (jao(klast).ge.i) |
| 736 |
& klast = klast - 1 |
| 737 |
if (jao(kfirst).lt.i) |
| 738 |
& kfirst = kfirst + 1 |
| 739 |
go to 130 |
| 740 |
endif |
| 741 |
c |
| 742 |
if (jao(klast).lt.i) then |
| 743 |
indu(i) = klast + 1 |
| 744 |
else |
| 745 |
indu(i) = klast |
| 746 |
endif |
| 747 |
140 continue |
| 748 |
if (job.le.2) return |
| 749 |
c |
| 750 |
c .. order the entries according to column indices |
| 751 |
c bubble-sort is used |
| 752 |
c |
| 753 |
do 190 i = 1, nrow |
| 754 |
do 160 ipos = iao(i), indu(i)-1 |
| 755 |
do 150 j = indu(i)-1, ipos+1, -1 |
| 756 |
k = j - 1 |
| 757 |
if (jao(k).gt.jao(j)) then |
| 758 |
ko = jao(k) |
| 759 |
jao(k) = jao(j) |
| 760 |
jao(j) = ko |
| 761 |
if (value2.ne.0) then |
| 762 |
tmp = ao(k) |
| 763 |
ao(k) = ao(j) |
| 764 |
ao(j) = tmp |
| 765 |
endif |
| 766 |
endif |
| 767 |
150 continue |
| 768 |
160 continue |
| 769 |
do 180 ipos = indu(i), iao(i+1)-1 |
| 770 |
do 170 j = iao(i+1)-1, ipos+1, -1 |
| 771 |
k = j - 1 |
| 772 |
if (jao(k).gt.jao(j)) then |
| 773 |
ko = jao(k) |
| 774 |
jao(k) = jao(j) |
| 775 |
jao(j) = ko |
| 776 |
if (value2.ne.0) then |
| 777 |
tmp = ao(k) |
| 778 |
ao(k) = ao(j) |
| 779 |
ao(j) = tmp |
| 780 |
endif |
| 781 |
endif |
| 782 |
170 continue |
| 783 |
180 continue |
| 784 |
190 continue |
| 785 |
c |
| 786 |
return |
| 787 |
c---- end of ssrcsr ---------------------------------------------------- |
| 788 |
c----------------------------------------------------------------------- |
| 789 |
end |
| 790 |
c----------------------------------------------------------------------- |
| 791 |
subroutine xssrcsr (nrow,a,ja,ia,nzmax,ao,jao,iao,indu,ierr) |
| 792 |
integer ia(nrow+1),iao(nrow+1),ja(*),jao(nzmax),indu(nrow+1) |
| 793 |
real*8 a(*),ao(nzmax) |
| 794 |
c----------------------------------------------------------------------- |
| 795 |
c Symmetric Sparse Row to (regular) Compressed Sparse Row |
| 796 |
c----------------------------------------------------------------------- |
| 797 |
c this subroutine converts a symmetric matrix in which only the lower |
| 798 |
c part is stored in compressed sparse row format, i.e., |
| 799 |
c a matrix stored in symmetric sparse format, into a fully stored matrix |
| 800 |
c i.e., a matrix where both the lower and upper parts are stored in |
| 801 |
c compressed sparse row format. the algorithm is in place (i.e. result |
| 802 |
c may be overwritten onto the input matrix a, ja, ia ----- ). |
| 803 |
c the output matrix delivered by ssrcsr is such that each row starts with |
| 804 |
c the elements of the lower part followed by those of the upper part. |
| 805 |
c----------------------------------------------------------------------- |
| 806 |
c on entry: |
| 807 |
c--------- |
| 808 |
c |
| 809 |
c nrow = row dimension of inout matrix |
| 810 |
c a, |
| 811 |
c ia, |
| 812 |
c ja = matrix in compressed sparse row format. This is assumed to be |
| 813 |
c a lower triangular matrix. |
| 814 |
c |
| 815 |
c nzmax = size of arrays ao and jao. ssrcsr will abort if the storage |
| 816 |
c provided in a, ja is not sufficient to store A. See ierr. |
| 817 |
c |
| 818 |
c on return: |
| 819 |
c---------- |
| 820 |
c ao, iao, |
| 821 |
c jao = output matrix in compressed sparse row format. The resulting |
| 822 |
c matrix is symmetric and is equal to A+A**T - D, if |
| 823 |
c A is the original lower triangular matrix. ao, jao, iao, |
| 824 |
c can be the same as a, ja, ia in the calling sequence. |
| 825 |
c |
| 826 |
c indu = integer array of length nrow+1. If the input matrix is such |
| 827 |
c that the last element in each row is its diagonal element then |
| 828 |
c on return, indu will contain the pointers to the diagonal |
| 829 |
c element in each row of the output matrix. Otherwise used as |
| 830 |
c work array. |
| 831 |
c ierr = integer. Serving as error message. If the length of the arrays |
| 832 |
c ao, jao exceeds nzmax, ierr returns the minimum value |
| 833 |
c needed for nzmax. otherwise ierr=0 (normal return). |
| 834 |
c |
| 835 |
c----------------------------------------------------------------------- |
| 836 |
ierr = 0 |
| 837 |
do 1 i=1,nrow+1 |
| 838 |
indu(i) = 0 |
| 839 |
1 continue |
| 840 |
c |
| 841 |
c compute number of elements in each row of strict upper part. |
| 842 |
c put result in indu(i+1) for row i. |
| 843 |
c |
| 844 |
do 3 i=1, nrow |
| 845 |
do 2 k=ia(i),ia(i+1)-1 |
| 846 |
j = ja(k) |
| 847 |
if (j .lt. i) indu(j+1) = indu(j+1)+1 |
| 848 |
2 continue |
| 849 |
3 continue |
| 850 |
c----------- |
| 851 |
c find addresses of first elements of ouput matrix. result in indu |
| 852 |
c----------- |
| 853 |
indu(1) = 1 |
| 854 |
do 4 i=1,nrow |
| 855 |
lenrow = ia(i+1)-ia(i) |
| 856 |
indu(i+1) = indu(i) + indu(i+1) + lenrow |
| 857 |
4 continue |
| 858 |
c--------------------- enough storage in a, ja ? -------- |
| 859 |
nnz = indu(nrow+1)-1 |
| 860 |
if (nnz .gt. nzmax) then |
| 861 |
ierr = nnz |
| 862 |
return |
| 863 |
endif |
| 864 |
c |
| 865 |
c now copy lower part (backwards). |
| 866 |
c |
| 867 |
kosav = indu(nrow+1) |
| 868 |
do 6 i=nrow,1,-1 |
| 869 |
klast = ia(i+1)-1 |
| 870 |
kfirst = ia(i) |
| 871 |
iao(i+1) = kosav |
| 872 |
ko = indu(i) |
| 873 |
kosav = ko |
| 874 |
do 5 k = kfirst, klast |
| 875 |
ao(ko) = a(k) |
| 876 |
jao(ko) = ja(k) |
| 877 |
ko = ko+1 |
| 878 |
5 continue |
| 879 |
indu(i) = ko |
| 880 |
6 continue |
| 881 |
iao(1) = 1 |
| 882 |
c |
| 883 |
c now copy upper part. Go through the structure of ao, jao, iao |
| 884 |
c that has already been copied (lower part). indu(i) is the address |
| 885 |
c of the next free location in row i for ao, jao. |
| 886 |
c |
| 887 |
do 8 i=1,nrow |
| 888 |
c i-th row is now in ao, jao, iao structure -- lower half part |
| 889 |
do 9 k=iao(i), iao(i+1)-1 |
| 890 |
j = jao(k) |
| 891 |
if (j .ge. i) goto 8 |
| 892 |
ipos = indu(j) |
| 893 |
ao(ipos) = ao(k) |
| 894 |
jao(ipos) = i |
| 895 |
indu(j) = indu(j) + 1 |
| 896 |
9 continue |
| 897 |
8 continue |
| 898 |
return |
| 899 |
c----- end of xssrcsr -------------------------------------------------- |
| 900 |
c----------------------------------------------------------------------- |
| 901 |
end |
| 902 |
c----------------------------------------------------------------------- |
| 903 |
subroutine csrell (nrow,a,ja,ia,maxcol,coef,jcoef,ncoef, |
| 904 |
* ndiag,ierr) |
| 905 |
integer ia(nrow+1), ja(*), jcoef(ncoef,1) |
| 906 |
real*8 a(*), coef(ncoef,1) |
| 907 |
c----------------------------------------------------------------------- |
| 908 |
c Compressed Sparse Row to Ellpack - Itpack format |
| 909 |
c----------------------------------------------------------------------- |
| 910 |
c this subroutine converts matrix stored in the general a, ja, ia |
| 911 |
c format into the coef, jcoef itpack format. |
| 912 |
c |
| 913 |
c----------------------------------------------------------------------- |
| 914 |
c on entry: |
| 915 |
c---------- |
| 916 |
c nrow = row dimension of the matrix A. |
| 917 |
c |
| 918 |
c a, |
| 919 |
c ia, |
| 920 |
c ja = input matrix in compressed sparse row format. |
| 921 |
c |
| 922 |
c ncoef = first dimension of arrays coef, and jcoef. |
| 923 |
c |
| 924 |
c maxcol = integer equal to the number of columns available in coef. |
| 925 |
c |
| 926 |
c on return: |
| 927 |
c---------- |
| 928 |
c coef = real array containing the values of the matrix A in |
| 929 |
c itpack-ellpack format. |
| 930 |
c jcoef = integer array containing the column indices of coef(i,j) |
| 931 |
c in A. |
| 932 |
c ndiag = number of active 'diagonals' found. |
| 933 |
c |
| 934 |
c ierr = error message. 0 = correct return. If ierr .ne. 0 on |
| 935 |
c return this means that the number of diagonals found |
| 936 |
c (ndiag) exceeds maxcol. |
| 937 |
c |
| 938 |
c----------------------------------------------------------------------- |
| 939 |
c first determine the length of each row of lower-part-of(A) |
| 940 |
ierr = 0 |
| 941 |
ndiag = 0 |
| 942 |
do 3 i=1, nrow |
| 943 |
k = ia(i+1)-ia(i) |
| 944 |
ndiag = max0(ndiag,k) |
| 945 |
3 continue |
| 946 |
c----- check whether sufficient columns are available. ----------------- |
| 947 |
if (ndiag .gt. maxcol) then |
| 948 |
ierr = 1 |
| 949 |
return |
| 950 |
endif |
| 951 |
c |
| 952 |
c fill coef with zero elements and jcoef with row numbers.------------ |
| 953 |
c |
| 954 |
do 4 j=1,ndiag |
| 955 |
do 41 i=1,nrow |
| 956 |
coef(i,j) = 0.0d0 |
| 957 |
jcoef(i,j) = i |
| 958 |
41 continue |
| 959 |
4 continue |
| 960 |
c |
| 961 |
c------- copy elements row by row.-------------------------------------- |
| 962 |
c |
| 963 |
do 6 i=1, nrow |
| 964 |
k1 = ia(i) |
| 965 |
k2 = ia(i+1)-1 |
| 966 |
do 5 k=k1,k2 |
| 967 |
coef(i,k-k1+1) = a(k) |
| 968 |
jcoef(i,k-k1+1) = ja(k) |
| 969 |
5 continue |
| 970 |
6 continue |
| 971 |
return |
| 972 |
c--- end of csrell------------------------------------------------------ |
| 973 |
c----------------------------------------------------------------------- |
| 974 |
end |
| 975 |
c----------------------------------------------------------------------- |
| 976 |
subroutine ellcsr(nrow,coef,jcoef,ncoef,ndiag,a,ja,ia,nzmax,ierr) |
| 977 |
integer ia(nrow+1), ja(*), jcoef(ncoef,1) |
| 978 |
real*8 a(*), coef(ncoef,1) |
| 979 |
c----------------------------------------------------------------------- |
| 980 |
c Ellpack - Itpack format to Compressed Sparse Row |
| 981 |
c----------------------------------------------------------------------- |
| 982 |
c this subroutine converts a matrix stored in ellpack-itpack format |
| 983 |
c coef-jcoef into the compressed sparse row format. It actually checks |
| 984 |
c whether an entry in the input matrix is a nonzero element before |
| 985 |
c putting it in the output matrix. The test does not account for small |
| 986 |
c values but only for exact zeros. |
| 987 |
c----------------------------------------------------------------------- |
| 988 |
c on entry: |
| 989 |
c---------- |
| 990 |
c |
| 991 |
c nrow = row dimension of the matrix A. |
| 992 |
c coef = array containing the values of the matrix A in ellpack format. |
| 993 |
c jcoef = integer arraycontains the column indices of coef(i,j) in A. |
| 994 |
c ncoef = first dimension of arrays coef, and jcoef. |
| 995 |
c ndiag = number of active columns in coef, jcoef. |
| 996 |
c |
| 997 |
c ndiag = on entry the number of columns made available in coef. |
| 998 |
c |
| 999 |
c on return: |
| 1000 |
c---------- |
| 1001 |
c a, ia, |
| 1002 |
c ja = matrix in a, ia, ja format where. |
| 1003 |
c |
| 1004 |
c nzmax = size of arrays a and ja. ellcsr will abort if the storage |
| 1005 |
c provided in a, ja is not sufficient to store A. See ierr. |
| 1006 |
c |
| 1007 |
c ierr = integer. serves are output error message. |
| 1008 |
c ierr = 0 means normal return. |
| 1009 |
c ierr = 1 means that there is not enough space in |
| 1010 |
c a and ja to store output matrix. |
| 1011 |
c----------------------------------------------------------------------- |
| 1012 |
c first determine the length of each row of lower-part-of(A) |
| 1013 |
ierr = 0 |
| 1014 |
c-----check whether sufficient columns are available. ----------------- |
| 1015 |
c |
| 1016 |
c------- copy elements row by row.-------------------------------------- |
| 1017 |
kpos = 1 |
| 1018 |
ia(1) = kpos |
| 1019 |
do 6 i=1, nrow |
| 1020 |
do 5 k=1,ndiag |
| 1021 |
if (coef(i,k) .ne. 0.0d0) then |
| 1022 |
if (kpos .gt. nzmax) then |
| 1023 |
ierr = kpos |
| 1024 |
return |
| 1025 |
endif |
| 1026 |
a(kpos) = coef(i,k) |
| 1027 |
ja(kpos) = jcoef(i,k) |
| 1028 |
kpos = kpos+1 |
| 1029 |
endif |
| 1030 |
5 continue |
| 1031 |
ia(i+1) = kpos |
| 1032 |
6 continue |
| 1033 |
return |
| 1034 |
c--- end of ellcsr ----------------------------------------------------- |
| 1035 |
c----------------------------------------------------------------------- |
| 1036 |
end |
| 1037 |
c----------------------------------------------------------------------- |
| 1038 |
subroutine csrmsr (n,a,ja,ia,ao,jao,wk,iwk) |
| 1039 |
real*8 a(*),ao(*),wk(n) |
| 1040 |
integer ia(n+1),ja(*),jao(*),iwk(n+1) |
| 1041 |
c----------------------------------------------------------------------- |
| 1042 |
c Compressed Sparse Row to Modified - Sparse Row |
| 1043 |
c Sparse row with separate main diagonal |
| 1044 |
c----------------------------------------------------------------------- |
| 1045 |
c converts a general sparse matrix a, ja, ia into |
| 1046 |
c a compressed matrix using a separated diagonal (referred to as |
| 1047 |
c the bell-labs format as it is used by bell labs semi conductor |
| 1048 |
c group. We refer to it here as the modified sparse row format. |
| 1049 |
c Note: this has been coded in such a way that one can overwrite |
| 1050 |
c the output matrix onto the input matrix if desired by a call of |
| 1051 |
c the form |
| 1052 |
c |
| 1053 |
c call csrmsr (n, a, ja, ia, a, ja, wk,iwk) |
| 1054 |
c |
| 1055 |
c In case ao, jao, are different from a, ja, then one can |
| 1056 |
c use ao, jao as the work arrays in the calling sequence: |
| 1057 |
c |
| 1058 |
c call csrmsr (n, a, ja, ia, ao, jao, ao,jao) |
| 1059 |
c |
| 1060 |
c----------------------------------------------------------------------- |
| 1061 |
c |
| 1062 |
c on entry : |
| 1063 |
c--------- |
| 1064 |
c a, ja, ia = matrix in csr format. note that the |
| 1065 |
c algorithm is in place: ao, jao can be the same |
| 1066 |
c as a, ja, in which case it will be overwritten on it |
| 1067 |
c upon return. |
| 1068 |
c |
| 1069 |
c on return : |
| 1070 |
c----------- |
| 1071 |
c |
| 1072 |
c ao, jao = sparse matrix in modified sparse row storage format: |
| 1073 |
c + ao(1:n) contains the diagonal of the matrix. |
| 1074 |
c + ao(n+2:nnz) contains the nondiagonal elements of the |
| 1075 |
c matrix, stored rowwise. |
| 1076 |
c + jao(n+2:nnz) : their column indices |
| 1077 |
c + jao(1:n+1) contains the pointer array for the nondiagonal |
| 1078 |
c elements in ao(n+1:nnz) and jao(n+2:nnz). |
| 1079 |
c i.e., for i .le. n+1 jao(i) points to beginning of row i |
| 1080 |
c in arrays ao, jao. |
| 1081 |
c here nnz = number of nonzero elements+1 |
| 1082 |
c work arrays: |
| 1083 |
c------------ |
| 1084 |
c wk = real work array of length n |
| 1085 |
c iwk = integer work array of length n+1 |
| 1086 |
c |
| 1087 |
c notes: |
| 1088 |
c------- |
| 1089 |
c Algorithm is in place. i.e. both: |
| 1090 |
c |
| 1091 |
c call csrmsr (n, a, ja, ia, ao, jao, ao,jao) |
| 1092 |
c (in which ao, jao, are different from a, ja) |
| 1093 |
c and |
| 1094 |
c call csrmsr (n, a, ja, ia, a, ja, wk,iwk) |
| 1095 |
c (in which wk, jwk, are different from a, ja) |
| 1096 |
c are OK. |
| 1097 |
c-------- |
| 1098 |
c coded by Y. Saad Sep. 1989. Rechecked Feb 27, 1990. |
| 1099 |
c----------------------------------------------------------------------- |
| 1100 |
icount = 0 |
| 1101 |
c |
| 1102 |
c store away diagonal elements and count nonzero diagonal elements. |
| 1103 |
c |
| 1104 |
do 1 i=1,n |
| 1105 |
wk(i) = 0.0d0 |
| 1106 |
iwk(i+1) = ia(i+1)-ia(i) |
| 1107 |
do 2 k=ia(i),ia(i+1)-1 |
| 1108 |
if (ja(k) .eq. i) then |
| 1109 |
wk(i) = a(k) |
| 1110 |
icount = icount + 1 |
| 1111 |
iwk(i+1) = iwk(i+1)-1 |
| 1112 |
endif |
| 1113 |
2 continue |
| 1114 |
1 continue |
| 1115 |
c |
| 1116 |
c compute total length |
| 1117 |
c |
| 1118 |
iptr = n + ia(n+1) - icount |
| 1119 |
c |
| 1120 |
c copy backwards (to avoid collisions) |
| 1121 |
c |
| 1122 |
do 500 ii=n,1,-1 |
| 1123 |
do 100 k=ia(ii+1)-1,ia(ii),-1 |
| 1124 |
j = ja(k) |
| 1125 |
if (j .ne. ii) then |
| 1126 |
ao(iptr) = a(k) |
| 1127 |
jao(iptr) = j |
| 1128 |
iptr = iptr-1 |
| 1129 |
endif |
| 1130 |
100 continue |
| 1131 |
500 continue |
| 1132 |
c |
| 1133 |
c compute pointer values and copy wk(*) |
| 1134 |
c |
| 1135 |
jao(1) = n+2 |
| 1136 |
do 600 i=1,n |
| 1137 |
ao(i) = wk(i) |
| 1138 |
jao(i+1) = jao(i)+iwk(i+1) |
| 1139 |
600 continue |
| 1140 |
return |
| 1141 |
c------------ end of subroutine csrmsr --------------------------------- |
| 1142 |
c----------------------------------------------------------------------- |
| 1143 |
end |
| 1144 |
c----------------------------------------------------------------------- |
| 1145 |
subroutine msrcsr (n,a,ja,ao,jao,iao,wk,iwk) |
| 1146 |
real*8 a(*),ao(*),wk(n) |
| 1147 |
integer ja(*),jao(*),iao(n+1),iwk(n+1) |
| 1148 |
c----------------------------------------------------------------------- |
| 1149 |
c Modified - Sparse Row to Compressed Sparse Row |
| 1150 |
c |
| 1151 |
c----------------------------------------------------------------------- |
| 1152 |
c converts a compressed matrix using a separated diagonal |
| 1153 |
c (modified sparse row format) in the Compressed Sparse Row |
| 1154 |
c format. |
| 1155 |
c does not check for zero elements in the diagonal. |
| 1156 |
c |
| 1157 |
c |
| 1158 |
c on entry : |
| 1159 |
c--------- |
| 1160 |
c n = row dimension of matrix |
| 1161 |
c a, ja = sparse matrix in msr sparse storage format |
| 1162 |
c see routine csrmsr for details on data structure |
| 1163 |
c |
| 1164 |
c on return : |
| 1165 |
c----------- |
| 1166 |
c |
| 1167 |
c ao,jao,iao = output matrix in csr format. |
| 1168 |
c |
| 1169 |
c work arrays: |
| 1170 |
c------------ |
| 1171 |
c wk = real work array of length n |
| 1172 |
c iwk = integer work array of length n+1 |
| 1173 |
c |
| 1174 |
c notes: |
| 1175 |
c The original version of this was NOT in place, but has |
| 1176 |
c been modified by adding the vector iwk to be in place. |
| 1177 |
c The original version had ja instead of iwk everywhere in |
| 1178 |
c loop 500. Modified Sun 29 May 1994 by R. Bramley (Indiana). |
| 1179 |
c |
| 1180 |
c----------------------------------------------------------------------- |
| 1181 |
logical added |
| 1182 |
do 1 i=1,n |
| 1183 |
wk(i) = a(i) |
| 1184 |
iwk(i) = ja(i) |
| 1185 |
1 continue |
| 1186 |
iwk(n+1) = ja(n+1) |
| 1187 |
iao(1) = 1 |
| 1188 |
iptr = 1 |
| 1189 |
c--------- |
| 1190 |
do 500 ii=1,n |
| 1191 |
added = .false. |
| 1192 |
idiag = iptr + (iwk(ii+1)-iwk(ii)) |
| 1193 |
do 100 k=iwk(ii),iwk(ii+1)-1 |
| 1194 |
j = ja(k) |
| 1195 |
if (j .lt. ii) then |
| 1196 |
ao(iptr) = a(k) |
| 1197 |
jao(iptr) = j |
| 1198 |
iptr = iptr+1 |
| 1199 |
elseif (added) then |
| 1200 |
ao(iptr) = a(k) |
| 1201 |
jao(iptr) = j |
| 1202 |
iptr = iptr+1 |
| 1203 |
else |
| 1204 |
c add diag element - only reserve a position for it. |
| 1205 |
idiag = iptr |
| 1206 |
iptr = iptr+1 |
| 1207 |
added = .true. |
| 1208 |
c then other element |
| 1209 |
ao(iptr) = a(k) |
| 1210 |
jao(iptr) = j |
| 1211 |
iptr = iptr+1 |
| 1212 |
endif |
| 1213 |
100 continue |
| 1214 |
ao(idiag) = wk(ii) |
| 1215 |
jao(idiag) = ii |
| 1216 |
if (.not. added) iptr = iptr+1 |
| 1217 |
iao(ii+1) = iptr |
| 1218 |
500 continue |
| 1219 |
return |
| 1220 |
c------------ end of subroutine msrcsr --------------------------------- |
| 1221 |
c----------------------------------------------------------------------- |
| 1222 |
end |
| 1223 |
c----------------------------------------------------------------------- |
| 1224 |
subroutine csrcsc (n,job,ipos,a,ja,ia,ao,jao,iao) |
| 1225 |
integer ia(n+1),iao(n+1),ja(*),jao(*) |
| 1226 |
real*8 a(*),ao(*) |
| 1227 |
c----------------------------------------------------------------------- |
| 1228 |
c Compressed Sparse Row to Compressed Sparse Column |
| 1229 |
c |
| 1230 |
c (transposition operation) Not in place. |
| 1231 |
c----------------------------------------------------------------------- |
| 1232 |
c -- not in place -- |
| 1233 |
c this subroutine transposes a matrix stored in a, ja, ia format. |
| 1234 |
c --------------- |
| 1235 |
c on entry: |
| 1236 |
c---------- |
| 1237 |
c n = dimension of A. |
| 1238 |
c job = integer to indicate whether to fill the values (job.eq.1) of the |
| 1239 |
c matrix ao or only the pattern., i.e.,ia, and ja (job .ne.1) |
| 1240 |
c |
| 1241 |
c ipos = starting position in ao, jao of the transposed matrix. |
| 1242 |
c the iao array takes this into account (thus iao(1) is set to ipos.) |
| 1243 |
c Note: this may be useful if one needs to append the data structure |
| 1244 |
c of the transpose to that of A. In this case use for example |
| 1245 |
c call csrcsc (n,1,ia(n+1),a,ja,ia,a,ja,ia(n+2)) |
| 1246 |
c for any other normal usage, enter ipos=1. |
| 1247 |
c a = real array of length nnz (nnz=number of nonzero elements in input |
| 1248 |
c matrix) containing the nonzero elements. |
| 1249 |
c ja = integer array of length nnz containing the column positions |
| 1250 |
c of the corresponding elements in a. |
| 1251 |
c ia = integer of size n+1. ia(k) contains the position in a, ja of |
| 1252 |
c the beginning of the k-th row. |
| 1253 |
c |
| 1254 |
c on return: |
| 1255 |
c ---------- |
| 1256 |
c output arguments: |
| 1257 |
c ao = real array of size nzz containing the "a" part of the transpose |
| 1258 |
c jao = integer array of size nnz containing the column indices. |
| 1259 |
c iao = integer array of size n+1 containing the "ia" index array of |
| 1260 |
c the transpose. |
| 1261 |
c |
| 1262 |
c----------------------------------------------------------------------- |
| 1263 |
call csrcsc2 (n,n,job,ipos,a,ja,ia,ao,jao,iao) |
| 1264 |
end |
| 1265 |
c----------------------------------------------------------------------- |
| 1266 |
subroutine csrcsc2 (n,n2,job,ipos,a,ja,ia,ao,jao,iao) |
| 1267 |
integer ia(n+1),iao(n2+1),ja(*),jao(*) |
| 1268 |
real*8 a(*),ao(*) |
| 1269 |
c----------------------------------------------------------------------- |
| 1270 |
c Compressed Sparse Row to Compressed Sparse Column |
| 1271 |
c |
| 1272 |
c (transposition operation) Not in place. |
| 1273 |
c----------------------------------------------------------------------- |
| 1274 |
c Rectangular version. n is number of rows of CSR matrix, |
| 1275 |
c n2 (input) is number of columns of CSC matrix. |
| 1276 |
c----------------------------------------------------------------------- |
| 1277 |
c -- not in place -- |
| 1278 |
c this subroutine transposes a matrix stored in a, ja, ia format. |
| 1279 |
c --------------- |
| 1280 |
c on entry: |
| 1281 |
c---------- |
| 1282 |
c n = number of rows of CSR matrix. |
| 1283 |
c n2 = number of columns of CSC matrix. |
| 1284 |
c job = integer to indicate whether to fill the values (job.eq.1) of the |
| 1285 |
c matrix ao or only the pattern., i.e.,ia, and ja (job .ne.1) |
| 1286 |
c |
| 1287 |
c ipos = starting position in ao, jao of the transposed matrix. |
| 1288 |
c the iao array takes this into account (thus iao(1) is set to ipos.) |
| 1289 |
c Note: this may be useful if one needs to append the data structure |
| 1290 |
c of the transpose to that of A. In this case use for example |
| 1291 |
c call csrcsc2 (n,n,1,ia(n+1),a,ja,ia,a,ja,ia(n+2)) |
| 1292 |
c for any other normal usage, enter ipos=1. |
| 1293 |
c a = real array of length nnz (nnz=number of nonzero elements in input |
| 1294 |
c matrix) containing the nonzero elements. |
| 1295 |
c ja = integer array of length nnz containing the column positions |
| 1296 |
c of the corresponding elements in a. |
| 1297 |
c ia = integer of size n+1. ia(k) contains the position in a, ja of |
| 1298 |
c the beginning of the k-th row. |
| 1299 |
c |
| 1300 |
c on return: |
| 1301 |
c ---------- |
| 1302 |
c output arguments: |
| 1303 |
c ao = real array of size nzz containing the "a" part of the transpose |
| 1304 |
c jao = integer array of size nnz containing the column indices. |
| 1305 |
c iao = integer array of size n+1 containing the "ia" index array of |
| 1306 |
c the transpose. |
| 1307 |
c |
| 1308 |
c----------------------------------------------------------------------- |
| 1309 |
c----------------- compute lengths of rows of transp(A) ---------------- |
| 1310 |
do 1 i=1,n2+1 |
| 1311 |
iao(i) = 0 |
| 1312 |
1 continue |
| 1313 |
do 3 i=1, n |
| 1314 |
do 2 k=ia(i), ia(i+1)-1 |
| 1315 |
j = ja(k)+1 |
| 1316 |
iao(j) = iao(j)+1 |
| 1317 |
2 continue |
| 1318 |
3 continue |
| 1319 |
c---------- compute pointers from lengths ------------------------------ |
| 1320 |
iao(1) = ipos |
| 1321 |
do 4 i=1,n2 |
| 1322 |
iao(i+1) = iao(i) + iao(i+1) |
| 1323 |
4 continue |
| 1324 |
c--------------- now do the actual copying ----------------------------- |
| 1325 |
do 6 i=1,n |
| 1326 |
do 62 k=ia(i),ia(i+1)-1 |
| 1327 |
j = ja(k) |
| 1328 |
next = iao(j) |
| 1329 |
if (job .eq. 1) ao(next) = a(k) |
| 1330 |
jao(next) = i |
| 1331 |
iao(j) = next+1 |
| 1332 |
62 continue |
| 1333 |
6 continue |
| 1334 |
c-------------------------- reshift iao and leave ---------------------- |
| 1335 |
do 7 i=n2,1,-1 |
| 1336 |
iao(i+1) = iao(i) |
| 1337 |
7 continue |
| 1338 |
iao(1) = ipos |
| 1339 |
c--------------- end of csrcsc2 ---------------------------------------- |
| 1340 |
c----------------------------------------------------------------------- |
| 1341 |
end |
| 1342 |
c----------------------------------------------------------------------- |
| 1343 |
subroutine csrlnk (n,a,ja,ia,link) |
| 1344 |
real*8 a(*) |
| 1345 |
integer n, ja(*), ia(n+1), link(*) |
| 1346 |
c----------------------------------------------------------------------- |
| 1347 |
c Compressed Sparse Row to Linked storage format. |
| 1348 |
c----------------------------------------------------------------------- |
| 1349 |
c this subroutine translates a matrix stored in compressed sparse |
| 1350 |
c row into one with a linked list storage format. Only the link |
| 1351 |
c array needs to be obtained since the arrays a, ja, and ia may |
| 1352 |
c be unchanged and carry the same meaning for the output matrix. |
| 1353 |
c in other words a, ja, ia, link is the output linked list data |
| 1354 |
c structure with a, ja, unchanged from input, and ia possibly |
| 1355 |
c altered (in case therea re null rows in matrix). Details on |
| 1356 |
c the output array link are given below. |
| 1357 |
c----------------------------------------------------------------------- |
| 1358 |
c Coded by Y. Saad, Feb 21, 1991. |
| 1359 |
c----------------------------------------------------------------------- |
| 1360 |
c |
| 1361 |
c on entry: |
| 1362 |
c---------- |
| 1363 |
c n = integer equal to the dimension of A. |
| 1364 |
c |
| 1365 |
c a = real array of size nna containing the nonzero elements |
| 1366 |
c ja = integer array of size nnz containing the column positions |
| 1367 |
c of the corresponding elements in a. |
| 1368 |
c ia = integer of size n+1 containing the pointers to the beginning |
| 1369 |
c of each row. ia(k) contains the position in a, ja of the |
| 1370 |
c beginning of the k-th row. |
| 1371 |
c |
| 1372 |
c on return: |
| 1373 |
c---------- |
| 1374 |
c a, ja, are not changed. |
| 1375 |
c ia may be changed if there are null rows. |
| 1376 |
c |
| 1377 |
c a = nonzero elements. |
| 1378 |
c ja = column positions. |
| 1379 |
c ia = ia(i) points to the first element of row i in linked structure. |
| 1380 |
c link = integer array of size containing the linked list information. |
| 1381 |
c link(k) points to the next element of the row after element |
| 1382 |
c a(k), ja(k). if link(k) = 0, then there is no next element, |
| 1383 |
c i.e., a(k), jcol(k) is the last element of the current row. |
| 1384 |
c |
| 1385 |
c Thus row number i can be accessed as follows: |
| 1386 |
c next = ia(i) |
| 1387 |
c while(next .ne. 0) do |
| 1388 |
c value = a(next) ! value a(i,j) |
| 1389 |
c jcol = ja(next) ! column index j |
| 1390 |
c next = link(next) ! address of next element in row |
| 1391 |
c endwhile |
| 1392 |
c notes: |
| 1393 |
c ------ ia may be altered on return. |
| 1394 |
c----------------------------------------------------------------------- |
| 1395 |
c local variables |
| 1396 |
integer i, k |
| 1397 |
c |
| 1398 |
c loop through all rows |
| 1399 |
c |
| 1400 |
do 100 i =1, n |
| 1401 |
istart = ia(i) |
| 1402 |
iend = ia(i+1)-1 |
| 1403 |
if (iend .gt. istart) then |
| 1404 |
do 99 k=istart, iend-1 |
| 1405 |
link(k) = k+1 |
| 1406 |
99 continue |
| 1407 |
link(iend) = 0 |
| 1408 |
else |
| 1409 |
ia(i) = 0 |
| 1410 |
endif |
| 1411 |
100 continue |
| 1412 |
c |
| 1413 |
return |
| 1414 |
c-------------end-of-csrlnk -------------------------------------------- |
| 1415 |
c----------------------------------------------------------------------- |
| 1416 |
end |
| 1417 |
c----------------------------------------------------------------------- |
| 1418 |
subroutine lnkcsr (n, a, jcol, istart, link, ao, jao, iao) |
| 1419 |
real*8 a(*), ao(*) |
| 1420 |
integer n, jcol(*), istart(n), link(*), jao(*), iao(*) |
| 1421 |
c----------------------------------------------------------------------- |
| 1422 |
c Linked list storage format to Compressed Sparse Row format |
| 1423 |
c----------------------------------------------------------------------- |
| 1424 |
c this subroutine translates a matrix stored in linked list storage |
| 1425 |
c format into the compressed sparse row format. |
| 1426 |
c----------------------------------------------------------------------- |
| 1427 |
c Coded by Y. Saad, Feb 21, 1991. |
| 1428 |
c----------------------------------------------------------------------- |
| 1429 |
c |
| 1430 |
c on entry: |
| 1431 |
c---------- |
| 1432 |
c n = integer equal to the dimension of A. |
| 1433 |
c |
| 1434 |
c a = real array of size nna containing the nonzero elements |
| 1435 |
c jcol = integer array of size nnz containing the column positions |
| 1436 |
c of the corresponding elements in a. |
| 1437 |
c istart= integer array of size n poiting to the beginning of the rows. |
| 1438 |
c istart(i) contains the position of the first element of |
| 1439 |
c row i in data structure. (a, jcol, link). |
| 1440 |
c if a row is empty istart(i) must be zero. |
| 1441 |
c link = integer array of size nnz containing the links in the linked |
| 1442 |
c list data structure. link(k) points to the next element |
| 1443 |
c of the row after element ao(k), jcol(k). if link(k) = 0, |
| 1444 |
c then there is no next element, i.e., ao(k), jcol(k) is |
| 1445 |
c the last element of the current row. |
| 1446 |
c |
| 1447 |
c on return: |
| 1448 |
c----------- |
| 1449 |
c ao, jao, iao = matrix stored in csr format: |
| 1450 |
c |
| 1451 |
c ao = real array containing the values of the nonzero elements of |
| 1452 |
c the matrix stored row-wise. |
| 1453 |
c jao = integer array of size nnz containing the column indices. |
| 1454 |
c iao = integer array of size n+1 containing the pointers array to the |
| 1455 |
c beginning of each row. iao(i) is the address in ao,jao of |
| 1456 |
c first element of row i. |
| 1457 |
c |
| 1458 |
c----------------------------------------------------------------------- |
| 1459 |
c first determine individial bandwidths and pointers. |
| 1460 |
c----------------------------------------------------------------------- |
| 1461 |
c local variables |
| 1462 |
integer irow, ipos, next |
| 1463 |
c----------------------------------------------------------------------- |
| 1464 |
ipos = 1 |
| 1465 |
iao(1) = ipos |
| 1466 |
c |
| 1467 |
c loop through all rows |
| 1468 |
c |
| 1469 |
do 100 irow =1, n |
| 1470 |
c |
| 1471 |
c unroll i-th row. |
| 1472 |
c |
| 1473 |
next = istart(irow) |
| 1474 |
10 if (next .eq. 0) goto 99 |
| 1475 |
jao(ipos) = jcol(next) |
| 1476 |
ao(ipos) = a(next) |
| 1477 |
ipos = ipos+1 |
| 1478 |
next = link(next) |
| 1479 |
goto 10 |
| 1480 |
99 iao(irow+1) = ipos |
| 1481 |
100 continue |
| 1482 |
c |
| 1483 |
return |
| 1484 |
c-------------end-of-lnkcsr ------------------------------------------- |
| 1485 |
c----------------------------------------------------------------------- |
| 1486 |
end |
| 1487 |
c----------------------------------------------------------------------- |
| 1488 |
subroutine csrdia (n,idiag,job,a,ja,ia,ndiag, |
| 1489 |
* diag,ioff,ao,jao,iao,ind) |
| 1490 |
real*8 diag(ndiag,idiag), a(*), ao(*) |
| 1491 |
integer ia(*), ind(*), ja(*), jao(*), iao(*), ioff(*) |
| 1492 |
c----------------------------------------------------------------------- |
| 1493 |
c Compressed sparse row to diagonal format |
| 1494 |
c----------------------------------------------------------------------- |
| 1495 |
c this subroutine extracts idiag diagonals from the input matrix a, |
| 1496 |
c a, ia, and puts the rest of the matrix in the output matrix ao, |
| 1497 |
c jao, iao. The diagonals to be extracted depend on the value of job |
| 1498 |
c (see below for details.) In the first case, the diagonals to be |
| 1499 |
c extracted are simply identified by their offsets provided in ioff |
| 1500 |
c by the caller. In the second case, the code internally determines |
| 1501 |
c the idiag most significant diagonals, i.e., those diagonals of the |
| 1502 |
c matrix which have the largest number of nonzero elements, and |
| 1503 |
c extracts them. |
| 1504 |
c----------------------------------------------------------------------- |
| 1505 |
c on entry: |
| 1506 |
c---------- |
| 1507 |
c n = dimension of the matrix a. |
| 1508 |
c idiag = integer equal to the number of diagonals to be extracted. |
| 1509 |
c Note: on return idiag may be modified. |
| 1510 |
c a, ja, |
| 1511 |
c ia = matrix stored in a, ja, ia, format |
| 1512 |
c job = integer. serves as a job indicator. Job is better thought |
| 1513 |
c of as a two-digit number job=xy. If the first (x) digit |
| 1514 |
c is one on entry then the diagonals to be extracted are |
| 1515 |
c internally determined. In this case csrdia exctracts the |
| 1516 |
c idiag most important diagonals, i.e. those having the largest |
| 1517 |
c number on nonzero elements. If the first digit is zero |
| 1518 |
c then csrdia assumes that ioff(*) contains the offsets |
| 1519 |
c of the diagonals to be extracted. there is no verification |
| 1520 |
c that ioff(*) contains valid entries. |
| 1521 |
c The second (y) digit of job determines whether or not |
| 1522 |
c the remainder of the matrix is to be written on ao,jao,iao. |
| 1523 |
c If it is zero then ao, jao, iao is not filled, i.e., |
| 1524 |
c the diagonals are found and put in array diag and the rest is |
| 1525 |
c is discarded. if it is one, ao, jao, iao contains matrix |
| 1526 |
c of the remaining elements. |
| 1527 |
c Thus: |
| 1528 |
c job= 0 means do not select diagonals internally (pick those |
| 1529 |
c defined by ioff) and do not fill ao,jao,iao |
| 1530 |
c job= 1 means do not select diagonals internally |
| 1531 |
c and fill ao,jao,iao |
| 1532 |
c job=10 means select diagonals internally |
| 1533 |
c and do not fill ao,jao,iao |
| 1534 |
c job=11 means select diagonals internally |
| 1535 |
c and fill ao,jao,iao |
| 1536 |
c |
| 1537 |
c ndiag = integer equal to the first dimension of array diag. |
| 1538 |
c |
| 1539 |
c on return: |
| 1540 |
c----------- |
| 1541 |
c |
| 1542 |
c idiag = number of diagonals found. This may be smaller than its value |
| 1543 |
c on entry. |
| 1544 |
c diag = real array of size (ndiag x idiag) containing the diagonals |
| 1545 |
c of A on return |
| 1546 |
c |
| 1547 |
c ioff = integer array of length idiag, containing the offsets of the |
| 1548 |
c diagonals to be extracted. |
| 1549 |
c ao, jao |
| 1550 |
c iao = remainder of the matrix in a, ja, ia format. |
| 1551 |
c work arrays: |
| 1552 |
c------------ |
| 1553 |
c ind = integer array of length 2*n-1 used as integer work space. |
| 1554 |
c needed only when job.ge.10 i.e., in case the diagonals are to |
| 1555 |
c be selected internally. |
| 1556 |
c |
| 1557 |
c Notes: |
| 1558 |
c------- |
| 1559 |
c 1) The algorithm is in place: ao, jao, iao can be overwritten on |
| 1560 |
c a, ja, ia if desired |
| 1561 |
c 2) When the code is required to select the diagonals (job .ge. 10) |
| 1562 |
c the selection of the diagonals is done from left to right |
| 1563 |
c as a result if several diagonals have the same weight (number |
| 1564 |
c of nonzero elemnts) the leftmost one is selected first. |
| 1565 |
c----------------------------------------------------------------------- |
| 1566 |
job1 = job/10 |
| 1567 |
job2 = job-job1*10 |
| 1568 |
if (job1 .eq. 0) goto 50 |
| 1569 |
n2 = n+n-1 |
| 1570 |
call infdia(n,ja,ia,ind,idum) |
| 1571 |
c----------- determine diagonals to accept.---------------------------- |
| 1572 |
c----------------------------------------------------------------------- |
| 1573 |
ii = 0 |
| 1574 |
4 ii=ii+1 |
| 1575 |
jmax = 0 |
| 1576 |
do 41 k=1, n2 |
| 1577 |
j = ind(k) |
| 1578 |
if (j .le. jmax) goto 41 |
| 1579 |
i = k |
| 1580 |
jmax = j |
| 1581 |
41 continue |
| 1582 |
if (jmax .le. 0) then |
| 1583 |
ii = ii-1 |
| 1584 |
goto 42 |
| 1585 |
endif |
| 1586 |
ioff(ii) = i-n |
| 1587 |
ind(i) = - jmax |
| 1588 |
if (ii .lt. idiag) goto 4 |
| 1589 |
42 idiag = ii |
| 1590 |
c---------------- initialize diago to zero ----------------------------- |
| 1591 |
50 continue |
| 1592 |
do 55 j=1,idiag |
| 1593 |
do 54 i=1,n |
| 1594 |
diag(i,j) = 0.0d0 |
| 1595 |
54 continue |
| 1596 |
55 continue |
| 1597 |
c----------------------------------------------------------------------- |
| 1598 |
ko = 1 |
| 1599 |
c----------------------------------------------------------------------- |
| 1600 |
c extract diagonals and accumulate remaining matrix. |
| 1601 |
c----------------------------------------------------------------------- |
| 1602 |
do 6 i=1, n |
| 1603 |
do 51 k=ia(i),ia(i+1)-1 |
| 1604 |
j = ja(k) |
| 1605 |
do 52 l=1,idiag |
| 1606 |
if (j-i .ne. ioff(l)) goto 52 |
| 1607 |
diag(i,l) = a(k) |
| 1608 |
goto 51 |
| 1609 |
52 continue |
| 1610 |
c--------------- append element not in any diagonal to ao,jao,iao ----- |
| 1611 |
if (job2 .eq. 0) goto 51 |
| 1612 |
ao(ko) = a(k) |
| 1613 |
jao(ko) = j |
| 1614 |
ko = ko+1 |
| 1615 |
51 continue |
| 1616 |
if (job2 .ne. 0 ) ind(i+1) = ko |
| 1617 |
6 continue |
| 1618 |
if (job2 .eq. 0) return |
| 1619 |
c finish with iao |
| 1620 |
iao(1) = 1 |
| 1621 |
do 7 i=2,n+1 |
| 1622 |
iao(i) = ind(i) |
| 1623 |
7 continue |
| 1624 |
return |
| 1625 |
c----------- end of csrdia --------------------------------------------- |
| 1626 |
c----------------------------------------------------------------------- |
| 1627 |
end |
| 1628 |
c----------------------------------------------------------------------- |
| 1629 |
subroutine diacsr (n,job,idiag,diag,ndiag,ioff,a,ja,ia) |
| 1630 |
real*8 diag(ndiag,idiag), a(*), t |
| 1631 |
integer ia(*), ja(*), ioff(*) |
| 1632 |
c----------------------------------------------------------------------- |
| 1633 |
c diagonal format to compressed sparse row |
| 1634 |
c----------------------------------------------------------------------- |
| 1635 |
c this subroutine extract the idiag most important diagonals from the |
| 1636 |
c input matrix a, ja, ia, i.e, those diagonals of the matrix which have |
| 1637 |
c the largest number of nonzero elements. If requested (see job), |
| 1638 |
c the rest of the matrix is put in a the output matrix ao, jao, iao |
| 1639 |
c----------------------------------------------------------------------- |
| 1640 |
c on entry: |
| 1641 |
c---------- |
| 1642 |
c n = integer. dimension of the matrix a. |
| 1643 |
c job = integer. job indicator with the following meaning. |
| 1644 |
c if (job .eq. 0) then check for each entry in diag |
| 1645 |
c whether this entry is zero. If it is then do not include |
| 1646 |
c in the output matrix. Note that the test is a test for |
| 1647 |
c an exact arithmetic zero. Be sure that the zeros are |
| 1648 |
c actual zeros in double precision otherwise this would not |
| 1649 |
c work. |
| 1650 |
c |
| 1651 |
c idiag = integer equal to the number of diagonals to be extracted. |
| 1652 |
c Note: on return idiag may be modified. |
| 1653 |
c |
| 1654 |
c diag = real array of size (ndiag x idiag) containing the diagonals |
| 1655 |
c of A on return. |
| 1656 |
c |
| 1657 |
c ndiag = integer equal to the first dimension of array diag. |
| 1658 |
c |
| 1659 |
c ioff = integer array of length idiag, containing the offsets of the |
| 1660 |
c diagonals to be extracted. |
| 1661 |
c |
| 1662 |
c on return: |
| 1663 |
c----------- |
| 1664 |
c a, |
| 1665 |
c ja, |
| 1666 |
c ia = matrix stored in a, ja, ia, format |
| 1667 |
c |
| 1668 |
c Note: |
| 1669 |
c ----- the arrays a and ja should be of length n*idiag. |
| 1670 |
c |
| 1671 |
c----------------------------------------------------------------------- |
| 1672 |
ia(1) = 1 |
| 1673 |
ko = 1 |
| 1674 |
do 80 i=1, n |
| 1675 |
do 70 jj = 1, idiag |
| 1676 |
j = i+ioff(jj) |
| 1677 |
if (j .lt. 1 .or. j .gt. n) goto 70 |
| 1678 |
t = diag(i,jj) |
| 1679 |
if (job .eq. 0 .and. t .eq. 0.0d0) goto 70 |
| 1680 |
a(ko) = t |
| 1681 |
ja(ko) = j |
| 1682 |
ko = ko+1 |
| 1683 |
70 continue |
| 1684 |
ia(i+1) = ko |
| 1685 |
80 continue |
| 1686 |
return |
| 1687 |
c----------- end of diacsr --------------------------------------------- |
| 1688 |
c----------------------------------------------------------------------- |
| 1689 |
end |
| 1690 |
c----------------------------------------------------------------------- |
| 1691 |
subroutine bsrcsr (job, n, m, na, a, ja, ia, ao, jao, iao) |
| 1692 |
implicit none |
| 1693 |
integer job, n, m, na, ia(*), ja(*), jao(*), iao(n+1) |
| 1694 |
real*8 a(na,*), ao(*) |
| 1695 |
c----------------------------------------------------------------------- |
| 1696 |
c Block Sparse Row to Compressed Sparse Row. |
| 1697 |
c----------------------------------------------------------------------- |
| 1698 |
c NOTE: ** meanings of parameters may have changed wrt earlier versions |
| 1699 |
c FORMAT DEFINITION HAS CHANGED WRT TO EARLIER VERSIONS... |
| 1700 |
c----------------------------------------------------------------------- |
| 1701 |
c |
| 1702 |
c converts a matrix stored in block-reduced a, ja, ia format to the |
| 1703 |
c general sparse row a, ja, ia format. A matrix that has a block |
| 1704 |
c structure is a matrix whose entries are blocks of the same size m |
| 1705 |
c (e.g. 3 x 3). Then it is often preferred to work with the reduced |
| 1706 |
c graph of the matrix. Instead of storing one element at a time one can |
| 1707 |
c store a whole block at a time. In this storage scheme an entry is a |
| 1708 |
c square array holding the m**2 elements of a block. |
| 1709 |
c |
| 1710 |
c----------------------------------------------------------------------- |
| 1711 |
c on entry: |
| 1712 |
c---------- |
| 1713 |
c job = if job.eq.0 on entry, values are not copied (pattern only) |
| 1714 |
c |
| 1715 |
c n = the block row dimension of the matrix. |
| 1716 |
c |
| 1717 |
c m = the dimension of each block. Thus, the actual row dimension |
| 1718 |
c of A is n x m. |
| 1719 |
c |
| 1720 |
c na = first dimension of array a as declared in calling program. |
| 1721 |
c This should be .ge. m**2. |
| 1722 |
c |
| 1723 |
c a = real array containing the real entries of the matrix. Recall |
| 1724 |
c that each entry is in fact an m x m block. These entries |
| 1725 |
c are stored column-wise in locations a(1:m*m,k) for each k-th |
| 1726 |
c entry. See details below. |
| 1727 |
c |
| 1728 |
c ja = integer array of length n. ja(k) contains the column index |
| 1729 |
c of the leading element, i.e., the element (1,1) of the block |
| 1730 |
c that is held in the column a(*,k) of the value array. |
| 1731 |
c |
| 1732 |
c ia = integer array of length n+1. ia(i) points to the beginning |
| 1733 |
c of block row number i in the arrays a and ja. |
| 1734 |
c |
| 1735 |
c on return: |
| 1736 |
c----------- |
| 1737 |
c ao, jao, |
| 1738 |
c iao = matrix stored in compressed sparse row format. The number of |
| 1739 |
c rows in the new matrix is n x m. |
| 1740 |
c |
| 1741 |
c Notes: THIS CODE IS NOT IN PLACE. |
| 1742 |
c |
| 1743 |
c----------------------------------------------------------------------- |
| 1744 |
c BSR FORMAT. |
| 1745 |
c---------- |
| 1746 |
c Each row of A contains the m x m block matrix unpacked column- |
| 1747 |
c wise (this allows the user to declare the array a as a(m,m,*) on entry |
| 1748 |
c if desired). The block rows are stored in sequence just as for the |
| 1749 |
c compressed sparse row format. |
| 1750 |
c |
| 1751 |
c----------------------------------------------------------------------- |
| 1752 |
c example with m = 2: |
| 1753 |
c 1 2 3 |
| 1754 |
c +-------|--------|--------+ +-------+ |
| 1755 |
c | 1 2 | 0 0 | 3 4 | Block | x 0 x | 1 |
| 1756 |
c | 5 6 | 0 0 | 7 8 | Representation: | 0 x x | 2 |
| 1757 |
c +-------+--------+--------+ | x 0 0 | 3 |
| 1758 |
c | 0 0 | 9 10 | 11 12 | +-------+ |
| 1759 |
c | 0 0 | 13 14 | 15 16 | |
| 1760 |
c +-------+--------+--------+ |
| 1761 |
c | 17 18 | 0 0 | 0 0 | |
| 1762 |
c | 22 23 | 0 0 | 0 0 | |
| 1763 |
c +-------+--------+--------+ |
| 1764 |
c |
| 1765 |
c For this matrix: n = 3 |
| 1766 |
c m = 2 |
| 1767 |
c nnz = 5 |
| 1768 |
c----------------------------------------------------------------------- |
| 1769 |
c Data structure in Block Sparse Row format: |
| 1770 |
c------------------------------------------- |
| 1771 |
c Array A: |
| 1772 |
c------------------------- |
| 1773 |
c 1 3 9 11 17 <<--each m x m block is stored column-wise |
| 1774 |
c 5 7 13 15 22 in a column of the array A. |
| 1775 |
c 2 4 10 12 18 |
| 1776 |
c 6 8 14 16 23 |
| 1777 |
c------------------------- |
| 1778 |
c JA 1 3 2 3 1 <<-- column indices for each block. Note that |
| 1779 |
c------------------------- these indices are wrt block matrix. |
| 1780 |
c IA 1 3 5 6 <<-- pointers to beginning of each block row |
| 1781 |
c------------------------- in arrays A and JA. |
| 1782 |
c----------------------------------------------------------------------- |
| 1783 |
c locals |
| 1784 |
c |
| 1785 |
integer i, i1, i2, ij, ii, irow, j, jstart, k, krow, no |
| 1786 |
logical val |
| 1787 |
c |
| 1788 |
val = (job.ne.0) |
| 1789 |
no = n * m |
| 1790 |
irow = 1 |
| 1791 |
krow = 1 |
| 1792 |
iao(irow) = 1 |
| 1793 |
c----------------------------------------------------------------------- |
| 1794 |
do 2 ii=1, n |
| 1795 |
c |
| 1796 |
c recall: n is the block-row dimension |
| 1797 |
c |
| 1798 |
i1 = ia(ii) |
| 1799 |
i2 = ia(ii+1)-1 |
| 1800 |
c |
| 1801 |
c create m rows for each block row -- i.e., each k. |
| 1802 |
c |
| 1803 |
do 23 i=1,m |
| 1804 |
do 21 k=i1, i2 |
| 1805 |
jstart = m*(ja(k)-1) |
| 1806 |
do 22 j=1,m |
| 1807 |
ij = (j-1)*m + i |
| 1808 |
if (val) ao(krow) = a(ij,k) |
| 1809 |
jao(krow) = jstart+j |
| 1810 |
krow = krow+1 |
| 1811 |
22 continue |
| 1812 |
21 continue |
| 1813 |
irow = irow+1 |
| 1814 |
iao(irow) = krow |
| 1815 |
23 continue |
| 1816 |
2 continue |
| 1817 |
return |
| 1818 |
c-------------end-of-bsrcsr -------------------------------------------- |
| 1819 |
c----------------------------------------------------------------------- |
| 1820 |
end |
| 1821 |
c----------------------------------------------------------------------- |
| 1822 |
subroutine csrbsr (job,nrow,m,na,a,ja,ia,ao,jao,iao,iw,ierr) |
| 1823 |
implicit none |
| 1824 |
integer job,ierr,nrow,m,na,ia(nrow+1),ja(*),jao(na),iao(*),iw(*) |
| 1825 |
real*8 a(*),ao(na,*) |
| 1826 |
c----------------------------------------------------------------------- |
| 1827 |
c Compressed Sparse Row to Block Sparse Row |
| 1828 |
c----------------------------------------------------------------------- |
| 1829 |
c |
| 1830 |
c This subroutine converts a matrix stored in a general compressed a, |
| 1831 |
c ja, ia format into a a block sparse row format a(m,m,*),ja(*),ia(*). |
| 1832 |
c See routine bsrcsr for more details on data structure for block |
| 1833 |
c matrices. |
| 1834 |
c |
| 1835 |
c NOTES: 1) the initial matrix does not have to have a block structure. |
| 1836 |
c zero padding is done for general sparse matrices. |
| 1837 |
c 2) For most practical purposes, na should be the same as m*m. |
| 1838 |
c |
| 1839 |
c----------------------------------------------------------------------- |
| 1840 |
c |
| 1841 |
c In what follows nr=1+(nrow-1)/m = block-row dimension of output matrix |
| 1842 |
c |
| 1843 |
c on entry: |
| 1844 |
c---------- |
| 1845 |
c |
| 1846 |
c job = job indicator. |
| 1847 |
c job = 0 -> only the pattern of output matrix is generated |
| 1848 |
c job > 0 -> both pattern and values are generated. |
| 1849 |
c job = -1 -> iao(1) will return the number of nonzero blocks, |
| 1850 |
c in the output matrix. In this case jao(1:nr) is used as |
| 1851 |
c workspace, ao is untouched, iao is untouched except iao(1) |
| 1852 |
c |
| 1853 |
c nrow = integer, the actual row dimension of the matrix. |
| 1854 |
c |
| 1855 |
c m = integer equal to the dimension of each block. m should be > 0. |
| 1856 |
c |
| 1857 |
c na = first dimension of array ao as declared in calling program. |
| 1858 |
c na should be .ge. m*m. |
| 1859 |
c |
| 1860 |
c a, ja, |
| 1861 |
c ia = input matrix stored in compressed sparse row format. |
| 1862 |
c |
| 1863 |
c on return: |
| 1864 |
c----------- |
| 1865 |
c |
| 1866 |
c ao = real array containing the values of the matrix. For details |
| 1867 |
c on the format see below. Each row of a contains the m x m |
| 1868 |
c block matrix unpacked column-wise (this allows the user to |
| 1869 |
c declare the array a as ao(m,m,*) on entry if desired). The |
| 1870 |
c block rows are stored in sequence just as for the compressed |
| 1871 |
c sparse row format. The block dimension of the output matrix |
| 1872 |
c is nr = 1 + (nrow-1) / m. |
| 1873 |
c |
| 1874 |
c jao = integer array. containing the block-column indices of the |
| 1875 |
c block-matrix. Each jao(k) is an integer between 1 and nr |
| 1876 |
c containing the block column index of the block ao(*,k). |
| 1877 |
c |
| 1878 |
c iao = integer array of length nr+1. iao(i) points to the beginning |
| 1879 |
c of block row number i in the arrays ao and jao. When job=-1 |
| 1880 |
c iao(1) contains the number of nonzero blocks of the output |
| 1881 |
c matrix and the rest of iao is unused. This is useful for |
| 1882 |
c determining the lengths of ao and jao. |
| 1883 |
c |
| 1884 |
c ierr = integer, error code. |
| 1885 |
c 0 -- normal termination |
| 1886 |
c 1 -- m is equal to zero |
| 1887 |
c 2 -- NA too small to hold the blocks (should be .ge. m**2) |
| 1888 |
c |
| 1889 |
c Work arrays: |
| 1890 |
c------------- |
| 1891 |
c iw = integer work array of dimension nr = 1 + (nrow-1) / m |
| 1892 |
c |
| 1893 |
c NOTES: |
| 1894 |
c------- |
| 1895 |
c 1) this code is not in place. |
| 1896 |
c 2) see routine bsrcsr for details on data sctructure for block |
| 1897 |
c sparse row format. |
| 1898 |
c |
| 1899 |
c----------------------------------------------------------------------- |
| 1900 |
c nr is the block-dimension of the output matrix. |
| 1901 |
c |
| 1902 |
integer nr, m2, io, ko, ii, len, k, jpos, j, i, ij, jr, irow |
| 1903 |
logical vals |
| 1904 |
c----- |
| 1905 |
ierr = 0 |
| 1906 |
if (m*m .gt. na) ierr = 2 |
| 1907 |
if (m .eq. 0) ierr = 1 |
| 1908 |
if (ierr .ne. 0) return |
| 1909 |
c----------------------------------------------------------------------- |
| 1910 |
vals = (job .gt. 0) |
| 1911 |
nr = 1 + (nrow-1) / m |
| 1912 |
m2 = m*m |
| 1913 |
ko = 1 |
| 1914 |
io = 1 |
| 1915 |
iao(io) = 1 |
| 1916 |
len = 0 |
| 1917 |
c |
| 1918 |
c iw determines structure of block-row (nonzero indicator) |
| 1919 |
c |
| 1920 |
do j=1, nr |
| 1921 |
iw(j) = 0 |
| 1922 |
enddo |
| 1923 |
c |
| 1924 |
c big loop -- leap by m rows each time. |
| 1925 |
c |
| 1926 |
do ii=1, nrow, m |
| 1927 |
irow = 0 |
| 1928 |
c |
| 1929 |
c go through next m rows -- make sure not to go beyond nrow. |
| 1930 |
c |
| 1931 |
do while (ii+irow .le. nrow .and. irow .le. m-1) |
| 1932 |
do k=ia(ii+irow),ia(ii+irow+1)-1 |
| 1933 |
c |
| 1934 |
c block column index = (scalar column index -1) / m + 1 |
| 1935 |
c |
| 1936 |
j = ja(k)-1 |
| 1937 |
jr = j/m + 1 |
| 1938 |
j = j - (jr-1)*m |
| 1939 |
jpos = iw(jr) |
| 1940 |
if (jpos .eq. 0) then |
| 1941 |
c |
| 1942 |
c create a new block |
| 1943 |
c |
| 1944 |
iw(jr) = ko |
| 1945 |
jao(ko) = jr |
| 1946 |
if (vals) then |
| 1947 |
c |
| 1948 |
c initialize new block to zero -- then copy nonzero element |
| 1949 |
c |
| 1950 |
do i=1, m2 |
| 1951 |
ao(i,ko) = 0.0d0 |
| 1952 |
enddo |
| 1953 |
ij = j*m + irow + 1 |
| 1954 |
ao(ij,ko) = a(k) |
| 1955 |
endif |
| 1956 |
ko = ko+1 |
| 1957 |
else |
| 1958 |
c |
| 1959 |
c copy column index and nonzero element |
| 1960 |
c |
| 1961 |
jao(jpos) = jr |
| 1962 |
ij = j*m + irow + 1 |
| 1963 |
if (vals) ao(ij,jpos) = a(k) |
| 1964 |
endif |
| 1965 |
enddo |
| 1966 |
irow = irow+1 |
| 1967 |
enddo |
| 1968 |
c |
| 1969 |
c refresh iw |
| 1970 |
c |
| 1971 |
do j = iao(io),ko-1 |
| 1972 |
iw(jao(j)) = 0 |
| 1973 |
enddo |
| 1974 |
if (job .eq. -1) then |
| 1975 |
len = len + ko-1 |
| 1976 |
ko = 1 |
| 1977 |
else |
| 1978 |
io = io+1 |
| 1979 |
iao(io) = ko |
| 1980 |
endif |
| 1981 |
enddo |
| 1982 |
if (job .eq. -1) iao(1) = len |
| 1983 |
c |
| 1984 |
return |
| 1985 |
c--------------end-of-csrbsr-------------------------------------------- |
| 1986 |
c----------------------------------------------------------------------- |
| 1987 |
end |
| 1988 |
c----------------------------------------------------------------------- |
| 1989 |
subroutine csrbnd (n,a,ja,ia,job,abd,nabd,lowd,ml,mu,ierr) |
| 1990 |
real*8 a(*),abd(nabd,n) |
| 1991 |
integer ia(n+1),ja(*) |
| 1992 |
c----------------------------------------------------------------------- |
| 1993 |
c Compressed Sparse Row to Banded (Linpack ) format. |
| 1994 |
c----------------------------------------------------------------------- |
| 1995 |
c this subroutine converts a general sparse matrix stored in |
| 1996 |
c compressed sparse row format into the banded format. for the |
| 1997 |
c banded format,the Linpack conventions are assumed (see below). |
| 1998 |
c----------------------------------------------------------------------- |
| 1999 |
c on entry: |
| 2000 |
c---------- |
| 2001 |
c n = integer,the actual row dimension of the matrix. |
| 2002 |
c |
| 2003 |
c a, |
| 2004 |
c ja, |
| 2005 |
c ia = input matrix stored in compressed sparse row format. |
| 2006 |
c |
| 2007 |
c job = integer. if job=1 then the values of the lower bandwith ml |
| 2008 |
c and the upper bandwidth mu are determined internally. |
| 2009 |
c otherwise it is assumed that the values of ml and mu |
| 2010 |
c are the correct bandwidths on input. See ml and mu below. |
| 2011 |
c |
| 2012 |
c nabd = integer. first dimension of array abd. |
| 2013 |
c |
| 2014 |
c lowd = integer. this should be set to the row number in abd where |
| 2015 |
c the lowest diagonal (leftmost) of A is located. |
| 2016 |
c lowd should be ( 1 .le. lowd .le. nabd). |
| 2017 |
c if it is not known in advance what lowd should be |
| 2018 |
c enter lowd = 0 and the default value lowd = ml+mu+1 |
| 2019 |
c will be chosen. Alternative: call routine getbwd from unary |
| 2020 |
c first to detrermione ml and mu then define lowd accordingly. |
| 2021 |
c (Note: the banded solvers in linpack use lowd=2*ml+mu+1. ) |
| 2022 |
c |
| 2023 |
c ml = integer. equal to the bandwidth of the strict lower part of A |
| 2024 |
c mu = integer. equal to the bandwidth of the strict upper part of A |
| 2025 |
c thus the total bandwidth of A is ml+mu+1. |
| 2026 |
c if ml+mu+1 is found to be larger than lowd then an error |
| 2027 |
c flag is raised (unless lowd = 0). see ierr. |
| 2028 |
c |
| 2029 |
c note: ml and mu are assumed to have the correct bandwidth values |
| 2030 |
c as defined above if job is set to zero on entry. |
| 2031 |
c |
| 2032 |
c on return: |
| 2033 |
c----------- |
| 2034 |
c |
| 2035 |
c abd = real array of dimension abd(nabd,n). |
| 2036 |
c on return contains the values of the matrix stored in |
| 2037 |
c banded form. The j-th column of abd contains the elements |
| 2038 |
c of the j-th column of the original matrix comprised in the |
| 2039 |
c band ( i in (j-ml,j+mu) ) with the lowest diagonal at |
| 2040 |
c the bottom row (row lowd). See details below for this format. |
| 2041 |
c |
| 2042 |
c ml = integer. equal to the bandwidth of the strict lower part of A |
| 2043 |
c mu = integer. equal to the bandwidth of the strict upper part of A |
| 2044 |
c if job=1 on entry then these two values are internally computed. |
| 2045 |
c |
| 2046 |
c lowd = integer. row number in abd where the lowest diagonal |
| 2047 |
c (leftmost) of A is located on return. In case lowd = 0 |
| 2048 |
c on return, then it is defined to ml+mu+1 on return and the |
| 2049 |
c lowd will contain this value on return. ` |
| 2050 |
c |
| 2051 |
c ierr = integer. used for error messages. On return: |
| 2052 |
c ierr .eq. 0 :means normal return |
| 2053 |
c ierr .eq. -1 : means invalid value for lowd. (either .lt. 0 |
| 2054 |
c or larger than nabd). |
| 2055 |
c ierr .eq. -2 : means that lowd is not large enough and as |
| 2056 |
c result the matrix cannot be stored in array abd. |
| 2057 |
c lowd should be at least ml+mu+1, where ml and mu are as |
| 2058 |
c provided on output. |
| 2059 |
c |
| 2060 |
c----------------------------------------------------------------------* |
| 2061 |
c Additional details on banded format. (this closely follows the * |
| 2062 |
c format used in linpack. may be useful for converting a matrix into * |
| 2063 |
c this storage format in order to use the linpack banded solvers). * |
| 2064 |
c----------------------------------------------------------------------* |
| 2065 |
c --- band storage format for matrix abd --- * |
| 2066 |
c uses ml+mu+1 rows of abd(nabd,*) to store the diagonals of * |
| 2067 |
c a in rows of abd starting from the lowest (sub)-diagonal which is * |
| 2068 |
c stored in row number lowd of abd. the minimum number of rows needed * |
| 2069 |
c in abd is ml+mu+1, i.e., the minimum value for lowd is ml+mu+1. the * |
| 2070 |
c j-th column of abd contains the elements of the j-th column of a, * |
| 2071 |
c from bottom to top: the element a(j+ml,j) is stored in position * |
| 2072 |
c abd(lowd,j), then a(j+ml-1,j) in position abd(lowd-1,j) and so on. * |
| 2073 |
c Generally, the element a(j+k,j) of original matrix a is stored in * |
| 2074 |
c position abd(lowd+k-ml,j), for k=ml,ml-1,..,0,-1, -mu. * |
| 2075 |
c The first dimension nabd of abd must be .ge. lowd * |
| 2076 |
c * |
| 2077 |
c example [from linpack ]: if the original matrix is * |
| 2078 |
c * |
| 2079 |
c 11 12 13 0 0 0 * |
| 2080 |
c 21 22 23 24 0 0 * |
| 2081 |
c 0 32 33 34 35 0 original banded matrix * |
| 2082 |
c 0 0 43 44 45 46 * |
| 2083 |
c 0 0 0 54 55 56 * |
| 2084 |
c 0 0 0 0 65 66 * |
| 2085 |
c * |
| 2086 |
c then n = 6, ml = 1, mu = 2. lowd should be .ge. 4 (=ml+mu+1) and * |
| 2087 |
c if lowd = 5 for example, abd should be: * |
| 2088 |
c * |
| 2089 |
c untouched --> x x x x x x * |
| 2090 |
c * * 13 24 35 46 * |
| 2091 |
c * 12 23 34 45 56 resulting abd matrix in banded * |
| 2092 |
c 11 22 33 44 55 66 format * |
| 2093 |
c row lowd--> 21 32 43 54 65 * * |
| 2094 |
c * |
| 2095 |
c * = not used * |
| 2096 |
c |
| 2097 |
* |
| 2098 |
c----------------------------------------------------------------------* |
| 2099 |
c first determine ml and mu. |
| 2100 |
c----------------------------------------------------------------------- |
| 2101 |
ierr = 0 |
| 2102 |
c----------- |
| 2103 |
if (job .eq. 1) call getbwd(n,a,ja,ia,ml,mu) |
| 2104 |
m = ml+mu+1 |
| 2105 |
if (lowd .eq. 0) lowd = m |
| 2106 |
if (m .gt. lowd) ierr = -2 |
| 2107 |
if (lowd .gt. nabd .or. lowd .lt. 0) ierr = -1 |
| 2108 |
if (ierr .lt. 0) return |
| 2109 |
c------------ |
| 2110 |
do 15 i=1,m |
| 2111 |
ii = lowd -i+1 |
| 2112 |
do 10 j=1,n |
| 2113 |
abd(ii,j) = 0.0d0 |
| 2114 |
10 continue |
| 2115 |
15 continue |
| 2116 |
c--------------------------------------------------------------------- |
| 2117 |
mdiag = lowd-ml |
| 2118 |
do 30 i=1,n |
| 2119 |
do 20 k=ia(i),ia(i+1)-1 |
| 2120 |
j = ja(k) |
| 2121 |
abd(i-j+mdiag,j) = a(k) |
| 2122 |
20 continue |
| 2123 |
30 continue |
| 2124 |
return |
| 2125 |
c------------- end of csrbnd ------------------------------------------- |
| 2126 |
c----------------------------------------------------------------------- |
| 2127 |
end |
| 2128 |
c----------------------------------------------------------------------- |
| 2129 |
subroutine bndcsr (n,abd,nabd,lowd,ml,mu,a,ja,ia,len,ierr) |
| 2130 |
real*8 a(*),abd(nabd,*), t |
| 2131 |
integer ia(n+1),ja(*) |
| 2132 |
c----------------------------------------------------------------------- |
| 2133 |
c Banded (Linpack ) format to Compressed Sparse Row format. |
| 2134 |
c----------------------------------------------------------------------- |
| 2135 |
c on entry: |
| 2136 |
c---------- |
| 2137 |
c n = integer,the actual row dimension of the matrix. |
| 2138 |
c |
| 2139 |
c nabd = first dimension of array abd. |
| 2140 |
c |
| 2141 |
c abd = real array containing the values of the matrix stored in |
| 2142 |
c banded form. The j-th column of abd contains the elements |
| 2143 |
c of the j-th column of the original matrix,comprised in the |
| 2144 |
c band ( i in (j-ml,j+mu) ) with the lowest diagonal located |
| 2145 |
c in row lowd (see below). |
| 2146 |
c |
| 2147 |
c lowd = integer. this should be set to the row number in abd where |
| 2148 |
c the lowest diagonal (leftmost) of A is located. |
| 2149 |
c lowd should be s.t. ( 1 .le. lowd .le. nabd). |
| 2150 |
c The subroutines dgbco, ... of linpack use lowd=2*ml+mu+1. |
| 2151 |
c |
| 2152 |
c ml = integer. equal to the bandwidth of the strict lower part of A |
| 2153 |
c mu = integer. equal to the bandwidth of the strict upper part of A |
| 2154 |
c thus the total bandwidth of A is ml+mu+1. |
| 2155 |
c if ml+mu+1 is found to be larger than nabd then an error |
| 2156 |
c message is set. see ierr. |
| 2157 |
c |
| 2158 |
c len = integer. length of arrays a and ja. bndcsr will stop if the |
| 2159 |
c length of the arrays a and ja is insufficient to store the |
| 2160 |
c matrix. see ierr. |
| 2161 |
c |
| 2162 |
c on return: |
| 2163 |
c----------- |
| 2164 |
c a, |
| 2165 |
c ja, |
| 2166 |
c ia = input matrix stored in compressed sparse row format. |
| 2167 |
c |
| 2168 |
c lowd = if on entry lowd was zero then lowd is reset to the default |
| 2169 |
c value ml+mu+l. |
| 2170 |
c |
| 2171 |
c ierr = integer. used for error message output. |
| 2172 |
c ierr .eq. 0 :means normal return |
| 2173 |
c ierr .eq. -1 : means invalid value for lowd. |
| 2174 |
c ierr .gt. 0 : means that there was not enough storage in a and ja |
| 2175 |
c for storing the ourput matrix. The process ran out of space |
| 2176 |
c (as indicated by len) while trying to fill row number ierr. |
| 2177 |
c This should give an idea of much more storage might be required. |
| 2178 |
c Moreover, the first irow-1 rows are correctly filled. |
| 2179 |
c |
| 2180 |
c notes: the values in abd found to be equal to zero |
| 2181 |
c ----- (actual test: if (abd(...) .eq. 0.0d0) are removed. |
| 2182 |
c The resulting may not be identical to a csr matrix |
| 2183 |
c originally transformed to a bnd format. |
| 2184 |
c |
| 2185 |
c----------------------------------------------------------------------- |
| 2186 |
ierr = 0 |
| 2187 |
c----------- |
| 2188 |
if (lowd .gt. nabd .or. lowd .le. 0) then |
| 2189 |
ierr = -1 |
| 2190 |
return |
| 2191 |
endif |
| 2192 |
c----------- |
| 2193 |
ko = 1 |
| 2194 |
ia(1) = 1 |
| 2195 |
do 30 irow=1,n |
| 2196 |
c----------------------------------------------------------------------- |
| 2197 |
i = lowd |
| 2198 |
do 20 j=irow-ml,irow+mu |
| 2199 |
if (j .le. 0 ) goto 19 |
| 2200 |
if (j .gt. n) goto 21 |
| 2201 |
t = abd(i,j) |
| 2202 |
if (t .eq. 0.0d0) goto 19 |
| 2203 |
if (ko .gt. len) then |
| 2204 |
ierr = irow |
| 2205 |
return |
| 2206 |
endif |
| 2207 |
a(ko) = t |
| 2208 |
ja(ko) = j |
| 2209 |
ko = ko+1 |
| 2210 |
19 i = i-1 |
| 2211 |
20 continue |
| 2212 |
c end for row irow |
| 2213 |
21 ia(irow+1) = ko |
| 2214 |
30 continue |
| 2215 |
return |
| 2216 |
c------------- end of bndcsr ------------------------------------------- |
| 2217 |
c----------------------------------------------------------------------- |
| 2218 |
end |
| 2219 |
c----------------------------------------------------------------------- |
| 2220 |
subroutine csrssk (n,imod,a,ja,ia,asky,isky,nzmax,ierr) |
| 2221 |
real*8 a(*),asky(nzmax) |
| 2222 |
integer n, imod, nzmax, ierr, ia(n+1), isky(n+1), ja(*) |
| 2223 |
c----------------------------------------------------------------------- |
| 2224 |
c Compressed Sparse Row to Symmetric Skyline Format |
| 2225 |
c or Symmetric Sparse Row |
| 2226 |
c----------------------------------------------------------------------- |
| 2227 |
c this subroutine translates a compressed sparse row or a symmetric |
| 2228 |
c sparse row format into a symmetric skyline format. |
| 2229 |
c the input matrix can be in either compressed sparse row or the |
| 2230 |
c symmetric sparse row format. The output matrix is in a symmetric |
| 2231 |
c skyline format: a real array containing the (active portions) of the |
| 2232 |
c rows in sequence and a pointer to the beginning of each row. |
| 2233 |
c |
| 2234 |
c This module is NOT in place. |
| 2235 |
c----------------------------------------------------------------------- |
| 2236 |
c Coded by Y. Saad, Oct 5, 1989. Revised Feb. 18, 1991. |
| 2237 |
c----------------------------------------------------------------------- |
| 2238 |
c |
| 2239 |
c on entry: |
| 2240 |
c---------- |
| 2241 |
c n = integer equal to the dimension of A. |
| 2242 |
c imod = integer indicating the variant of skyline format wanted: |
| 2243 |
c imod = 0 means the pointer isky points to the `zeroth' |
| 2244 |
c element of the row, i.e., to the position of the diagonal |
| 2245 |
c element of previous row (for i=1, isky(1)= 0) |
| 2246 |
c imod = 1 means that itpr points to the beginning of the row. |
| 2247 |
c imod = 2 means that isky points to the end of the row (diagonal |
| 2248 |
c element) |
| 2249 |
c |
| 2250 |
c a = real array of size nna containing the nonzero elements |
| 2251 |
c ja = integer array of size nnz containing the column positions |
| 2252 |
c of the corresponding elements in a. |
| 2253 |
c ia = integer of size n+1. ia(k) contains the position in a, ja of |
| 2254 |
c the beginning of the k-th row. |
| 2255 |
c nzmax = integer. must be set to the number of available locations |
| 2256 |
c in the output array asky. |
| 2257 |
c |
| 2258 |
c on return: |
| 2259 |
c---------- |
| 2260 |
c |
| 2261 |
c asky = real array containing the values of the matrix stored in skyline |
| 2262 |
c format. asky contains the sequence of active rows from |
| 2263 |
c i=1, to n, an active row being the row of elemnts of |
| 2264 |
c the matrix contained between the leftmost nonzero element |
| 2265 |
c and the diagonal element. |
| 2266 |
c isky = integer array of size n+1 containing the pointer array to |
| 2267 |
c each row. The meaning of isky depends on the input value of |
| 2268 |
c imod (see above). |
| 2269 |
c ierr = integer. Error message. If the length of the |
| 2270 |
c output array asky exceeds nzmax. ierr returns the minimum value |
| 2271 |
c needed for nzmax. otherwise ierr=0 (normal return). |
| 2272 |
c |
| 2273 |
c Notes: |
| 2274 |
c 1) This module is NOT in place. |
| 2275 |
c 2) even when imod = 2, length of isky is n+1, not n. |
| 2276 |
c |
| 2277 |
c----------------------------------------------------------------------- |
| 2278 |
c first determine individial bandwidths and pointers. |
| 2279 |
c----------------------------------------------------------------------- |
| 2280 |
ierr = 0 |
| 2281 |
isky(1) = 0 |
| 2282 |
do 3 i=1,n |
| 2283 |
ml = 0 |
| 2284 |
do 31 k=ia(i),ia(i+1)-1 |
| 2285 |
ml = max(ml,i-ja(k)+1) |
| 2286 |
31 continue |
| 2287 |
isky(i+1) = isky(i)+ml |
| 2288 |
3 continue |
| 2289 |
c |
| 2290 |
c test if there is enough space asky to do the copying. |
| 2291 |
c |
| 2292 |
nnz = isky(n+1) |
| 2293 |
if (nnz .gt. nzmax) then |
| 2294 |
ierr = nnz |
| 2295 |
return |
| 2296 |
endif |
| 2297 |
c |
| 2298 |
c fill asky with zeros. |
| 2299 |
c |
| 2300 |
do 1 k=1, nnz |
| 2301 |
asky(k) = 0.0d0 |
| 2302 |
1 continue |
| 2303 |
c |
| 2304 |
c copy nonzero elements. |
| 2305 |
c |
| 2306 |
do 4 i=1,n |
| 2307 |
kend = isky(i+1) |
| 2308 |
do 41 k=ia(i),ia(i+1)-1 |
| 2309 |
j = ja(k) |
| 2310 |
if (j .le. i) asky(kend+j-i) = a(k) |
| 2311 |
41 continue |
| 2312 |
4 continue |
| 2313 |
c |
| 2314 |
c modify pointer according to imod if necessary. |
| 2315 |
c |
| 2316 |
if (imod .eq. 0) return |
| 2317 |
if (imod .eq. 1) then |
| 2318 |
do 50 k=1, n+1 |
| 2319 |
isky(k) = isky(k)+1 |
| 2320 |
50 continue |
| 2321 |
endif |
| 2322 |
if (imod .eq. 2) then |
| 2323 |
do 60 k=1, n |
| 2324 |
isky(k) = isky(k+1) |
| 2325 |
60 continue |
| 2326 |
endif |
| 2327 |
c |
| 2328 |
return |
| 2329 |
c------------- end of csrssk ------------------------------------------- |
| 2330 |
c----------------------------------------------------------------------- |
| 2331 |
end |
| 2332 |
c----------------------------------------------------------------------- |
| 2333 |
subroutine sskssr (n,imod,asky,isky,ao,jao,iao,nzmax,ierr) |
| 2334 |
real*8 asky(*),ao(nzmax) |
| 2335 |
integer n, imod,nzmax,ierr, isky(n+1),iao(n+1),jao(nzmax) |
| 2336 |
c----------------------------------------------------------------------- |
| 2337 |
c Symmetric Skyline Format to Symmetric Sparse Row format. |
| 2338 |
c----------------------------------------------------------------------- |
| 2339 |
c tests for exact zeros in skyline matrix (and ignores them in |
| 2340 |
c output matrix). In place routine (a, isky :: ao, iao) |
| 2341 |
c----------------------------------------------------------------------- |
| 2342 |
c this subroutine translates a symmetric skyline format into a |
| 2343 |
c symmetric sparse row format. Each element is tested to see if it is |
| 2344 |
c a zero element. Only the actual nonzero elements are retained. Note |
| 2345 |
c that the test used is simple and does take into account the smallness |
| 2346 |
c of a value. the subroutine filter (see unary module) can be used |
| 2347 |
c for this purpose. |
| 2348 |
c----------------------------------------------------------------------- |
| 2349 |
c Coded by Y. Saad, Oct 5, 1989. Revised Feb 18, 1991./ |
| 2350 |
c----------------------------------------------------------------------- |
| 2351 |
c |
| 2352 |
c on entry: |
| 2353 |
c---------- |
| 2354 |
c n = integer equal to the dimension of A. |
| 2355 |
c imod = integer indicating the variant of skyline format used: |
| 2356 |
c imod = 0 means the pointer iao points to the `zeroth' |
| 2357 |
c element of the row, i.e., to the position of the diagonal |
| 2358 |
c element of previous row (for i=1, iao(1)= 0) |
| 2359 |
c imod = 1 means that itpr points to the beginning of the row. |
| 2360 |
c imod = 2 means that iao points to the end of the row |
| 2361 |
c (diagonal element) |
| 2362 |
c asky = real array containing the values of the matrix. asky contains |
| 2363 |
c the sequence of active rows from i=1, to n, an active row |
| 2364 |
c being the row of elemnts of the matrix contained between the |
| 2365 |
c leftmost nonzero element and the diagonal element. |
| 2366 |
c isky = integer array of size n+1 containing the pointer array to |
| 2367 |
c each row. isky (k) contains the address of the beginning of the |
| 2368 |
c k-th active row in the array asky. |
| 2369 |
c nzmax = integer. equal to the number of available locations in the |
| 2370 |
c output array ao. |
| 2371 |
c |
| 2372 |
c on return: |
| 2373 |
c ---------- |
| 2374 |
c ao = real array of size nna containing the nonzero elements |
| 2375 |
c jao = integer array of size nnz containing the column positions |
| 2376 |
c of the corresponding elements in a. |
| 2377 |
c iao = integer of size n+1. iao(k) contains the position in a, ja of |
| 2378 |
c the beginning of the k-th row. |
| 2379 |
c ierr = integer. Serving as error message. If the length of the |
| 2380 |
c output arrays ao, jao exceeds nzmax then ierr returns |
| 2381 |
c the row number where the algorithm stopped: rows |
| 2382 |
c i, to ierr-1 have been processed succesfully. |
| 2383 |
c ierr = 0 means normal return. |
| 2384 |
c ierr = -1 : illegal value for imod |
| 2385 |
c Notes: |
| 2386 |
c------- |
| 2387 |
c This module is in place: ao and iao can be the same as asky, and isky. |
| 2388 |
c----------------------------------------------------------------------- |
| 2389 |
c local variables |
| 2390 |
integer next, kend, kstart, i, j |
| 2391 |
ierr = 0 |
| 2392 |
c |
| 2393 |
c check for validity of imod |
| 2394 |
c |
| 2395 |
if (imod.ne.0 .and. imod.ne.1 .and. imod .ne. 2) then |
| 2396 |
ierr =-1 |
| 2397 |
return |
| 2398 |
endif |
| 2399 |
c |
| 2400 |
c next = pointer to next available position in output matrix |
| 2401 |
c kend = pointer to end of current row in skyline matrix. |
| 2402 |
c |
| 2403 |
next = 1 |
| 2404 |
c |
| 2405 |
c set kend = start position -1 in skyline matrix. |
| 2406 |
c |
| 2407 |
kend = 0 |
| 2408 |
if (imod .eq. 1) kend = isky(1)-1 |
| 2409 |
if (imod .eq. 0) kend = isky(1) |
| 2410 |
c |
| 2411 |
c loop through all rows |
| 2412 |
c |
| 2413 |
do 50 i=1,n |
| 2414 |
c |
| 2415 |
c save value of pointer to ith row in output matrix |
| 2416 |
c |
| 2417 |
iao(i) = next |
| 2418 |
c |
| 2419 |
c get beginnning and end of skyline row |
| 2420 |
c |
| 2421 |
kstart = kend+1 |
| 2422 |
if (imod .eq. 0) kend = isky(i+1) |
| 2423 |
if (imod .eq. 1) kend = isky(i+1)-1 |
| 2424 |
if (imod .eq. 2) kend = isky(i) |
| 2425 |
c |
| 2426 |
c copy element into output matrix unless it is a zero element. |
| 2427 |
c |
| 2428 |
do 40 k=kstart,kend |
| 2429 |
if (asky(k) .eq. 0.0d0) goto 40 |
| 2430 |
j = i-(kend-k) |
| 2431 |
jao(next) = j |
| 2432 |
ao(next) = asky(k) |
| 2433 |
next=next+1 |
| 2434 |
if (next .gt. nzmax+1) then |
| 2435 |
ierr = i |
| 2436 |
return |
| 2437 |
endif |
| 2438 |
40 continue |
| 2439 |
50 continue |
| 2440 |
iao(n+1) = next |
| 2441 |
return |
| 2442 |
c-------------end-of-sskssr -------------------------------------------- |
| 2443 |
c----------------------------------------------------------------------- |
| 2444 |
end |
| 2445 |
c----------------------------------------------------------------------- |
| 2446 |
subroutine csrjad (nrow, a, ja, ia, idiag, iperm, ao, jao, iao) |
| 2447 |
integer ja(*), jao(*), ia(nrow+1), iperm(nrow), iao(nrow) |
| 2448 |
real*8 a(*), ao(*) |
| 2449 |
c----------------------------------------------------------------------- |
| 2450 |
c Compressed Sparse Row to JAgged Diagonal storage. |
| 2451 |
c----------------------------------------------------------------------- |
| 2452 |
c this subroutine converts matrix stored in the compressed sparse |
| 2453 |
c row format to the jagged diagonal format. The data structure |
| 2454 |
c for the JAD (Jagged Diagonal storage) is as follows. The rows of |
| 2455 |
c the matrix are (implicitly) permuted so that their lengths are in |
| 2456 |
c decreasing order. The real entries ao(*) and their column indices |
| 2457 |
c jao(*) are stored in succession. The number of such diagonals is idiag. |
| 2458 |
c the lengths of each of these diagonals is stored in iao(*). |
| 2459 |
c For more details see [E. Anderson and Y. Saad, |
| 2460 |
c ``Solving sparse triangular systems on parallel computers'' in |
| 2461 |
c Inter. J. of High Speed Computing, Vol 1, pp. 73-96 (1989).] |
| 2462 |
c or [Y. Saad, ``Krylov Subspace Methods on Supercomputers'' |
| 2463 |
c SIAM J. on Stat. Scient. Comput., volume 10, pp. 1200-1232 (1989).] |
| 2464 |
c----------------------------------------------------------------------- |
| 2465 |
c on entry: |
| 2466 |
c---------- |
| 2467 |
c nrow = row dimension of the matrix A. |
| 2468 |
c |
| 2469 |
c a, |
| 2470 |
c ia, |
| 2471 |
c ja = input matrix in compressed sparse row format. |
| 2472 |
c |
| 2473 |
c on return: |
| 2474 |
c---------- |
| 2475 |
c |
| 2476 |
c idiag = integer. The number of jagged diagonals in the matrix. |
| 2477 |
c |
| 2478 |
c iperm = integer array of length nrow containing the permutation |
| 2479 |
c of the rows that leads to a decreasing order of the |
| 2480 |
c number of nonzero elements. |
| 2481 |
c |
| 2482 |
c ao = real array containing the values of the matrix A in |
| 2483 |
c jagged diagonal storage. The j-diagonals are stored |
| 2484 |
c in ao in sequence. |
| 2485 |
c |
| 2486 |
c jao = integer array containing the column indices of the |
| 2487 |
c entries in ao. |
| 2488 |
c |
| 2489 |
c iao = integer array containing pointers to the beginning |
| 2490 |
c of each j-diagonal in ao, jao. iao is also used as |
| 2491 |
c a work array and it should be of length n at least. |
| 2492 |
c |
| 2493 |
c----------------------------------------------------------------------- |
| 2494 |
c ---- define initial iperm and get lengths of each row |
| 2495 |
c ---- jao is used a work vector to store tehse lengths |
| 2496 |
c |
| 2497 |
idiag = 0 |
| 2498 |
ilo = nrow |
| 2499 |
do 10 j=1, nrow |
| 2500 |
iperm(j) = j |
| 2501 |
len = ia(j+1) - ia(j) |
| 2502 |
ilo = min(ilo,len) |
| 2503 |
idiag = max(idiag,len) |
| 2504 |
jao(j) = len |
| 2505 |
10 continue |
| 2506 |
c |
| 2507 |
c call sorter to get permutation. use iao as work array. |
| 2508 |
c |
| 2509 |
call dcsort (jao, nrow, iao, iperm, ilo, idiag) |
| 2510 |
c |
| 2511 |
c define output data structure. first lengths of j-diagonals |
| 2512 |
c |
| 2513 |
do 20 j=1, nrow |
| 2514 |
iao(j) = 0 |
| 2515 |
20 continue |
| 2516 |
do 40 k=1, nrow |
| 2517 |
len = jao(iperm(k)) |
| 2518 |
do 30 i=1,len |
| 2519 |
iao(i) = iao(i)+1 |
| 2520 |
30 continue |
| 2521 |
40 continue |
| 2522 |
c |
| 2523 |
c get the output matrix itself |
| 2524 |
c |
| 2525 |
k1 = 1 |
| 2526 |
k0 = k1 |
| 2527 |
do 60 jj=1, idiag |
| 2528 |
len = iao(jj) |
| 2529 |
do 50 k=1,len |
| 2530 |
i = ia(iperm(k))+jj-1 |
| 2531 |
ao(k1) = a(i) |
| 2532 |
jao(k1) = ja(i) |
| 2533 |
k1 = k1+1 |
| 2534 |
50 continue |
| 2535 |
iao(jj) = k0 |
| 2536 |
k0 = k1 |
| 2537 |
60 continue |
| 2538 |
iao(idiag+1) = k1 |
| 2539 |
return |
| 2540 |
c----------end-of-csrjad------------------------------------------------ |
| 2541 |
c----------------------------------------------------------------------- |
| 2542 |
end |
| 2543 |
c----------------------------------------------------------------------- |
| 2544 |
subroutine jadcsr (nrow, idiag, a, ja, ia, iperm, ao, jao, iao) |
| 2545 |
integer ja(*), jao(*), ia(idiag+1), iperm(nrow), iao(nrow+1) |
| 2546 |
real*8 a(*), ao(*) |
| 2547 |
c----------------------------------------------------------------------- |
| 2548 |
c Jagged Diagonal Storage to Compressed Sparse Row |
| 2549 |
c----------------------------------------------------------------------- |
| 2550 |
c this subroutine converts a matrix stored in the jagged diagonal format |
| 2551 |
c to the compressed sparse row format. |
| 2552 |
c----------------------------------------------------------------------- |
| 2553 |
c on entry: |
| 2554 |
c---------- |
| 2555 |
c nrow = integer. the row dimension of the matrix A. |
| 2556 |
c |
| 2557 |
c idiag = integer. The number of jagged diagonals in the data |
| 2558 |
c structure a, ja, ia. |
| 2559 |
c |
| 2560 |
c a, |
| 2561 |
c ja, |
| 2562 |
c ia = input matrix in jagged diagonal format. |
| 2563 |
c |
| 2564 |
c iperm = permutation of the rows used to obtain the JAD ordering. |
| 2565 |
c |
| 2566 |
c on return: |
| 2567 |
c---------- |
| 2568 |
c |
| 2569 |
c ao, jao, |
| 2570 |
c iao = matrix in CSR format. |
| 2571 |
c----------------------------------------------------------------------- |
| 2572 |
c determine first the pointers for output matrix. Go through the |
| 2573 |
c structure once: |
| 2574 |
c |
| 2575 |
do 137 j=1,nrow |
| 2576 |
jao(j) = 0 |
| 2577 |
137 continue |
| 2578 |
c |
| 2579 |
c compute the lengths of each row of output matrix - |
| 2580 |
c |
| 2581 |
do 140 i=1, idiag |
| 2582 |
len = ia(i+1)-ia(i) |
| 2583 |
do 138 k=1,len |
| 2584 |
jao(iperm(k)) = jao(iperm(k))+1 |
| 2585 |
138 continue |
| 2586 |
140 continue |
| 2587 |
c |
| 2588 |
c remember to permute |
| 2589 |
c |
| 2590 |
kpos = 1 |
| 2591 |
iao(1) = 1 |
| 2592 |
do 141 i=1, nrow |
| 2593 |
kpos = kpos+jao(i) |
| 2594 |
iao(i+1) = kpos |
| 2595 |
141 continue |
| 2596 |
c |
| 2597 |
c copy elemnts one at a time. |
| 2598 |
c |
| 2599 |
do 200 jj = 1, idiag |
| 2600 |
k1 = ia(jj)-1 |
| 2601 |
len = ia(jj+1)-k1-1 |
| 2602 |
do 160 k=1,len |
| 2603 |
kpos = iao(iperm(k)) |
| 2604 |
ao(kpos) = a(k1+k) |
| 2605 |
jao(kpos) = ja(k1+k) |
| 2606 |
iao(iperm(k)) = kpos+1 |
| 2607 |
160 continue |
| 2608 |
200 continue |
| 2609 |
c |
| 2610 |
c rewind pointers |
| 2611 |
c |
| 2612 |
do 5 j=nrow,1,-1 |
| 2613 |
iao(j+1) = iao(j) |
| 2614 |
5 continue |
| 2615 |
iao(1) = 1 |
| 2616 |
return |
| 2617 |
c----------end-of-jadcsr------------------------------------------------ |
| 2618 |
c----------------------------------------------------------------------- |
| 2619 |
end |
| 2620 |
subroutine dcsort(ival, n, icnt, index, ilo, ihi) |
| 2621 |
c----------------------------------------------------------------------- |
| 2622 |
c Specifications for arguments: |
| 2623 |
c ---------------------------- |
| 2624 |
integer n, ilo, ihi, ival(n), icnt(ilo:ihi), index(n) |
| 2625 |
c----------------------------------------------------------------------- |
| 2626 |
c This routine computes a permutation which, when applied to the |
| 2627 |
c input vector ival, sorts the integers in ival in descending |
| 2628 |
c order. The permutation is represented by the vector index. The |
| 2629 |
c permuted ival can be interpreted as follows: |
| 2630 |
c ival(index(i-1)) .ge. ival(index(i)) .ge. ival(index(i+1)) |
| 2631 |
c |
| 2632 |
c A specialized sort, the distribution counting sort, is used |
| 2633 |
c which takes advantage of the knowledge that |
| 2634 |
c 1) The values are in the (small) range [ ilo, ihi ] |
| 2635 |
c 2) Values are likely to be repeated often |
| 2636 |
c |
| 2637 |
c contributed to SPARSKIT by Mike Heroux. (Cray Research) |
| 2638 |
c --------------------------------------- |
| 2639 |
c----------------------------------------------------------------------- |
| 2640 |
c Usage: |
| 2641 |
c------ |
| 2642 |
c call dcsort( ival, n, icnt, index, ilo, ihi ) |
| 2643 |
c |
| 2644 |
c Arguments: |
| 2645 |
c----------- |
| 2646 |
c ival integer array (input) |
| 2647 |
c On entry, ia is an n dimensional array that contains |
| 2648 |
c the values to be sorted. ival is unchanged on exit. |
| 2649 |
c |
| 2650 |
c n integer (input) |
| 2651 |
c On entry, n is the number of elements in ival and index. |
| 2652 |
c |
| 2653 |
c icnt integer (work) |
| 2654 |
c On entry, is an integer work vector of length |
| 2655 |
c (ihi - ilo + 1). |
| 2656 |
c |
| 2657 |
c index integer array (output) |
| 2658 |
c On exit, index is an n-length integer vector containing |
| 2659 |
c the permutation which sorts the vector ival. |
| 2660 |
c |
| 2661 |
c ilo integer (input) |
| 2662 |
c On entry, ilo is .le. to the minimum value in ival. |
| 2663 |
c |
| 2664 |
c ihi integer (input) |
| 2665 |
c On entry, ihi is .ge. to the maximum value in ival. |
| 2666 |
c |
| 2667 |
c Remarks: |
| 2668 |
c--------- |
| 2669 |
c The permutation is NOT applied to the vector ival. |
| 2670 |
c |
| 2671 |
c---------------------------------------------------------------- |
| 2672 |
c |
| 2673 |
c Local variables: |
| 2674 |
c Other integer values are temporary indices. |
| 2675 |
c |
| 2676 |
c Author: |
| 2677 |
c-------- |
| 2678 |
c Michael Heroux |
| 2679 |
c Sandra Carney |
| 2680 |
c Mathematical Software Research Group |
| 2681 |
c Cray Research, Inc. |
| 2682 |
c |
| 2683 |
c References: |
| 2684 |
c Knuth, Donald E., "The Art of Computer Programming, Volume 3: |
| 2685 |
c Sorting and Searching," Addison-Wesley, Reading, Massachusetts, |
| 2686 |
c 1973, pp. 78-79. |
| 2687 |
c |
| 2688 |
c Revision history: |
| 2689 |
c 05/09/90: Original implementation. A variation of the |
| 2690 |
c Distribution Counting Sort recommended by |
| 2691 |
c Sandra Carney. (Mike Heroux) |
| 2692 |
c |
| 2693 |
c----------------------------------------------------------------- |
| 2694 |
c ---------------------------------- |
| 2695 |
c Specifications for local variables |
| 2696 |
c ---------------------------------- |
| 2697 |
integer i, j, ivalj |
| 2698 |
c |
| 2699 |
c -------------------------- |
| 2700 |
c First executable statement |
| 2701 |
c -------------------------- |
| 2702 |
do 10 i = ilo, ihi |
| 2703 |
icnt(i) = 0 |
| 2704 |
10 continue |
| 2705 |
c |
| 2706 |
do 20 i = 1, n |
| 2707 |
icnt(ival(i)) = icnt(ival(i)) + 1 |
| 2708 |
20 continue |
| 2709 |
c |
| 2710 |
do 30 i = ihi-1,ilo,-1 |
| 2711 |
icnt(i) = icnt(i) + icnt(i+1) |
| 2712 |
30 continue |
| 2713 |
c |
| 2714 |
do 40 j = n, 1, -1 |
| 2715 |
ivalj = ival(j) |
| 2716 |
index(icnt(ivalj)) = j |
| 2717 |
icnt(ivalj) = icnt(ivalj) - 1 |
| 2718 |
40 continue |
| 2719 |
return |
| 2720 |
end |
| 2721 |
c-------end-of-dcsort--------------------------------------------------- |
| 2722 |
c----------------------------------------------------------------------- |
| 2723 |
subroutine cooell(job,n,nnz,a,ja,ia,ao,jao,lda,ncmax,nc,ierr) |
| 2724 |
implicit none |
| 2725 |
integer job,n,nnz,lda,ncmax,nc,ierr |
| 2726 |
integer ja(nnz),ia(nnz),jao(lda,ncmax) |
| 2727 |
real*8 a(nnz),ao(lda,ncmax) |
| 2728 |
c----------------------------------------------------------------------- |
| 2729 |
c COOrdinate format to ELLpack format |
| 2730 |
c----------------------------------------------------------------------- |
| 2731 |
c On entry: |
| 2732 |
c job -- 0 if only pattern is to be processed(AO is not touched) |
| 2733 |
c n -- number of rows in the matrix |
| 2734 |
c a,ja,ia -- input matix in COO format |
| 2735 |
c lda -- leading dimension of array AO and JAO |
| 2736 |
c ncmax -- size of the second dimension of array AO and JAO |
| 2737 |
c |
| 2738 |
c On exit: |
| 2739 |
c ao,jao -- the matrix in ELL format |
| 2740 |
c nc -- maximum number of nonzeros per row |
| 2741 |
c ierr -- 0 if convertion succeeded |
| 2742 |
c -1 if LDA < N |
| 2743 |
c nc if NC > ncmax |
| 2744 |
c |
| 2745 |
c NOTE: the last column of JAO is used as work space!! |
| 2746 |
c----------------------------------------------------------------------- |
| 2747 |
integer i,j,k,ip |
| 2748 |
real*8 zero |
| 2749 |
logical copyval |
| 2750 |
parameter (zero=0.0D0) |
| 2751 |
c .. first executable statement .. |
| 2752 |
copyval = (job.ne.0) |
| 2753 |
if (lda .lt. n) then |
| 2754 |
ierr = -1 |
| 2755 |
return |
| 2756 |
endif |
| 2757 |
c .. use the last column of JAO as workspace |
| 2758 |
c .. initialize the work space |
| 2759 |
do i = 1, n |
| 2760 |
jao(i,ncmax) = 0 |
| 2761 |
enddo |
| 2762 |
nc = 0 |
| 2763 |
c .. go through ia and ja to find out number nonzero per row |
| 2764 |
do k = 1, nnz |
| 2765 |
i = ia(k) |
| 2766 |
jao(i,ncmax) = jao(i,ncmax) + 1 |
| 2767 |
enddo |
| 2768 |
c .. maximum number of nonzero per row |
| 2769 |
nc = 0 |
| 2770 |
do i = 1, n |
| 2771 |
if (nc.lt.jao(i,ncmax)) nc = jao(i,ncmax) |
| 2772 |
jao(i,ncmax) = 0 |
| 2773 |
enddo |
| 2774 |
c .. if nc > ncmax retrun now |
| 2775 |
if (nc.gt.ncmax) then |
| 2776 |
ierr = nc |
| 2777 |
return |
| 2778 |
endif |
| 2779 |
c .. go through ia and ja to copy the matrix to AO and JAO |
| 2780 |
do k = 1, nnz |
| 2781 |
i = ia(k) |
| 2782 |
j = ja(k) |
| 2783 |
jao(i,ncmax) = jao(i,ncmax) + 1 |
| 2784 |
ip = jao(i,ncmax) |
| 2785 |
if (ip.gt.nc) nc = ip |
| 2786 |
if (copyval) ao(i,ip) = a(k) |
| 2787 |
jao(i,ip) = j |
| 2788 |
enddo |
| 2789 |
c .. fill the unspecified elements of AO and JAO with zero diagonals |
| 2790 |
do i = 1, n |
| 2791 |
do j = ia(i+1)-ia(i)+1, nc |
| 2792 |
jao(i,j)=i |
| 2793 |
if(copyval) ao(i,j) = zero |
| 2794 |
enddo |
| 2795 |
enddo |
| 2796 |
ierr = 0 |
| 2797 |
c |
| 2798 |
return |
| 2799 |
end |
| 2800 |
c-----end-of-cooell----------------------------------------------------- |
| 2801 |
c----------------------------------------------------------------------- |
| 2802 |
subroutine xcooell(n,nnz,a,ja,ia,ac,jac,nac,ner,ncmax,ierr) |
| 2803 |
C----------------------------------------------------------------------- |
| 2804 |
C coordinate format to ellpack format. |
| 2805 |
C----------------------------------------------------------------------- |
| 2806 |
C |
| 2807 |
C DATE WRITTEN: June 4, 1989. |
| 2808 |
C |
| 2809 |
C PURPOSE |
| 2810 |
C ------- |
| 2811 |
C This subroutine takes a sparse matrix in coordinate format and |
| 2812 |
C converts it into the Ellpack-Itpack storage. |
| 2813 |
C |
| 2814 |
C Example: |
| 2815 |
C ------- |
| 2816 |
C ( 11 0 13 0 0 0 ) |
| 2817 |
C | 21 22 0 24 0 0 | |
| 2818 |
C | 0 32 33 0 35 0 | |
| 2819 |
C A = | 0 0 43 44 0 46 | |
| 2820 |
C | 51 0 0 54 55 0 | |
| 2821 |
C ( 61 62 0 0 65 66 ) |
| 2822 |
C |
| 2823 |
C Coordinate storage scheme: |
| 2824 |
C |
| 2825 |
C A = (11,22,33,44,55,66,13,21,24,32,35,43,46,51,54,61,62,65) |
| 2826 |
C IA = (1, 2, 3, 4, 5, 6, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6 ) |
| 2827 |
C JA = ( 1, 2, 3, 4, 5, 6, 3, 1, 4, 2, 5, 3, 6, 1, 4, 1, 2, 5) |
| 2828 |
C |
| 2829 |
C Ellpack-Itpack storage scheme: |
| 2830 |
C |
| 2831 |
C ( 11 13 0 0 ) ( 1 3 * * ) |
| 2832 |
C | 22 21 24 0 | | 2 1 4 * | |
| 2833 |
C AC = | 33 32 35 0 | JAC = | 3 2 5 * | |
| 2834 |
C | 44 43 46 0 | | 4 3 6 * | |
| 2835 |
C | 55 51 54 0 | | 5 1 4 * | |
| 2836 |
C ( 66 61 62 65 ) ( 6 1 2 5 ) |
| 2837 |
C |
| 2838 |
C Note: * means that you can store values from 1 to 6 (1 to n, where |
| 2839 |
C n is the order of the matrix) in that position in the array. |
| 2840 |
C |
| 2841 |
C Contributed by: |
| 2842 |
C --------------- |
| 2843 |
C Ernest E. Rothman |
| 2844 |
C Cornell Thoery Center/Cornell National Supercomputer Facility |
| 2845 |
C e-mail address: BITNET: [email protected] |
| 2846 |
C INTERNET: [email protected] |
| 2847 |
C |
| 2848 |
C checked and modified 04/13/90 Y.Saad. |
| 2849 |
C |
| 2850 |
C REFERENCES |
| 2851 |
C ---------- |
| 2852 |
C Kincaid, D. R.; Oppe, T. C.; Respess, J. R.; Young, D. M. 1984. |
| 2853 |
C ITPACKV 2C User's Guide, CNA-191. Center for Numerical Analysis, |
| 2854 |
C University of Texas at Austin. |
| 2855 |
C |
| 2856 |
C "Engineering and Scientific Subroutine Library; Guide and |
| 2857 |
C Reference; Release 3 (SC23-0184-3). Pp. 79-86. |
| 2858 |
C |
| 2859 |
C----------------------------------------------------------------------- |
| 2860 |
C |
| 2861 |
C INPUT PARAMETERS |
| 2862 |
C ---------------- |
| 2863 |
C N - Integer. The size of the square matrix. |
| 2864 |
C |
| 2865 |
C NNZ - Integer. Must be greater than or equal to the number of |
| 2866 |
C nonzero elements in the sparse matrix. Dimension of A, IA |
| 2867 |
C and JA. |
| 2868 |
C |
| 2869 |
C NCA - Integer. First dimension of output arrays ca and jac. |
| 2870 |
C |
| 2871 |
C A(NNZ) - Real array. (Double precision) |
| 2872 |
C Stored entries of the sparse matrix A. |
| 2873 |
C NNZ is the number of nonzeros. |
| 2874 |
C |
| 2875 |
C IA(NNZ) - Integer array. |
| 2876 |
C Pointers to specify rows for the stored nonzero entries |
| 2877 |
C in A. |
| 2878 |
C |
| 2879 |
C JA(NNZ) - Integer array. |
| 2880 |
C Pointers to specify columns for the stored nonzero |
| 2881 |
C entries in A. |
| 2882 |
C |
| 2883 |
C NER - Integer. Must be set greater than or equal to the maximum |
| 2884 |
C number of nonzeros in any row of the sparse matrix. |
| 2885 |
C |
| 2886 |
C OUTPUT PARAMETERS |
| 2887 |
C ----------------- |
| 2888 |
C AC(NAC,*) - Real array. (Double precision) |
| 2889 |
C Stored entries of the sparse matrix A in compressed |
| 2890 |
C storage mode. |
| 2891 |
C |
| 2892 |
C JAC(NAC,*) - Integer array. |
| 2893 |
C Contains the column numbers of the sparse matrix |
| 2894 |
C elements stored in the corresponding positions in |
| 2895 |
C array AC. |
| 2896 |
C |
| 2897 |
C NCMAX - Integer. Equals the maximum number of nonzeros in any |
| 2898 |
C row of the sparse matrix. |
| 2899 |
C |
| 2900 |
C IERR - Error parameter is returned as zero on successful |
| 2901 |
C execution of the subroutin<e. |
| 2902 |
C Error diagnostics are given by means of positive values |
| 2903 |
C of this parameter as follows: |
| 2904 |
C |
| 2905 |
C IERR = -1 - NER is too small and should be set equal |
| 2906 |
C to NCMAX. The array AC may not be large |
| 2907 |
C enough to accomodate all the non-zeros of |
| 2908 |
C of the sparse matrix. |
| 2909 |
C IERR = 1 - The array AC has a zero column. (Warning) |
| 2910 |
C IERR = 2 - The array AC has a zero row. (Warning) |
| 2911 |
C |
| 2912 |
C--------------------------------------------------------------------- |
| 2913 |
real*8 a(nnz), ac(nac,ner) |
| 2914 |
integer ja(nnz), ia(nnz), jac(nac,ner), ierr, ncmax, icount |
| 2915 |
c |
| 2916 |
c- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 2917 |
c Initial error parameter to zero: |
| 2918 |
c |
| 2919 |
ierr = 0 |
| 2920 |
c |
| 2921 |
c- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 2922 |
c Initial output arrays to zero: |
| 2923 |
c |
| 2924 |
do 4 in = 1,ner |
| 2925 |
do 4 innz =1,n |
| 2926 |
jac(innz,in) = n |
| 2927 |
ac(innz,in) = 0.0d0 |
| 2928 |
4 continue |
| 2929 |
c |
| 2930 |
c- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 2931 |
c |
| 2932 |
c Assign nonzero elements of the sparse matrix (stored in the one |
| 2933 |
c dimensional array A to the two dimensional array AC. |
| 2934 |
c Also, assign the correct values with information about their |
| 2935 |
c column indices to the two dimensional array KA. And at the same |
| 2936 |
c time count the number of nonzeros in each row so that the |
| 2937 |
c parameter NCMAX equals the maximum number of nonzeros in any row |
| 2938 |
c of the sparse matrix. |
| 2939 |
c |
| 2940 |
ncmax = 1 |
| 2941 |
do 10 is = 1,n |
| 2942 |
k = 0 |
| 2943 |
do 30 ii = 1,nnz |
| 2944 |
if(ia(ii).eq.is)then |
| 2945 |
k = k + 1 |
| 2946 |
if (k .le. ner) then |
| 2947 |
ac(is,k) = a(ii) |
| 2948 |
jac(is,k) = ja(ii) |
| 2949 |
endif |
| 2950 |
endif |
| 2951 |
30 continue |
| 2952 |
if (k.ge.ncmax) ncmax = k |
| 2953 |
10 continue |
| 2954 |
c- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 2955 |
c |
| 2956 |
c Perform some simple error checks: |
| 2957 |
c |
| 2958 |
check maximum number of nonzeros in each row: |
| 2959 |
if (ncmax.eq.ner) ierr = 0 |
| 2960 |
if (ncmax.gt.ner) then |
| 2961 |
ierr = -1 |
| 2962 |
return |
| 2963 |
endif |
| 2964 |
c |
| 2965 |
check if there are any zero columns in AC: |
| 2966 |
c |
| 2967 |
do 45 in = 1,ncmax |
| 2968 |
icount = 0 |
| 2969 |
do 44 inn =1,n |
| 2970 |
if (ac(inn,in).ne.0.0d0) icount = 1 |
| 2971 |
44 continue |
| 2972 |
if (icount.eq.0) then |
| 2973 |
ierr = 1 |
| 2974 |
return |
| 2975 |
endif |
| 2976 |
45 continue |
| 2977 |
c |
| 2978 |
check if there are any zero rows in AC: |
| 2979 |
c |
| 2980 |
do 55 inn = 1,n |
| 2981 |
icount = 0 |
| 2982 |
do 54 in =1,ncmax |
| 2983 |
if (ac(inn,in).ne.0.0d0) icount = 1 |
| 2984 |
54 continue |
| 2985 |
if (icount.eq.0) then |
| 2986 |
ierr = 2 |
| 2987 |
return |
| 2988 |
endif |
| 2989 |
55 continue |
| 2990 |
return |
| 2991 |
c------------- end of xcooell ------------------------------------------- |
| 2992 |
end |
| 2993 |
c----------------------------------------------------------------------- |
| 2994 |
subroutine csruss (nrow,a,ja,ia,diag,al,jal,ial,au,jau,iau) |
| 2995 |
real*8 a(*),al(*),diag(*),au(*) |
| 2996 |
integer nrow,ja(*),ia(nrow+1),jal(*),ial(nrow+1),jau(*), |
| 2997 |
* iau(nrow+1) |
| 2998 |
c----------------------------------------------------------------------- |
| 2999 |
c Compressed Sparse Row to Unsymmetric Sparse Skyline format |
| 3000 |
c----------------------------------------------------------------------- |
| 3001 |
c this subroutine converts a matrix stored in csr format into a nonsym. |
| 3002 |
c sparse skyline format. This latter format does not assume |
| 3003 |
c that the matrix has a symmetric pattern and consists of the following |
| 3004 |
c * the diagonal of A stored separately in diag(*); |
| 3005 |
c * The strict lower part of A is stored in CSR format in al,jal,ial |
| 3006 |
c * The strict upper part is stored in CSC format in au,jau,iau. |
| 3007 |
c----------------------------------------------------------------------- |
| 3008 |
c On entry |
| 3009 |
c--------- |
| 3010 |
c nrow = dimension of the matrix a. |
| 3011 |
c a = real array containing the nonzero values of the matrix |
| 3012 |
c stored rowwise. |
| 3013 |
c ja = column indices of the values in array a |
| 3014 |
c ia = integer array of length n+1 containing the pointers to |
| 3015 |
c beginning of each row in arrays a, ja. |
| 3016 |
c |
| 3017 |
c On return |
| 3018 |
c---------- |
| 3019 |
c diag = array containing the diagonal entries of A |
| 3020 |
c al,jal,ial = matrix in CSR format storing the strict lower |
| 3021 |
c trangular part of A. |
| 3022 |
c au,jau,iau = matrix in CSC format storing the strict upper |
| 3023 |
c triangular part of A. |
| 3024 |
c----------------------------------------------------------------------- |
| 3025 |
integer i, j, k, kl, ku |
| 3026 |
c |
| 3027 |
c determine U's data structure first |
| 3028 |
c |
| 3029 |
do 1 i=1,nrow+1 |
| 3030 |
iau(i) = 0 |
| 3031 |
1 continue |
| 3032 |
do 3 i=1, nrow |
| 3033 |
do 2 k=ia(i), ia(i+1)-1 |
| 3034 |
j = ja(k) |
| 3035 |
if (j .gt. i) iau(j+1) = iau(j+1)+1 |
| 3036 |
2 continue |
| 3037 |
3 continue |
| 3038 |
c |
| 3039 |
c compute pointers from lengths |
| 3040 |
c |
| 3041 |
iau(1) = 1 |
| 3042 |
do 4 i=1,nrow |
| 3043 |
iau(i+1) = iau(i)+iau(i+1) |
| 3044 |
ial(i+1) = ial(i)+ial(i+1) |
| 3045 |
4 continue |
| 3046 |
c |
| 3047 |
c now do the extractions. scan all rows. |
| 3048 |
c |
| 3049 |
kl = 1 |
| 3050 |
ial(1) = kl |
| 3051 |
do 7 i=1, nrow |
| 3052 |
c |
| 3053 |
c scan all elements in a row |
| 3054 |
c |
| 3055 |
do 71 k = ia(i), ia(i+1)-1 |
| 3056 |
j = ja(k) |
| 3057 |
c |
| 3058 |
c if in upper part, store in row j (of transp(U) ) |
| 3059 |
c |
| 3060 |
if (j .gt. i) then |
| 3061 |
ku = iau(j) |
| 3062 |
au(ku) = a(k) |
| 3063 |
jau(ku) = i |
| 3064 |
iau(j) = ku+1 |
| 3065 |
elseif (j .eq. i) then |
| 3066 |
diag(i) = a(k) |
| 3067 |
elseif (j .lt. i) then |
| 3068 |
al(kl) = a(k) |
| 3069 |
jal(kl) = j |
| 3070 |
kl = kl+1 |
| 3071 |
endif |
| 3072 |
71 continue |
| 3073 |
ial(i+1) = kl |
| 3074 |
7 continue |
| 3075 |
c |
| 3076 |
c readjust iau |
| 3077 |
c |
| 3078 |
do 8 i=nrow,1,-1 |
| 3079 |
iau(i+1) = iau(i) |
| 3080 |
8 continue |
| 3081 |
iau(1) = 1 |
| 3082 |
c--------------- end-of-csruss ----------------------------------------- |
| 3083 |
c----------------------------------------------------------------------- |
| 3084 |
end |
| 3085 |
c----------------------------------------------------------------------- |
| 3086 |
subroutine usscsr (nrow,a,ja,ia,diag,al,jal,ial,au,jau,iau) |
| 3087 |
real*8 a(*),al(*),diag(*),au(*) |
| 3088 |
integer ja(*),ia(nrow+1),jal(*),ial(nrow+1),jau(*),iau(nrow+1) |
| 3089 |
c----------------------------------------------------------------------- |
| 3090 |
c Unsymmetric Sparse Skyline format to Compressed Sparse Row |
| 3091 |
c----------------------------------------------------------------------- |
| 3092 |
c this subroutine converts a matrix stored in nonsymmetric sparse |
| 3093 |
c skyline format into csr format. The sparse skyline format is |
| 3094 |
c described in routine csruss. |
| 3095 |
c----------------------------------------------------------------------- |
| 3096 |
c----------------------------------------------------------------------- |
| 3097 |
c On entry |
| 3098 |
c----------------------------------------------------------------------- |
| 3099 |
c nrow = dimension of the matrix a. |
| 3100 |
c diag = array containing the diagonal entries of A |
| 3101 |
c al,jal,ial = matrix in CSR format storing the strict lower |
| 3102 |
c trangular part of A. |
| 3103 |
c au,jau,iau = matrix in CSC format storing the strict upper |
| 3104 |
c trangular part of A. |
| 3105 |
c On return |
| 3106 |
c --------- |
| 3107 |
c a = real array containing the nonzero values of the matrix |
| 3108 |
c stored rowwise. |
| 3109 |
c ja = column indices of the values in array a |
| 3110 |
c ia = integer array of length n+1 containing the pointers to |
| 3111 |
c beginning of each row in arrays a, ja. |
| 3112 |
c |
| 3113 |
c----------------------------------------------------------------------- |
| 3114 |
c |
| 3115 |
c count elements in lower part + diagonal |
| 3116 |
c |
| 3117 |
do 1 i=1, nrow |
| 3118 |
ia(i+1) = ial(i+1)-ial(i)+1 |
| 3119 |
1 continue |
| 3120 |
c |
| 3121 |
c count elements in upper part |
| 3122 |
c |
| 3123 |
do 3 i=1, nrow |
| 3124 |
do 2 k=iau(i), iau(i+1)-1 |
| 3125 |
j = jau(k) |
| 3126 |
ia(j+1) = ia(j+1)+1 |
| 3127 |
2 continue |
| 3128 |
3 continue |
| 3129 |
c---------- compute pointers from lengths ------------------------------ |
| 3130 |
ia(1) = 1 |
| 3131 |
do 4 i=1,nrow |
| 3132 |
ia(i+1) = ia(i)+ia(i+1) |
| 3133 |
4 continue |
| 3134 |
c |
| 3135 |
c copy lower part + diagonal |
| 3136 |
c |
| 3137 |
do 6 i=1, nrow |
| 3138 |
ka = ia(i) |
| 3139 |
do 5 k=ial(i), ial(i+1)-1 |
| 3140 |
a(ka) = al(k) |
| 3141 |
ja(ka) = jal(k) |
| 3142 |
ka = ka+1 |
| 3143 |
5 continue |
| 3144 |
a(ka) = diag(i) |
| 3145 |
ja(ka) = i |
| 3146 |
ia(i) = ka+1 |
| 3147 |
6 continue |
| 3148 |
c |
| 3149 |
c copy upper part |
| 3150 |
c |
| 3151 |
do 8 i=1, nrow |
| 3152 |
do 7 k=iau(i), iau(i+1)-1 |
| 3153 |
c |
| 3154 |
c row number |
| 3155 |
c |
| 3156 |
jak = jau(k) |
| 3157 |
c |
| 3158 |
c where element goes |
| 3159 |
c |
| 3160 |
ka = ia(jak) |
| 3161 |
a(ka) = au(k) |
| 3162 |
ja(ka) = i |
| 3163 |
ia(jak) = ka+1 |
| 3164 |
7 continue |
| 3165 |
8 continue |
| 3166 |
c |
| 3167 |
c readjust ia |
| 3168 |
c |
| 3169 |
do 9 i=nrow,1,-1 |
| 3170 |
ia(i+1) = ia(i) |
| 3171 |
9 continue |
| 3172 |
ia(1) = 1 |
| 3173 |
c----------end-of-usscsr------------------------------------------------ |
| 3174 |
end |
| 3175 |
c----------------------------------------------------------------------- |
| 3176 |
subroutine csrsss (nrow,a,ja,ia,sorted,diag,al,jal,ial,au) |
| 3177 |
real*8 a(*),al(*),diag(*),au(*) |
| 3178 |
integer ja(*),ia(nrow+1),jal(*),ial(nrow+1) |
| 3179 |
logical sorted |
| 3180 |
c----------------------------------------------------------------------- |
| 3181 |
c Compressed Sparse Row to Symmetric Sparse Skyline format |
| 3182 |
c----------------------------------------------------------------------- |
| 3183 |
c this subroutine converts a matrix stored in csr format into the |
| 3184 |
c Symmetric sparse skyline format. This latter format assumes that |
| 3185 |
c that the matrix has a symmetric pattern. It consists of the following |
| 3186 |
c * the diagonal of A stored separately in diag(*); |
| 3187 |
c * The strict lower part of A is stored in csr format in al,jal,ial |
| 3188 |
c * The values only of strict upper part as stored in csc format in au. |
| 3189 |
c----------------------------------------------------------------------- |
| 3190 |
c On entry |
| 3191 |
c----------- |
| 3192 |
c nrow = dimension of the matrix a. |
| 3193 |
c a = real array containing the nonzero values of the matrix |
| 3194 |
c stored rowwise. |
| 3195 |
c ja = column indices of the values in array a |
| 3196 |
c ia = integer array of length n+1 containing the pointers to |
| 3197 |
c beginning of each row in arrays a, ja. |
| 3198 |
c sorted= a logical indicating whether or not the elements in a,ja,ia |
| 3199 |
c are sorted. |
| 3200 |
c |
| 3201 |
c On return |
| 3202 |
c --------- |
| 3203 |
c diag = array containing the diagonal entries of A |
| 3204 |
c al,jal,ial = matrix in csr format storing the strict lower |
| 3205 |
c trangular part of A. |
| 3206 |
c au = values of the strict upper trangular part of A, column wise. |
| 3207 |
c----------------------------------------------------------------------- |
| 3208 |
c |
| 3209 |
c extract lower part and diagonal. |
| 3210 |
c |
| 3211 |
kl = 1 |
| 3212 |
ial(1) = kl |
| 3213 |
do 7 i=1, nrow |
| 3214 |
c |
| 3215 |
c scan all elements in a row |
| 3216 |
c |
| 3217 |
do 71 k = ia(i), ia(i+1)-1 |
| 3218 |
jak = ja(k) |
| 3219 |
if (jak .eq. i) then |
| 3220 |
diag(i) = a(k) |
| 3221 |
elseif (jak .lt. i) then |
| 3222 |
al(kl) = a(k) |
| 3223 |
jal(kl) = jak |
| 3224 |
kl = kl+1 |
| 3225 |
endif |
| 3226 |
71 continue |
| 3227 |
ial(i+1) = kl |
| 3228 |
7 continue |
| 3229 |
c |
| 3230 |
c sort if not sorted |
| 3231 |
c |
| 3232 |
if (.not. sorted) then |
| 3233 |
call csort (nrow, al, jal, ial, au, .true.) |
| 3234 |
endif |
| 3235 |
c |
| 3236 |
c copy u |
| 3237 |
c |
| 3238 |
do 8 i=1, nrow |
| 3239 |
c |
| 3240 |
c scan all elements in a row |
| 3241 |
c |
| 3242 |
do 81 k = ia(i), ia(i+1)-1 |
| 3243 |
jak = ja(k) |
| 3244 |
if (jak .gt. i) then |
| 3245 |
ku = ial(jak) |
| 3246 |
au(ku) = a(k) |
| 3247 |
ial(jak) = ku+1 |
| 3248 |
endif |
| 3249 |
81 continue |
| 3250 |
8 continue |
| 3251 |
c |
| 3252 |
c readjust ial |
| 3253 |
c |
| 3254 |
do 9 i=nrow,1,-1 |
| 3255 |
ial(i+1) = ial(i) |
| 3256 |
9 continue |
| 3257 |
ial(1) = 1 |
| 3258 |
c--------------- end-of-csrsss ----------------------------------------- |
| 3259 |
c----------------------------------------------------------------------- |
| 3260 |
end |
| 3261 |
c |
| 3262 |
subroutine ssscsr (nrow,a,ja,ia,diag,al,jal,ial,au) |
| 3263 |
real*8 a(*),al(*),diag(*),au(*) |
| 3264 |
integer ja(*),ia(nrow+1),jal(*),ial(nrow+1) |
| 3265 |
c----------------------------------------------------------------------- |
| 3266 |
c Unsymmetric Sparse Skyline format to Compressed Sparse Row |
| 3267 |
c----------------------------------------------------------------------- |
| 3268 |
c this subroutine converts a matrix stored in nonsymmetric sparse |
| 3269 |
c skyline format into csr format. The sparse skyline format is |
| 3270 |
c described in routine csruss. |
| 3271 |
c----------------------------------------------------------------------- |
| 3272 |
c On entry |
| 3273 |
c--------- |
| 3274 |
c diag = array containing the diagonal entries of A |
| 3275 |
c al,jal,ial = matrix in csr format storing the strict lower |
| 3276 |
c trangular part of A. |
| 3277 |
c au = values of strict upper part. |
| 3278 |
c |
| 3279 |
c On return |
| 3280 |
c --------- |
| 3281 |
c nrow = dimension of the matrix a. |
| 3282 |
c a = real array containing the nonzero values of the matrix |
| 3283 |
c stored rowwise. |
| 3284 |
c ja = column indices of the values in array a |
| 3285 |
c ia = integer array of length n+1 containing the pointers to |
| 3286 |
c beginning of each row in arrays a, ja. |
| 3287 |
c |
| 3288 |
c----------------------------------------------------------------------- |
| 3289 |
c |
| 3290 |
c count elements in lower part + diagonal |
| 3291 |
c |
| 3292 |
do 1 i=1, nrow |
| 3293 |
ia(i+1) = ial(i+1)-ial(i)+1 |
| 3294 |
1 continue |
| 3295 |
c |
| 3296 |
c count elements in upper part |
| 3297 |
c |
| 3298 |
do 3 i=1, nrow |
| 3299 |
do 2 k=ial(i), ial(i+1)-1 |
| 3300 |
j = jal(k) |
| 3301 |
ia(j+1) = ia(j+1)+1 |
| 3302 |
2 continue |
| 3303 |
3 continue |
| 3304 |
c---------- compute pointers from lengths ------------------------------ |
| 3305 |
ia(1) = 1 |
| 3306 |
do 4 i=1,nrow |
| 3307 |
ia(i+1) = ia(i)+ia(i+1) |
| 3308 |
4 continue |
| 3309 |
c |
| 3310 |
c copy lower part + diagonal |
| 3311 |
c |
| 3312 |
do 6 i=1, nrow |
| 3313 |
ka = ia(i) |
| 3314 |
do 5 k=ial(i), ial(i+1)-1 |
| 3315 |
a(ka) = al(k) |
| 3316 |
ja(ka) = jal(k) |
| 3317 |
ka = ka+1 |
| 3318 |
5 continue |
| 3319 |
a(ka) = diag(i) |
| 3320 |
ia(i) = ka+1 |
| 3321 |
6 continue |
| 3322 |
c |
| 3323 |
c copy upper part |
| 3324 |
c |
| 3325 |
do 8 i=1, nrow |
| 3326 |
do 7 k=ial(i), ial(i+1)-1 |
| 3327 |
c |
| 3328 |
c row number |
| 3329 |
c |
| 3330 |
jak = jal(k) |
| 3331 |
c |
| 3332 |
c where element goes |
| 3333 |
c |
| 3334 |
ka = ia(jak) |
| 3335 |
a(ka) = au(k) |
| 3336 |
ja(ka) = i |
| 3337 |
ia(jak) = ka+1 |
| 3338 |
7 continue |
| 3339 |
8 continue |
| 3340 |
c |
| 3341 |
c readjust ia |
| 3342 |
c |
| 3343 |
do 9 i=nrow,1,-1 |
| 3344 |
ia(i+1) = ia(i) |
| 3345 |
9 continue |
| 3346 |
ia(1) = 1 |
| 3347 |
c----------end-of-ssscsr------------------------------------------------ |
| 3348 |
end |
| 3349 |
c----------------------------------------------------------------------- |
| 3350 |
subroutine csrvbr(n,ia,ja,a,nr,nc,kvstr,kvstc,ib,jb,kb, |
| 3351 |
& b, job, iwk, nkmax, nzmax, ierr ) |
| 3352 |
c----------------------------------------------------------------------- |
| 3353 |
integer n, ia(n+1), ja(*), nr, nc, ib(*), jb(nkmax-1), kb(nkmax) |
| 3354 |
integer kvstr(*), kvstc(*), job, iwk(*), nkmax, nzmax, ierr |
| 3355 |
real*8 a(*), b(nzmax) |
| 3356 |
c----------------------------------------------------------------------- |
| 3357 |
c Converts compressed sparse row to variable block row format. |
| 3358 |
c----------------------------------------------------------------------- |
| 3359 |
c On entry: |
| 3360 |
c-------------- |
| 3361 |
c n = number of matrix rows |
| 3362 |
c ia,ja,a = input matrix in CSR format |
| 3363 |
c |
| 3364 |
c job = job indicator. |
| 3365 |
c If job=0, kvstr and kvstc are used as supplied. |
| 3366 |
c If job=1, kvstr and kvstc are determined by the code. |
| 3367 |
c If job=2, a conformal row/col partitioning is found and |
| 3368 |
c returned in both kvstr and kvstc. In the latter two cases, |
| 3369 |
c an optimized algorithm can be used to perform the |
| 3370 |
c conversion because all blocks are full. |
| 3371 |
c |
| 3372 |
c nkmax = size of supplied jb and kb arrays |
| 3373 |
c nzmax = size of supplied b array |
| 3374 |
c |
| 3375 |
c If job=0 then the following are input: |
| 3376 |
c nr,nc = matrix block row and block column dimension |
| 3377 |
c kvstr = first row number for each block row |
| 3378 |
c kvstc = first column number for each block column. |
| 3379 |
c (kvstr and kvstc may be the same array) |
| 3380 |
c |
| 3381 |
c On return: |
| 3382 |
c--------------- |
| 3383 |
c |
| 3384 |
c ib,jb,kb,b = output matrix in VBR format |
| 3385 |
c |
| 3386 |
c ierr = error message |
| 3387 |
c ierr = 0 means normal return |
| 3388 |
c ierr = 1 out of space in jb and/or kb arrays |
| 3389 |
c ierr = 2 out of space in b array |
| 3390 |
c ierr = 3 nonsquare matrix used with job=2 |
| 3391 |
c |
| 3392 |
c If job=1,2 then the following are output: |
| 3393 |
c nr,nc = matrix block row and block column dimension |
| 3394 |
c kvstr = first row number for each block row |
| 3395 |
c kvstc = first column number for each block column |
| 3396 |
c If job=2, then kvstr and kvstc contain the same info. |
| 3397 |
c |
| 3398 |
c Work space: |
| 3399 |
c---------------- |
| 3400 |
c iwk(1:ncol) = inverse kvstc array. If job=1,2 then we also need: |
| 3401 |
c iwk(ncol+1:ncol+nr) = used to help determine sparsity of each block row. |
| 3402 |
c The workspace is not assumed to be initialized to zero, nor is it |
| 3403 |
c left that way. |
| 3404 |
c |
| 3405 |
c Algorithms: |
| 3406 |
c---------------- |
| 3407 |
c There are two conversion codes in this routine. The first assumes |
| 3408 |
c that all blocks are full (there is a nonzero in the CSR data |
| 3409 |
c structure for each entry in the block), and is used if the routine |
| 3410 |
c determines the block partitioning itself. The second code makes |
| 3411 |
c no assumptions about the block partitioning, and is used if the |
| 3412 |
c caller provides the partitioning. The second code is much less |
| 3413 |
c efficient than the first code. |
| 3414 |
c |
| 3415 |
c In the first code, the CSR data structure is traversed sequentially |
| 3416 |
c and entries are placed into the VBR data structure with stride |
| 3417 |
c equal to the row dimension of the block row. The columns of the |
| 3418 |
c CSR data structure are sorted first if necessary. |
| 3419 |
c |
| 3420 |
c In the second code, the block sparsity pattern is first determined. |
| 3421 |
c This is done by traversing the CSR data structure and using an |
| 3422 |
c implied linked list to determine which blocks are nonzero. Then |
| 3423 |
c the VBR data structure is filled by mapping each individual entry |
| 3424 |
c in the CSR data structure into the VBR data structure. The columns |
| 3425 |
c of the CSR data structure are sorted first if necessary. |
| 3426 |
c |
| 3427 |
c----------------------------------------------------------------------- |
| 3428 |
c Local variables: |
| 3429 |
c--------------------- |
| 3430 |
integer ncol, nb, neqr, numc, a0, b0, b1, k0, i, ii, j, jj, jnew |
| 3431 |
logical sorted |
| 3432 |
c |
| 3433 |
c ncol = number of scalar columns in matrix |
| 3434 |
c nb = number of blocks in conformal row/col partitioning |
| 3435 |
c neqr = number of rows in block row |
| 3436 |
c numc = number of nonzero columns in row |
| 3437 |
c a0 = index for entries in CSR a array |
| 3438 |
c b0 = index for entries in VBR b array |
| 3439 |
c b1 = temp |
| 3440 |
c k0 = index for entries in VBR kb array |
| 3441 |
c i = loop index for block rows |
| 3442 |
c ii = loop index for scalar rows in block row |
| 3443 |
c j = loop index for block columns |
| 3444 |
c jj = loop index for scalar columns in block column |
| 3445 |
c jnew = block column number |
| 3446 |
c sorted = used to indicate if matrix already sorted by columns |
| 3447 |
c |
| 3448 |
c----------------------------------------------------------------------- |
| 3449 |
ierr = 0 |
| 3450 |
c-----sort matrix by column indices |
| 3451 |
call csorted(n, ia, ja, sorted) |
| 3452 |
if (.not. sorted) then |
| 3453 |
call csort (n, a, ja, ia, b, .true.) |
| 3454 |
endif |
| 3455 |
if (job .eq. 1 .or. job .eq. 2) then |
| 3456 |
c--------need to zero workspace; first find ncol |
| 3457 |
ncol = 0 |
| 3458 |
do i = 2, n |
| 3459 |
ncol = max0(ncol, ja(ia(i)-1)) |
| 3460 |
enddo |
| 3461 |
do i = 1, ncol |
| 3462 |
iwk(i) = 0 |
| 3463 |
enddo |
| 3464 |
call csrkvstr(n, ia, ja, nr, kvstr) |
| 3465 |
call csrkvstc(n, ia, ja, nc, kvstc, iwk) |
| 3466 |
endif |
| 3467 |
c-----check if want conformal partitioning |
| 3468 |
if (job .eq. 2) then |
| 3469 |
if (kvstr(nr+1) .ne. kvstc(nc+1)) then |
| 3470 |
ierr = 3 |
| 3471 |
return |
| 3472 |
endif |
| 3473 |
c use iwk temporarily |
| 3474 |
call kvstmerge(nr, kvstr, nc, kvstc, nb, iwk) |
| 3475 |
nr = nb |
| 3476 |
nc = nb |
| 3477 |
do i = 1, nb+1 |
| 3478 |
kvstr(i) = iwk(i) |
| 3479 |
kvstc(i) = iwk(i) |
| 3480 |
enddo |
| 3481 |
endif |
| 3482 |
c----------------------------------------------------------------------- |
| 3483 |
c inverse kvst (scalar col number) = block col number |
| 3484 |
c stored in iwk(1:n) |
| 3485 |
c----------------------------------------------------------------------- |
| 3486 |
do i = 1, nc |
| 3487 |
do j = kvstc(i), kvstc(i+1)-1 |
| 3488 |
iwk(j) = i |
| 3489 |
enddo |
| 3490 |
enddo |
| 3491 |
ncol = kvstc(nc+1)-1 |
| 3492 |
c-----jump to conversion routine |
| 3493 |
if (job .eq. 0) goto 400 |
| 3494 |
c----------------------------------------------------------------------- |
| 3495 |
c Fast conversion for computed block partitioning |
| 3496 |
c----------------------------------------------------------------------- |
| 3497 |
a0 = 1 |
| 3498 |
b0 = 1 |
| 3499 |
k0 = 1 |
| 3500 |
kb(1) = 1 |
| 3501 |
c-----loop on block rows |
| 3502 |
do i = 1, nr |
| 3503 |
neqr = kvstr(i+1) - kvstr(i) |
| 3504 |
numc = ia(kvstr(i)+1) - ia(kvstr(i)) |
| 3505 |
ib(i) = k0 |
| 3506 |
c--------loop on first row in block row to determine block sparsity |
| 3507 |
j = 0 |
| 3508 |
do jj = ia(kvstr(i)), ia(kvstr(i)+1)-1 |
| 3509 |
jnew = iwk(ja(jj)) |
| 3510 |
if (jnew .ne. j) then |
| 3511 |
c--------------check there is enough space in kb and jb arrays |
| 3512 |
if (k0+1 .gt. nkmax) then |
| 3513 |
ierr = 1 |
| 3514 |
write (*,*) 'csrvbr: no space in kb for block row ', i |
| 3515 |
return |
| 3516 |
endif |
| 3517 |
c--------------set entries for this block |
| 3518 |
j = jnew |
| 3519 |
b0 = b0 + neqr * (kvstc(j+1) - kvstc(j)) |
| 3520 |
kb(k0+1) = b0 |
| 3521 |
jb(k0) = j |
| 3522 |
k0 = k0 + 1 |
| 3523 |
endif |
| 3524 |
enddo |
| 3525 |
c--------loop on scalar rows in block row |
| 3526 |
do ii = 0, neqr-1 |
| 3527 |
b1 = kb(ib(i))+ii |
| 3528 |
c-----------loop on elements in a scalar row |
| 3529 |
do jj = 1, numc |
| 3530 |
c--------------check there is enough space in b array |
| 3531 |
if (b1 .gt. nzmax) then |
| 3532 |
ierr = 2 |
| 3533 |
write (*,*) 'csrvbr: no space in b for block row ', i |
| 3534 |
return |
| 3535 |
endif |
| 3536 |
b(b1) = a(a0) |
| 3537 |
b1 = b1 + neqr |
| 3538 |
a0 = a0 + 1 |
| 3539 |
enddo |
| 3540 |
enddo |
| 3541 |
enddo |
| 3542 |
ib(nr+1) = k0 |
| 3543 |
return |
| 3544 |
c----------------------------------------------------------------------- |
| 3545 |
c Conversion for user supplied block partitioning |
| 3546 |
c----------------------------------------------------------------------- |
| 3547 |
400 continue |
| 3548 |
c-----initialize workspace for sparsity indicator |
| 3549 |
do i = ncol+1, ncol+nc |
| 3550 |
iwk(i) = 0 |
| 3551 |
enddo |
| 3552 |
k0 = 1 |
| 3553 |
kb(1) = 1 |
| 3554 |
c-----find sparsity of block rows |
| 3555 |
do i = 1, nr |
| 3556 |
neqr = kvstr(i+1) - kvstr(i) |
| 3557 |
numc = ia(kvstr(i)+1) - ia(kvstr(i)) |
| 3558 |
ib(i) = k0 |
| 3559 |
c--------loop on all the elements in the block row to determine block sparsity |
| 3560 |
do jj = ia(kvstr(i)), ia(kvstr(i+1))-1 |
| 3561 |
iwk(iwk(ja(jj))+ncol) = 1 |
| 3562 |
enddo |
| 3563 |
c--------use sparsity to set jb and kb arrays |
| 3564 |
do j = 1, nc |
| 3565 |
if (iwk(j+ncol) .ne. 0) then |
| 3566 |
c--------------check there is enough space in kb and jb arrays |
| 3567 |
if (k0+1 .gt. nkmax) then |
| 3568 |
ierr = 1 |
| 3569 |
write (*,*) 'csrvbr: no space in kb for block row ', i |
| 3570 |
return |
| 3571 |
endif |
| 3572 |
kb(k0+1) = kb(k0) + neqr * (kvstc(j+1) - kvstc(j)) |
| 3573 |
jb(k0) = j |
| 3574 |
k0 = k0 + 1 |
| 3575 |
iwk(j+ncol) = 0 |
| 3576 |
endif |
| 3577 |
enddo |
| 3578 |
enddo |
| 3579 |
ib(nr+1) = k0 |
| 3580 |
c-----Fill b with entries from a by traversing VBR data structure. |
| 3581 |
a0 = 1 |
| 3582 |
c-----loop on block rows |
| 3583 |
do i = 1, nr |
| 3584 |
neqr = kvstr(i+1) - kvstr(i) |
| 3585 |
c--------loop on scalar rows in block row |
| 3586 |
do ii = 0, neqr-1 |
| 3587 |
b0 = kb(ib(i)) + ii |
| 3588 |
c-----------loop on block columns |
| 3589 |
do j = ib(i), ib(i+1)-1 |
| 3590 |
c--------------loop on scalar columns within block column |
| 3591 |
do jj = kvstc(jb(j)), kvstc(jb(j)+1)-1 |
| 3592 |
c-----------------check there is enough space in b array |
| 3593 |
if (b0 .gt. nzmax) then |
| 3594 |
ierr = 2 |
| 3595 |
write (*,*)'csrvbr: no space in b for blk row',i |
| 3596 |
return |
| 3597 |
endif |
| 3598 |
if (a0 .ge. ia(kvstr(i)+ii+1)) then |
| 3599 |
b(b0) = 0.d0 |
| 3600 |
else |
| 3601 |
if (jj .eq. ja(a0)) then |
| 3602 |
b(b0) = a(a0) |
| 3603 |
a0 = a0 + 1 |
| 3604 |
else |
| 3605 |
b(b0) = 0.d0 |
| 3606 |
endif |
| 3607 |
endif |
| 3608 |
b0 = b0 + neqr |
| 3609 |
c--------------endloop on scalar columns |
| 3610 |
enddo |
| 3611 |
c-----------endloop on block columns |
| 3612 |
enddo |
| 3613 |
2020 continue |
| 3614 |
enddo |
| 3615 |
enddo |
| 3616 |
return |
| 3617 |
end |
| 3618 |
c----------------------------------------------------------------------- |
| 3619 |
c----------------------------end-of-csrvbr------------------------------ |
| 3620 |
c----------------------------------------------------------------------c |
| 3621 |
subroutine vbrcsr(ia, ja, a, nr, kvstr, kvstc, ib, jb, kb, |
| 3622 |
& b, nzmax, ierr) |
| 3623 |
c----------------------------------------------------------------------- |
| 3624 |
integer ia(*), ja(*), nr, ib(nr+1), jb(*), kb(*) |
| 3625 |
integer kvstr(nr+1), kvstc(*), nzmax, ierr |
| 3626 |
real*8 a(*), b(nzmax) |
| 3627 |
c----------------------------------------------------------------------- |
| 3628 |
c Converts variable block row to compressed sparse row format. |
| 3629 |
c----------------------------------------------------------------------- |
| 3630 |
c On entry: |
| 3631 |
c-------------- |
| 3632 |
c nr = number of block rows |
| 3633 |
c kvstr = first row number for each block row |
| 3634 |
c kvstc = first column number for each block column |
| 3635 |
c ib,jb,kb,b = input matrix in VBR format |
| 3636 |
c nzmax = size of supplied ja and a arrays |
| 3637 |
c |
| 3638 |
c On return: |
| 3639 |
c--------------- |
| 3640 |
c ia,ja,a = output matrix in CSR format |
| 3641 |
c |
| 3642 |
c ierr = error message |
| 3643 |
c ierr = 0 means normal return |
| 3644 |
c ierr = negative row number when out of space in |
| 3645 |
c ja and a arrays |
| 3646 |
c |
| 3647 |
c Work space: |
| 3648 |
c---------------- |
| 3649 |
c None |
| 3650 |
c |
| 3651 |
c Algorithm: |
| 3652 |
c--------------- |
| 3653 |
c The VBR data structure is traversed in the order that is required |
| 3654 |
c to fill the CSR data structure. In a given block row, consecutive |
| 3655 |
c entries in the CSR data structure are entries in the VBR data |
| 3656 |
c structure with stride equal to the row dimension of the block. |
| 3657 |
c The VBR data structure is assumed to be sorted by block columns. |
| 3658 |
c |
| 3659 |
c----------------------------------------------------------------------- |
| 3660 |
c Local variables: |
| 3661 |
c--------------------- |
| 3662 |
integer neqr, numc, a0, b0, i, ii, j, jj |
| 3663 |
c |
| 3664 |
c neqr = number of rows in block row |
| 3665 |
c numc = number of nonzero columns in row |
| 3666 |
c a0 = index for entries in CSR a array |
| 3667 |
c b0 = index for entries in VBR b array |
| 3668 |
c i = loop index for block rows |
| 3669 |
c ii = loop index for scalar rows in block row |
| 3670 |
c j = loop index for block columns |
| 3671 |
c jj = loop index for scalar columns in block column |
| 3672 |
c |
| 3673 |
c----------------------------------------------------------------------- |
| 3674 |
ierr = 0 |
| 3675 |
a0 = 1 |
| 3676 |
b0 = 1 |
| 3677 |
c-----loop on block rows |
| 3678 |
do i = 1, nr |
| 3679 |
c--------set num of rows in block row, and num of nonzero cols in row |
| 3680 |
neqr = kvstr(i+1) - kvstr(i) |
| 3681 |
numc = ( kb(ib(i+1)) - kb(ib(i)) ) / neqr |
| 3682 |
c--------construct ja for a scalar row |
| 3683 |
do j = ib(i), ib(i+1)-1 |
| 3684 |
do jj = kvstc(jb(j)), kvstc(jb(j)+1)-1 |
| 3685 |
ja(a0) = jj |
| 3686 |
a0 = a0 + 1 |
| 3687 |
enddo |
| 3688 |
enddo |
| 3689 |
c--------construct neqr-1 additional copies of ja for the block row |
| 3690 |
do ii = 1, neqr-1 |
| 3691 |
do j = 1, numc |
| 3692 |
ja(a0) = ja(a0-numc) |
| 3693 |
a0 = a0 + 1 |
| 3694 |
enddo |
| 3695 |
enddo |
| 3696 |
c--------reset a0 back to beginning of block row |
| 3697 |
a0 = kb(ib(i)) |
| 3698 |
c--------loop on scalar rows in block row |
| 3699 |
do ii = 0, neqr-1 |
| 3700 |
ia(kvstr(i)+ii) = a0 |
| 3701 |
b0 = kb(ib(i)) + ii |
| 3702 |
c-----------loop on elements in a scalar row |
| 3703 |
do jj = 1, numc |
| 3704 |
c--------------check there is enough space in a array |
| 3705 |
if (a0 .gt. nzmax) then |
| 3706 |
ierr = -(kvstr(i)+ii) |
| 3707 |
write (*,*) 'vbrcsr: no space for row ', -ierr |
| 3708 |
return |
| 3709 |
endif |
| 3710 |
a(a0) = b(b0) |
| 3711 |
a0 = a0 + 1 |
| 3712 |
b0 = b0 + neqr |
| 3713 |
enddo |
| 3714 |
enddo |
| 3715 |
c-----endloop on block rows |
| 3716 |
enddo |
| 3717 |
ia(kvstr(nr+1)) = a0 |
| 3718 |
return |
| 3719 |
end |
| 3720 |
c----------------------------------------------------------------------- |
| 3721 |
c---------------------------end-of-vbrcsr------------------------------- |
| 3722 |
c----------------------------------------------------------------------- |
| 3723 |
c----------------------------------------------------------------------- |
| 3724 |
subroutine csorted(n, ia, ja, sorted) |
| 3725 |
c----------------------------------------------------------------------- |
| 3726 |
integer n, ia(n+1), ja(*) |
| 3727 |
logical sorted |
| 3728 |
c----------------------------------------------------------------------- |
| 3729 |
c Checks if matrix in CSR format is sorted by columns. |
| 3730 |
c----------------------------------------------------------------------- |
| 3731 |
c On entry: |
| 3732 |
c-------------- |
| 3733 |
c n = number of rows in matrix |
| 3734 |
c ia, ja = sparsity structure of matrix in CSR format |
| 3735 |
c |
| 3736 |
c On return: |
| 3737 |
c--------------- |
| 3738 |
c sorted = indicates if matrix is sorted by columns |
| 3739 |
c |
| 3740 |
c----------------------------------------------------------------------- |
| 3741 |
c-----local variables |
| 3742 |
integer i,j |
| 3743 |
c--------------------------------- |
| 3744 |
do i = 1, n |
| 3745 |
do j = ia(i)+1, ia(i+1)-1 |
| 3746 |
if (ja(j-1) .ge. ja(j)) then |
| 3747 |
sorted = .false. |
| 3748 |
return |
| 3749 |
endif |
| 3750 |
enddo |
| 3751 |
enddo |
| 3752 |
sorted = .true. |
| 3753 |
return |
| 3754 |
end |
| 3755 |
c----------------------------------------------------------------------- |
| 3756 |
c------------------------end-of-csorted--------------------------------- |