-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsparsekit2.f
27615 lines (27521 loc) · 906 KB
/
sparsekit2.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
c-----------------------------------------------------------------------
subroutine addblk(nrowa, ncola, a, ja, ia, ipos, jpos, job,
& nrowb, ncolb, b, jb, ib, nrowc, ncolc, c, jc, ic, nzmx, ierr)
c implicit none
integer nrowa, nrowb, nrowc, ncola, ncolb, ncolc, ipos, jpos
integer nzmx, ierr, job
integer ja(1:*), ia(1:*), jb(1:*), ib(1:*), jc(1:*), ic(1:*)
real*8 a(1:*), b(1:*), c(1:*)
c-----------------------------------------------------------------------
c This subroutine adds a matrix B into a submatrix of A whose
c (1,1) element is located in the starting position (ipos, jpos).
c The resulting matrix is allowed to be larger than A (and B),
c and the resulting dimensions nrowc, ncolc will be redefined
c accordingly upon return.
c The input matrices are assumed to be sorted, i.e. in each row
c the column indices appear in ascending order in the CSR format.
c-----------------------------------------------------------------------
c on entry:
c ---------
c nrowa = number of rows in A.
c bcola = number of columns in A.
c a,ja,ia = Matrix A in compressed sparse row format with entries sorted
c nrowb = number of rows in B.
c ncolb = number of columns in B.
c b,jb,ib = Matrix B in compressed sparse row format with entries sorted
c
c nzmax = integer. The length of the arrays c and jc. addblk will
c stop if the number of nonzero elements in the matrix C
c exceeds nzmax. See ierr.
c
c on return:
c----------
c nrowc = number of rows in C.
c ncolc = number of columns in C.
c c,jc,ic = resulting matrix C in compressed sparse row sparse format
c with entries sorted ascendly in each row.
c
c ierr = integer. serving as error message.
c ierr = 0 means normal return,
c ierr .gt. 0 means that addblk stopped while computing the
c i-th row of C with i=ierr, because the number
c of elements in C exceeds nzmax.
c
c Notes:
c-------
c this will not work if any of the two input matrices is not sorted
c-----------------------------------------------------------------------
logical values
integer i,j1,j2,ka,kb,kc,kamax,kbmax
values = (job .ne. 0)
ierr = 0
nrowc = max(nrowa, nrowb+ipos-1)
ncolc = max(ncola, ncolb+jpos-1)
kc = 1
kbmax = 0
ic(1) = kc
c
do 10 i=1, nrowc
if (i.le.nrowa) then
ka = ia(i)
kamax = ia(i+1)-1
else
ka = ia(nrowa+1)
end if
if ((i.ge.ipos).and.((i-ipos).le.nrowb)) then
kb = ib(i-ipos+1)
kbmax = ib(i-ipos+2)-1
else
kb = ib(nrowb+1)
end if
c
c a do-while type loop -- goes through all the elements in a row.
c
20 continue
if (ka .le. kamax) then
j1 = ja(ka)
else
j1 = ncolc+1
endif
if (kb .le. kbmax) then
j2 = jb(kb) + jpos - 1
else
j2 = ncolc+1
endif
c
c if there are more elements to be added.
c
if ((ka .le. kamax .or. kb .le. kbmax) .and.
& (j1 .le. ncolc .or. j2 .le. ncolc)) then
c
c three cases
c
if (j1 .eq. j2) then
if (values) c(kc) = a(ka)+b(kb)
jc(kc) = j1
ka = ka+1
kb = kb+1
kc = kc+1
else if (j1 .lt. j2) then
jc(kc) = j1
if (values) c(kc) = a(ka)
ka = ka+1
kc = kc+1
else if (j1 .gt. j2) then
jc(kc) = j2
if (values) c(kc) = b(kb)
kb = kb+1
kc = kc+1
endif
if (kc .gt. nzmx) goto 999
goto 20
end if
ic(i+1) = kc
10 continue
return
999 ierr = i
return
c---------end-of-addblk-------------------------------------------------
end
c-----------------------------------------------------------------------
subroutine add_lk(new,nod,idom,ndom,lkend,levst,link,nodes,marker)
implicit none
integer new,nod,idom,ndom,lkend,levst(*),link(*),nodes(*),
* marker(*)
c-----------------------------------------------------------------------
c inserts new element to linked list from the tail.
c-----------------------------------------------------------------------
c adds one entry (new) to linked list and ipdates everything.
c new = node to be added
c nod = current number of marked nodes
c idom = domain to which new is to be added
c ndom = total number of domains
c lkend= location of end of structure (link and nodes)
c levst= pointer array for link, nodes
c link = link array
c nodes= nodes array --
c marker = marker array == if marker(k) =0 then node k is not
c assigned yet.
c-----------------------------------------------------------------------
c locals
c
integer ktop
lkend = lkend + 1
nodes(lkend) = new
nod = nod+1
marker(new) = idom
ktop = levst(idom)
link(lkend) = ktop
link(idom) = link(idom)-1
levst(idom) = lkend
return
c-----------------------------------------------------------------------
c-------end-of-add_lk---------------------------------------------------
end
c-----------------------------------------------------------------------
subroutine add_lvst(istart,iend,nlev,riord,ja,ia,mask,maskval)
integer nlev, nod, riord(*), ja(*), ia(*), mask(*)
c-------------------------------------------------------------
c adds one level set to the previous sets..
c span all nodes of previous mask
c-------------------------------------------------------------
nod = iend
do 25 ir = istart+1,iend
i = riord(ir)
do 24 k=ia(i),ia(i+1)-1
j = ja(k)
if (mask(j) .eq. maskval) then
nod = nod+1
mask(j) = 0
riord(nod) = j
endif
24 continue
25 continue
istart = iend
iend = nod
return
end
c-----------------------------------------------------------------------
subroutine amask (nrow,ncol,a,ja,ia,jmask,imask,
* c,jc,ic,iw,nzmax,ierr)
c---------------------------------------------------------------------
real*8 a(*),c(*)
integer ia(nrow+1),ja(*),jc(*),ic(nrow+1),jmask(*),imask(nrow+1)
logical iw(ncol)
c-----------------------------------------------------------------------
c This subroutine builds a sparse matrix from an input matrix by
c extracting only elements in positions defined by the mask jmask, imask
c-----------------------------------------------------------------------
c On entry:
c---------
c nrow = integer. row dimension of input matrix
c ncol = integer. Column dimension of input matrix.
c
c a,
c ja,
c ia = matrix in Compressed Sparse Row format
c
c jmask,
c imask = matrix defining mask (pattern only) stored in compressed
c sparse row format.
c
c nzmax = length of arrays c and jc. see ierr.
c
c On return:
c-----------
c
c a, ja, ia and jmask, imask are unchanged.
c
c c
c jc,
c ic = the output matrix in Compressed Sparse Row format.
c
c ierr = integer. serving as error message.c
c ierr = 1 means normal return
c ierr .gt. 1 means that amask stopped when processing
c row number ierr, because there was not enough space in
c c, jc according to the value of nzmax.
c
c work arrays:
c-------------
c iw = logical work array of length ncol.
c
c note:
c------ the algorithm is in place: c, jc, ic can be the same as
c a, ja, ia in which cas the code will overwrite the matrix c
c on a, ja, ia
c
c-----------------------------------------------------------------------
ierr = 0
len = 0
do 1 j=1, ncol
iw(j) = .false.
1 continue
c unpack the mask for row ii in iw
do 100 ii=1, nrow
c save pointer in order to be able to do things in place
do 2 k=imask(ii), imask(ii+1)-1
iw(jmask(k)) = .true.
2 continue
c add umasked elemnts of row ii
k1 = ia(ii)
k2 = ia(ii+1)-1
ic(ii) = len+1
do 200 k=k1,k2
j = ja(k)
if (iw(j)) then
len = len+1
if (len .gt. nzmax) then
ierr = ii
return
endif
jc(len) = j
c(len) = a(k)
endif
200 continue
c
do 3 k=imask(ii), imask(ii+1)-1
iw(jmask(k)) = .false.
3 continue
100 continue
ic(nrow+1)=len+1
c
return
c-----end-of-amask -----------------------------------------------------
c-----------------------------------------------------------------------
end
c-----------------------------------------------------------------------
subroutine amubdg (nrow,ncol,ncolb,ja,ia,jb,ib,ndegr,nnz,iw)
integer ja(*),jb(*),ia(nrow+1),ib(ncol+1),ndegr(nrow),iw(ncolb)
c-----------------------------------------------------------------------
c gets the number of nonzero elements in each row of A*B and the total
c number of nonzero elements in A*B.
c-----------------------------------------------------------------------
c on entry:
c --------
c
c nrow = integer. row dimension of matrix A
c ncol = integer. column dimension of matrix A = row dimension of
c matrix B.
c ncolb = integer. the colum dimension of the matrix B.
c
c ja, ia= row structure of input matrix A: ja = column indices of
c the nonzero elements of A stored by rows.
c ia = pointer to beginning of each row in ja.
c
c jb, ib= row structure of input matrix B: jb = column indices of
c the nonzero elements of A stored by rows.
c ib = pointer to beginning of each row in jb.
c
c on return:
c ---------
c ndegr = integer array of length nrow containing the degrees (i.e.,
c the number of nonzeros in each row of the matrix A * B
c
c nnz = total number of nonzero elements found in A * B
c
c work arrays:
c-------------
c iw = integer work array of length ncolb.
c-----------------------------------------------------------------------
do 1 k=1, ncolb
iw(k) = 0
1 continue
do 2 k=1, nrow
ndegr(k) = 0
2 continue
c
c method used: Transp(A) * A = sum [over i=1, nrow] a(i)^T a(i)
c where a(i) = i-th row of A. We must be careful not to add the
c elements already accounted for.
c
c
do 7 ii=1,nrow
c
c for each row of A
c
ldg = 0
c
c end-of-linked list
c
last = -1
do 6 j = ia(ii),ia(ii+1)-1
c
c row number to be added:
c
jr = ja(j)
do 5 k=ib(jr),ib(jr+1)-1
jc = jb(k)
if (iw(jc) .eq. 0) then
c
c add one element to the linked list
c
ldg = ldg + 1
iw(jc) = last
last = jc
endif
5 continue
6 continue
ndegr(ii) = ldg
c
c reset iw to zero
c
do 61 k=1,ldg
j = iw(last)
iw(last) = 0
last = j
61 continue
c-----------------------------------------------------------------------
7 continue
c
nnz = 0
do 8 ii=1, nrow
nnz = nnz+ndegr(ii)
8 continue
c
return
c---------------end-of-amubdg ------------------------------------------
c-----------------------------------------------------------------------
end
subroutine amub (nrow,ncol,job,a,ja,ia,b,jb,ib,
* c,jc,ic,nzmax,iw,ierr)
real*8 a(*), b(*), c(*)
integer ja(*),jb(*),jc(*),ia(nrow+1),ib(*),ic(*),iw(ncol)
c-----------------------------------------------------------------------
c performs the matrix by matrix product C = A B
c-----------------------------------------------------------------------
c on entry:
c ---------
c nrow = integer. The row dimension of A = row dimension of C
c ncol = integer. The column dimension of B = column dimension of C
c job = integer. Job indicator. When job = 0, only the structure
c (i.e. the arrays jc, ic) is computed and the
c real values are ignored.
c
c a,
c ja,
c ia = Matrix A in compressed sparse row format.
c
c b,
c jb,
c ib = Matrix B in compressed sparse row format.
c
c nzmax = integer. The length of the arrays c and jc.
c amub will stop if the result matrix C has a number
c of elements that exceeds exceeds nzmax. See ierr.
c
c on return:
c----------
c c,
c jc,
c ic = resulting matrix C in compressed sparse row sparse format.
c
c ierr = integer. serving as error message.
c ierr = 0 means normal return,
c ierr .gt. 0 means that amub stopped while computing the
c i-th row of C with i=ierr, because the number
c of elements in C exceeds nzmax.
c
c work arrays:
c------------
c iw = integer work array of length equal to the number of
c columns in A.
c Note:
c-------
c The row dimension of B is not needed. However there is no checking
c on the condition that ncol(A) = nrow(B).
c
c-----------------------------------------------------------------------
real*8 scal
logical values
values = (job .ne. 0)
len = 0
ic(1) = 1
ierr = 0
c initialize array iw.
do 1 j=1, ncol
iw(j) = 0
1 continue
c
do 500 ii=1, nrow
c row i
do 200 ka=ia(ii), ia(ii+1)-1
if (values) scal = a(ka)
jj = ja(ka)
do 100 kb=ib(jj),ib(jj+1)-1
jcol = jb(kb)
jpos = iw(jcol)
if (jpos .eq. 0) then
len = len+1
if (len .gt. nzmax) then
ierr = ii
return
endif
jc(len) = jcol
iw(jcol)= len
if (values) c(len) = scal*b(kb)
else
if (values) c(jpos) = c(jpos) + scal*b(kb)
endif
100 continue
200 continue
do 201 k=ic(ii), len
iw(jc(k)) = 0
201 continue
ic(ii+1) = len+1
500 continue
return
c-------------end-of-amub-----------------------------------------------
c-----------------------------------------------------------------------
end
c-----------------------------------------------------------------------
subroutine amudia (nrow,job, a, ja, ia, diag, b, jb, ib)
real*8 a(*), b(*), diag(nrow)
integer ja(*),jb(*), ia(nrow+1),ib(nrow+1)
c-----------------------------------------------------------------------
c performs the matrix by matrix product B = A * Diag (in place)
c-----------------------------------------------------------------------
c on entry:
c ---------
c nrow = integer. The row dimension of A
c
c job = integer. job indicator. Job=0 means get array b only
c job = 1 means get b, and the integer arrays ib, jb.
c
c a,
c ja,
c ia = Matrix A in compressed sparse row format.
c
c diag = diagonal matrix stored as a vector dig(1:n)
c
c on return:
c----------
c
c b,
c jb,
c ib = resulting matrix B in compressed sparse row sparse format.
c
c Notes:
c-------
c 1) The column dimension of A is not needed.
c 2) algorithm in place (B can take the place of A).
c-----------------------------------------------------------------
do 1 ii=1,nrow
c
c scale each element
c
k1 = ia(ii)
k2 = ia(ii+1)-1
do 2 k=k1, k2
b(k) = a(k)*diag(ja(k))
2 continue
1 continue
c
if (job .eq. 0) return
c
do 3 ii=1, nrow+1
ib(ii) = ia(ii)
3 continue
do 31 k=ia(1), ia(nrow+1) -1
jb(k) = ja(k)
31 continue
return
c-----------------------------------------------------------------------
c-----------end-of-amudiag----------------------------------------------
end
c-----------------------------------------------------------------------
subroutine amuxd (n,x,y,diag,ndiag,idiag,ioff)
integer n, ndiag, idiag, ioff(idiag)
real*8 x(n), y(n), diag(ndiag,idiag)
c-----------------------------------------------------------------------
c A times a vector in Diagonal storage format (DIA)
c-----------------------------------------------------------------------
c multiplies a matrix by a vector when the original matrix is stored
c in the diagonal storage format.
c-----------------------------------------------------------------------
c
c on entry:
c----------
c n = row dimension of A
c x = real array of length equal to the column dimension of
c the A matrix.
c ndiag = integer. The first dimension of array adiag as declared in
c the calling program.
c idiag = integer. The number of diagonals in the matrix.
c diag = real array containing the diagonals stored of A.
c idiag = number of diagonals in matrix.
c diag = real array of size (ndiag x idiag) containing the diagonals
c
c ioff = integer array of length idiag, containing the offsets of the
c diagonals of the matrix:
c diag(i,k) contains the element a(i,i+ioff(k)) of the matrix.
c
c on return:
c-----------
c y = real array of length n, containing the product y=A*x
c
c-----------------------------------------------------------------------
c local variables
c
integer j, k, io, i1, i2
c-----------------------------------------------------------------------
do 1 j=1, n
y(j) = 0.0d0
1 continue
do 10 j=1, idiag
io = ioff(j)
i1 = max0(1,1-io)
i2 = min0(n,n-io)
do 9 k=i1, i2
y(k) = y(k)+diag(k,j)*x(k+io)
9 continue
10 continue
c
return
c----------end-of-amuxd-------------------------------------------------
c-----------------------------------------------------------------------
end
c-----------------------------------------------------------------------
subroutine amuxe (n,x,y,na,ncol,a,ja)
real*8 x(n), y(n), a(na,*)
integer n, na, ncol, ja(na,*)
c-----------------------------------------------------------------------
c A times a vector in Ellpack Itpack format (ELL)
c-----------------------------------------------------------------------
c multiplies a matrix by a vector when the original matrix is stored
c in the ellpack-itpack sparse format.
c-----------------------------------------------------------------------
c
c on entry:
c----------
c n = row dimension of A
c x = real array of length equal to the column dimension of
c the A matrix.
c na = integer. The first dimension of arrays a and ja
c as declared by the calling program.
c ncol = integer. The number of active columns in array a.
c (i.e., the number of generalized diagonals in matrix.)
c a, ja = the real and integer arrays of the itpack format
c (a(i,k),k=1,ncol contains the elements of row i in matrix
c ja(i,k),k=1,ncol contains their column numbers)
c
c on return:
c-----------
c y = real array of length n, containing the product y=y=A*x
c
c-----------------------------------------------------------------------
c local variables
c
integer i, j
c-----------------------------------------------------------------------
do 1 i=1, n
y(i) = 0.0
1 continue
do 10 j=1,ncol
do 25 i = 1,n
y(i) = y(i)+a(i,j)*x(ja(i,j))
25 continue
10 continue
c
return
c--------end-of-amuxe---------------------------------------------------
c-----------------------------------------------------------------------
end
c----------------------------------------------------------------------c
c S P A R S K I T c
c----------------------------------------------------------------------c
c BASIC MATRIX-VECTOR OPERATIONS - MATVEC MODULE c
c Matrix-vector Mulitiplications and Triang. Solves c
c----------------------------------------------------------------------c
c contents: (as of Nov 18, 1991) c
c---------- c
c 1) Matrix-vector products: c
c--------------------------- c
c amux : A times a vector. Compressed Sparse Row (CSR) format. c
c amuxms: A times a vector. Modified Compress Sparse Row format. c
c atmux : Transp(A) times a vector. CSR format. c
c atmuxr: Transp(A) times a vector. CSR format. A rectangular. c
c amuxe : A times a vector. Ellpack/Itpack (ELL) format. c
c amuxd : A times a vector. Diagonal (DIA) format. c
c amuxj : A times a vector. Jagged Diagonal (JAD) format. c
c vbrmv : Sparse matrix-full vector product, in VBR format c
c c
c 2) Triangular system solutions: c
c------------------------------- c
c lsol : Unit Lower Triang. solve. Compressed Sparse Row (CSR) format.c
c ldsol : Lower Triang. solve. Modified Sparse Row (MSR) format. c
c lsolc : Unit Lower Triang. solve. Comp. Sparse Column (CSC) format. c
c ldsolc: Lower Triang. solve. Modified Sparse Column (MSC) format. c
c ldsoll: Lower Triang. solve with level scheduling. MSR format. c
c usol : Unit Upper Triang. solve. Compressed Sparse Row (CSR) format.c
c udsol : Upper Triang. solve. Modified Sparse Row (MSR) format. c
c usolc : Unit Upper Triang. solve. Comp. Sparse Column (CSC) format. c
c udsolc: Upper Triang. solve. Modified Sparse Column (MSC) format. c
c----------------------------------------------------------------------c
c 1) M A T R I X B Y V E C T O R P R O D U C T S c
c----------------------------------------------------------------------c
subroutine amux (n, x, y, a,ja,ia)
real*8 x(*), y(*), a(*)
integer n, ja(*), ia(*)
c-----------------------------------------------------------------------
c A times a vector
c-----------------------------------------------------------------------
c multiplies a matrix by a vector using the dot product form
c Matrix A is stored in compressed sparse row storage.
c
c on entry:
c----------
c n = row dimension of A
c x = real array of length equal to the column dimension of
c the A matrix.
c a, ja,
c ia = input matrix in compressed sparse row format.
c
c on return:
c-----------
c y = real array of length n, containing the product y=Ax
c
c-----------------------------------------------------------------------
c local variables
c
real*8 t
integer i, k
c-----------------------------------------------------------------------
do 100 i = 1,n
c
c compute the inner product of row i with vector x
c
t = 0.0d0
do 99 k=ia(i), ia(i+1)-1
t = t + a(k)*x(ja(k))
99 continue
c
c store result in y(i)
c
y(i) = t
100 continue
c
return
c---------end-of-amux---------------------------------------------------
c-----------------------------------------------------------------------
end
c-----------------------------------------------------------------------
subroutine amuxj (n, x, y, jdiag, a, ja, ia)
integer n, jdiag, ja(*), ia(*)
real*8 x(n), y(n), a(*)
c-----------------------------------------------------------------------
c A times a vector in Jagged-Diagonal storage format (JAD)
c-----------------------------------------------------------------------
c multiplies a matrix by a vector when the original matrix is stored
c in the jagged diagonal storage format.
c-----------------------------------------------------------------------
c
c on entry:
c----------
c n = row dimension of A
c x = real array of length equal to the column dimension of
c the A matrix.
c jdiag = integer. The number of jadded-diagonals in the data-structure.
c a = real array containing the jadded diagonals of A stored
c in succession (in decreasing lengths)
c j = integer array containing the colum indices of the
c corresponding elements in a.
c ia = integer array containing the lengths of the jagged diagonals
c
c on return:
c-----------
c y = real array of length n, containing the product y=A*x
c
c Note:
c-------
c Permutation related to the JAD format is not performed.
c this can be done by:
c call permvec (n,y,y,iperm)
c after the call to amuxj, where iperm is the permutation produced
c by csrjad.
c-----------------------------------------------------------------------
c local variables
c
integer i, ii, k1, len, j
c-----------------------------------------------------------------------
do 1 i=1, n
y(i) = 0.0d0
1 continue
do 70 ii=1, jdiag
k1 = ia(ii)-1
len = ia(ii+1)-k1-1
do 60 j=1,len
y(j)= y(j)+a(k1+j)*x(ja(k1+j))
60 continue
70 continue
c
return
c----------end-of-amuxj-------------------------------------------------
c-----------------------------------------------------------------------
end
c-----------------------------------------------------------------------
subroutine amuxms (n, x, y, a,ja)
real*8 x(*), y(*), a(*)
integer n, ja(*)
c-----------------------------------------------------------------------
c A times a vector in MSR format
c-----------------------------------------------------------------------
c multiplies a matrix by a vector using the dot product form
c Matrix A is stored in Modified Sparse Row storage.
c
c on entry:
c----------
c n = row dimension of A
c x = real array of length equal to the column dimension of
c the A matrix.
c a, ja,= input matrix in modified compressed sparse row format.
c
c on return:
c-----------
c y = real array of length n, containing the product y=Ax
c
c-----------------------------------------------------------------------
c local variables
c
integer i, k
c-----------------------------------------------------------------------
do 10 i=1, n
y(i) = a(i)*x(i)
10 continue
do 100 i = 1,n
c
c compute the inner product of row i with vector x
c
do 99 k=ja(i), ja(i+1)-1
y(i) = y(i) + a(k) *x(ja(k))
99 continue
100 continue
c
return
c---------end-of-amuxm--------------------------------------------------
c-----------------------------------------------------------------------
end
c **********************************************************************
subroutine ANCCNX(n, mccnex, iccnex, mark, ncount)
C-----------------------------------------------------------------------
c
c We put in ICCNEX the vertices marked in the component MCCNEX.
C
C-----------------------------------------------------------------------
c include "NSIMPLIC"
dimension mark(n)
C-----------------------------------------------------------------------
C Laura C. Dutto - email: [email protected] - December 1993
C-----------------------------------------------------------------------
ncount = 0
do i = 1, n
if( mark(i) .eq. mccnex) then
mark(i) = iccnex
ncount = ncount + 1
endif
enddo
c
return
end
c----------------------------------------------------------------------
subroutine ansym(n,sym,a,ja,ia,ao,jao,iao,imatch,
* av,fas,fan)
c---------------------------------------------------------------------
c this routine computes the Frobenius norm of the symmetric and
c non-symmetric parts of A, computes number of matching elements
c in symmetry and relative symmetry match.
c---------------------------------------------------------------------
c on entry:
c----------
c n = integer column dimension of matrix
c a = real array containing the nonzero elements of the matrix
c the elements are stored by columns in order
c (i.e. column i comes before column i+1, but the elements
c within each column can be disordered).
c ja = integer array containing the row indices of elements in a
c ia = integer array containing of length n+1 containing the
c pointers to the beginning of the columns in arrays a and ja.
c It is assumed that ia(*) = 1 and ia(n+1) = nzz+1.
c sym = logical variable indicating whether or not the matrix is
c symmetric.
c on return
c----------
c fas = Frobenius norm of symmetric part
c fan = Frobenius norm of non-symmetric part
c imatch = number of matching elements in symmetry
c av = relative symmetry match (symmetry = 1)
c ao,jao,iao = transpose of A just as a, ja, ia contains
c information of A.
c-----------------------------------------------------------------------
implicit real*8 (a-h, o-z)
real*8 a(*),ao(*),fas,fan,av, Fnorm, st
integer n, ja(*), ia(n+1), jao(*), iao(n+1),imatch
logical sym
c-----------------------------------------------------------------------
nnz = ia(n+1)-ia(1)
call csrcsc(n,1,1,a,ja,ia,ao,jao,iao)
if (sym) goto 7
st = 0.0d0
fas = 0.0d0
fan = 0.0d0
imatch = 0
do 6 i=1,n
k1 = ia(i)
k2 = iao(i)
k1max = ia(i+1) - 1
k2max = iao(i+1) - 1
c
5 if (k1 .gt. k1max .or. k2 .gt. k2max) goto 6
c
j1 = ja(k1)
j2 = jao(k2)
if (j1 .ne. j2 ) goto 51
fas = fas + (a(k1)+ao(k2))**2
fan = fan + (a(k1)-ao(k2))**2
st = st + a(k1)**2
imatch = imatch + 1
51 k1 = k1+1
k2 = k2+1
if (j1 .lt. j2) k2 = k2 - 1
if (j1 .gt. j2) k1 = k1 - 1
goto 5
6 continue
fas = 0.25D0 * fas
fan = 0.25D0 * fan
7 call frobnorm(n,sym,ao,jao,iao,Fnorm)
if (sym) then
imatch = nnz
fas = Fnorm
fan = 0.0d0
else
if (imatch.eq.nnz) then
st = 0.0D0
else
st = 0.5D0 * (Fnorm**2 - st)
if (st.lt.0.0D0) st = 0.0D0
endif
fas = sqrt(fas + st)
fan = sqrt(fan + st)
endif
av = real(imatch)/real(nnz)
return
end
c-----------------------------------------------------------------------
subroutine aplb1(nrow,ncol,job,a,ja,ia,b,jb,ib,c,jc,ic,nzmax,ierr)
real*8 a(*), b(*), c(*)
integer ja(*),jb(*),jc(*),ia(nrow+1),ib(nrow+1),ic(nrow+1)
c-----------------------------------------------------------------------
c performs the matrix sum C = A+B for matrices in sorted CSR format.
c the difference with aplb is that the resulting matrix is such that
c the elements of each row are sorted with increasing column indices in
c each row, provided the original matrices are sorted in the same way.
c-----------------------------------------------------------------------
c on entry:
c ---------
c nrow = integer. The row dimension of A and B
c ncol = integer. The column dimension of A and B.
c job = integer. Job indicator. When job = 0, only the structure
c (i.e. the arrays jc, ic) is computed and the
c real values are ignored.
c
c a,
c ja,
c ia = Matrix A in compressed sparse row format with entries sorted
c
c b,
c jb,
c ib = Matrix B in compressed sparse row format with entries sorted
c ascendly in each row
c
c nzmax = integer. The length of the arrays c and jc.
c amub will stop if the result matrix C has a number
c of elements that exceeds exceeds nzmax. See ierr.
c
c on return:
c----------
c c,
c jc,
c ic = resulting matrix C in compressed sparse row sparse format
c with entries sorted ascendly in each row.
c
c ierr = integer. serving as error message.
c ierr = 0 means normal return,
c ierr .gt. 0 means that amub stopped while computing the
c i-th row of C with i=ierr, because the number
c of elements in C exceeds nzmax.
c
c Notes:
c-------
c this will not work if any of the two input matrices is not sorted
c-----------------------------------------------------------------------
logical values
values = (job .ne. 0)
ierr = 0
kc = 1
ic(1) = kc
c
do 6 i=1, nrow
ka = ia(i)
kb = ib(i)
kamax = ia(i+1)-1
kbmax = ib(i+1)-1
5 continue
if (ka .le. kamax) then
j1 = ja(ka)
else
j1 = ncol+1
endif
if (kb .le. kbmax) then
j2 = jb(kb)
else
j2 = ncol+1
endif
c
c three cases
c
if (kc .gt. nzmax) goto 999
if (j1 .eq. j2) then
if (values) c(kc) = a(ka)+b(kb)
jc(kc) = j1
ka = ka+1
kb = kb+1
kc = kc+1
else if (j1 .lt. j2) then
jc(kc) = j1
if (values) c(kc) = a(ka)
ka = ka+1
kc = kc+1
else if (j1 .gt. j2) then
jc(kc) = j2
if (values) c(kc) = b(kb)
kb = kb+1
kc = kc+1
endif
if (ka .le. kamax .or. kb .le. kbmax) goto 5
ic(i+1) = kc
6 continue
return
999 ierr = i
return
c------------end-of-aplb1-----------------------------------------------
c-----------------------------------------------------------------------
end
c-----------------------------------------------------------------------
subroutine aplbdg (nrow,ncol,ja,ia,jb,ib,ndegr,nnz,iw)
integer ja(*),jb(*),ia(nrow+1),ib(nrow+1),iw(ncol),ndegr(nrow)
c-----------------------------------------------------------------------
c gets the number of nonzero elements in each row of A+B and the total
c number of nonzero elements in A+B.
c-----------------------------------------------------------------------
c on entry:
c ---------
c nrow = integer. The row dimension of A and B
c ncol = integer. The column dimension of A and B.
c
c a,
c ja,
c ia = Matrix A in compressed sparse row format.