5164
|
1 C ====================================================================== |
|
2 C === Fortran AMD demo main program ==================================== |
|
3 C ====================================================================== |
|
4 |
|
5 C ---------------------------------------------------------------------- |
|
6 C AMD Version 1.1 (Jan. 21, 2004), Copyright (c) 2004 by Timothy A. |
|
7 C Davis, Patrick R. Amestoy, and Iain S. Duff. See ../README for |
|
8 C License. email: davis@cise.ufl.edu CISE Department, Univ. of |
|
9 C Florida. web: http://www.cise.ufl.edu/research/sparse/amd |
|
10 C ---------------------------------------------------------------------- |
|
11 |
|
12 C A simple Fortran 77 main program that illustrates the use of the |
|
13 C Fortran version of AMD (both the AMD and AMDBAR routines). Note |
|
14 C that aggressive absorption has no effect on this particular matrix. |
|
15 |
|
16 C AP and AI contain the symmetric can_24 Harwell/Boeing matrix, |
|
17 C including upper and lower triangular parts, but excluding the |
|
18 C diagonal entries. Note that this matrix is 1-based, with row |
|
19 C and column indices in the range 1 to N. |
|
20 |
|
21 INTEGER N, NZ, IWLEN, PFREE, I, J, K, JNEW, P, INEW, |
|
22 $ METHOD, NCMPA |
|
23 PARAMETER (N = 24, NZ = 136, IWLEN = 200) |
|
24 INTEGER PE (N), DEGREE (N), NV (N), NEXT (N), PERM (N), W (N), |
|
25 $ HEAD (N), PINV (N), LEN (N), AP (N+1), AI (NZ), IW (IWLEN) |
|
26 CHARACTER A (24,24) |
|
27 |
|
28 DATA AP |
|
29 $ / 1, 9, 14, 19, 24, 29, 34, 42, 50, 53, 61, 66, 71, |
|
30 $ 76, 81, 86, 91, 94, 102, 110, 118, 123, 131, 134, 137 / |
|
31 DATA AI / |
|
32 $ 6, 7, 13, 14, 18, 19, 20, 22, |
|
33 $ 9, 10, 14, 15, 18, |
|
34 $ 7, 12, 21, 22, 23, |
|
35 $ 8, 11, 16, 19, 20, |
|
36 $ 8, 10, 15, 16, 17, |
|
37 $ 1, 7, 13, 14, 18, |
|
38 $ 1, 3, 6, 12, 13, 20, 22, 24, |
|
39 $ 4, 5, 10, 15, 16, 17, 18, 19, |
|
40 $ 2, 10, 15, |
|
41 $ 2, 5, 8, 9, 14, 15, 18, 19, |
|
42 $ 4, 19, 20, 21, 22, |
|
43 $ 3, 7, 13, 22, 24, |
|
44 $ 1, 6, 7, 12, 24, |
|
45 $ 1, 2, 6, 10, 18, |
|
46 $ 2, 5, 8, 9, 10, |
|
47 $ 4, 5, 8, 17, 19, |
|
48 $ 5, 8, 16, |
|
49 $ 1, 2, 6, 8, 10, 14, 19, 20, |
|
50 $ 1, 4, 8, 10, 11, 16, 18, 20, |
|
51 $ 1, 4, 7, 11, 18, 19, 21, 22, |
|
52 $ 3, 11, 20, 22, 23, |
|
53 $ 1, 3, 7, 11, 12, 20, 21, 23, |
|
54 $ 3, 21, 22, |
|
55 $ 7, 12, 13 / |
|
56 |
|
57 C print the input matrix |
|
58 PRINT 11, N, N, NZ |
|
59 11 FORMAT ('AMD Fortran 77 demo, with the 24-by-24', |
|
60 $ ' Harwell/Boeing matrix, can_24:' |
|
61 $ /, 'Input matrix: ', I2, '-by-', I2,' with ',I3,' entries', |
|
62 $ /, 'Note that the Fortran version of AMD requires that' |
|
63 $ /, 'no diagonal entries be present.') |
|
64 DO 20 J = 1, N |
|
65 PRINT 21, J, AP (J+1) - AP (J), AP (J), AP (J+1)-1 |
|
66 21 FORMAT ( /, 'Column: ', I2, ' number of entries: ', I2, |
|
67 $ ' with row indices in AI (', I3, ' ... ', I3, ')') |
|
68 PRINT 10, ((AI (P)), P = AP (J), AP (J+1) - 1) |
|
69 10 FORMAT (' row indices: ', 24I3) |
|
70 20 CONTINUE |
|
71 |
|
72 C print a character plot of the input matrix. This is only |
|
73 C reasonable because the matrix is small. |
|
74 PRINT 31 |
|
75 31 FORMAT ('Plot of input matrix pattern:') |
|
76 DO 50 J = 1,N |
|
77 DO 30 I = 1,N |
|
78 A (I, J) = '.' |
|
79 30 CONTINUE |
|
80 C add the diagonal entry to the plot |
|
81 A (J, J) = 'X' |
|
82 DO 40 P = AP (J), AP (J+1) - 1 |
|
83 I = AI (P) |
|
84 A (I, J) = 'X' |
|
85 40 CONTINUE |
|
86 50 CONTINUE |
|
87 PRINT 60, ((MOD (J, 10)), J = 1,N) |
|
88 60 FORMAT (' ', 24I2) |
|
89 DO 80 I = 1,N |
|
90 PRINT 70, I, (A (I, J), J = 1,N) |
|
91 70 FORMAT (' ', I2, ': ', 24A2) |
|
92 80 CONTINUE |
|
93 |
|
94 DO 190 METHOD = 1,2 |
|
95 |
|
96 C load the matrix into AMD's workspace |
|
97 DO 90 J = 1,N |
|
98 PE (J) = AP (J) |
|
99 LEN (J) = AP (J+1) - AP (J) |
|
100 90 CONTINUE |
|
101 DO 100 P = 1,NZ |
|
102 IW (P) = AI (P) |
|
103 100 CONTINUE |
|
104 PFREE = NZ + 1 |
|
105 |
|
106 C order the matrix using AMD or AMDBAR |
|
107 IF (METHOD .EQ. 1) THEN |
|
108 PRINT 101 |
|
109 101 FORMAT (/, '------------------------------------------', |
|
110 $ /, 'ordering the matrix with AMD', |
|
111 $ /, '------------------------------------------') |
|
112 CALL AMD (N, PE, IW, LEN, IWLEN, PFREE, NV, NEXT, |
|
113 $ PERM, HEAD, PINV, DEGREE, NCMPA, W) |
|
114 ELSE |
|
115 PRINT 102 |
|
116 102 FORMAT (/, '------------------------------------------', |
|
117 $ /, 'ordering the matrix with AMDBAR', |
|
118 $ /, '------------------------------------------') |
|
119 CALL AMDBAR (N, PE, IW, LEN, IWLEN, PFREE, NV, NEXT, |
|
120 $ PERM, HEAD, PINV, DEGREE, NCMPA, W) |
|
121 ENDIF |
|
122 |
|
123 C print the permutation vector, PERM, and its inverse, PINV. |
|
124 C row/column J = PERM (K) is the Kth row/column in the |
|
125 C permuted matrix. |
|
126 PRINT 110, (PERM (K), K = 1,N) |
|
127 110 FORMAT (/, 'Permutation vector: ', /, 24I3) |
|
128 PRINT 120, (PINV (J), J = 1,N) |
|
129 120 FORMAT (/, 'Inverse permutation vector: ', /, 24I3) |
|
130 |
|
131 C print a character plot of the permuted matrix. |
|
132 PRINT 121 |
|
133 121 FORMAT ('Plot of permuted matrix pattern:') |
|
134 DO 150 JNEW = 1,N |
|
135 J = PERM (JNEW) |
|
136 DO 130 INEW = 1,N |
|
137 A (INEW, JNEW) = '.' |
|
138 130 CONTINUE |
|
139 C add the diagonal entry to the plot |
|
140 A (JNEW, JNEW) = 'X' |
|
141 DO 140 P = AP (J), AP (J+1) - 1 |
|
142 INEW = PINV (AI (P)) |
|
143 A (INEW, JNEW) = 'X' |
|
144 140 CONTINUE |
|
145 150 CONTINUE |
|
146 PRINT 60, ((MOD (J, 10)), J = 1,N) |
|
147 DO 160 I = 1,N |
|
148 PRINT 70, I, (A (I, J), J = 1,N) |
|
149 160 CONTINUE |
|
150 |
|
151 C print the permuted matrix, PERM*A*PERM' |
|
152 DO 180 JNEW = 1,N |
|
153 J = PERM (JNEW) |
|
154 PRINT 171, JNEW, J, AP (J+1) - AP (J) |
|
155 171 FORMAT (/, 'New column: ', I2, ' old column: ', I2, |
|
156 $ ' number of entries: ', I2) |
|
157 PRINT 170, (PINV (AI (P)), P = AP (J), AP (J+1) - 1) |
|
158 170 FORMAT (' new row indices: ', 24I3) |
|
159 180 CONTINUE |
|
160 190 CONTINUE |
|
161 END |