forked from xiaoyeli/superlu_dist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpzdrive3.c
executable file
·317 lines (275 loc) · 9.95 KB
/
pzdrive3.c
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
/*! \file
Copyright (c) 2003, The Regents of the University of California, through
Lawrence Berkeley National Laboratory (subject to receipt of any required
approvals from U.S. Dept. of Energy)
All rights reserved.
The source code is distributed under BSD license, see the file License.txt
at the top-level directory.
*/
/*! @file
* \brief Driver program for PZGSSVX example
*
* <pre>
* -- Distributed SuperLU routine (version 9.0) --
* Lawrence Berkeley National Lab, Univ. of California Berkeley.
* March 15, 2003
* April 5, 2015
* </pre>
*/
#include <math.h>
#include "superlu_zdefs.h"
/*! \brief
*
* <pre>
* Purpose
* =======
*
* The driver program PZDRIVE3.
*
* This example illustrates how to use PZGSSVX to solve
* systems repeatedly with the same sparsity pattern and similar
* numerical values of matrix A.
* In this case, the row and column permutation vectors and symbolic
* factorization are computed only once. The following data structures
* will be reused in the subsequent call to PZGSSVX:
* ScalePermstruct : DiagScale, R, C, perm_r, perm_c
* LUstruct : etree, Glu_persist, Llu
*
* NOTE:
* The distributed nonzero structures of L and U remain the same,
* although the numerical values are different. So 'Llu' is set up once
* in the first call to PZGSSVX, and reused in the subsequent call.
*
* With MPICH, program may be run by typing:
* mpiexec -n <np> pzdrive3 -r <proc rows> -c <proc columns> big.rua
* </pre>
*/
int main(int argc, char *argv[])
{
superlu_dist_options_t options;
SuperLUStat_t stat;
SuperMatrix A;
NRformat_loc *Astore;
zScalePermstruct_t ScalePermstruct;
zLUstruct_t LUstruct;
zSOLVEstruct_t SOLVEstruct;
gridinfo_t grid;
double *berr;
doublecomplex *b, *b1, *xtrue, *nzval, *nzval1;
int_t *colind, *colind1, *rowptr, *rowptr1;
int_t i, j, m, n, nnz_loc, m_loc, fst_row;
int nprow, npcol;
int iam, info, ldb, ldx, nrhs;
char **cpp, c, *postfix;
int ii, omp_mpi_level;
FILE *fp, *fopen();
int cpp_defs();
nprow = 1; /* Default process rows. */
npcol = 1; /* Default process columns. */
nrhs = 1; /* Number of right-hand side. */
/* ------------------------------------------------------------
INITIALIZE MPI ENVIRONMENT.
------------------------------------------------------------*/
MPI_Init_thread( &argc, &argv, MPI_THREAD_MULTIPLE, &omp_mpi_level);
/* Parse command line argv[]. */
for (cpp = argv+1; *cpp; ++cpp) {
if ( **cpp == '-' ) {
c = *(*cpp+1);
++cpp;
switch (c) {
case 'h':
printf("Options:\n");
printf("\t-r <int>: process rows (default %d)\n", nprow);
printf("\t-c <int>: process columns (default %d)\n", npcol);
exit(0);
break;
case 'r': nprow = atoi(*cpp);
break;
case 'c': npcol = atoi(*cpp);
break;
}
} else { /* Last arg is considered a filename */
if ( !(fp = fopen(*cpp, "r")) ) {
ABORT("File does not exist");
}
break;
}
}
/* ------------------------------------------------------------
INITIALIZE THE SUPERLU PROCESS GRID.
------------------------------------------------------------*/
superlu_gridinit(MPI_COMM_WORLD, nprow, npcol, &grid);
/* Bail out if I do not belong in the grid. */
iam = grid.iam;
if ( iam == -1 ) goto out;
if ( !iam ) {
int v_major, v_minor, v_bugfix;
#ifdef __INTEL_COMPILER
printf("__INTEL_COMPILER is defined\n");
#endif
printf("__STDC_VERSION__ %ld\n", __STDC_VERSION__);
superlu_dist_GetVersionNumber(&v_major, &v_minor, &v_bugfix);
printf("Library version:\t%d.%d.%d\n", v_major, v_minor, v_bugfix);
printf("Input matrix file:\t%s\n", *cpp);
printf("Process grid:\t\t%d X %d\n", (int)grid.nprow, (int)grid.npcol);
fflush(stdout);
}
#if ( DEBUGlevel>=1 )
CHECK_MALLOC(iam, "Enter main()");
#endif
for(ii = 0;ii<strlen(*cpp);ii++){
if((*cpp)[ii]=='.'){
postfix = &((*cpp)[ii+1]);
}
}
// printf("%s\n", postfix);
/* ------------------------------------------------------------
GET THE MATRIX FROM FILE AND SETUP THE RIGHT HAND SIDE.
------------------------------------------------------------*/
zcreate_matrix_postfix(&A, nrhs, &b, &ldb, &xtrue, &ldx, fp, postfix, &grid);
if ( !(b1 = doublecomplexMalloc_dist(ldb * nrhs)) )
ABORT("Malloc fails for b1[]");
for (j = 0; j < nrhs; ++j)
for (i = 0; i < ldb; ++i) b1[i+j*ldb] = b[i+j*ldb];
if ( !(berr = doubleMalloc_dist(nrhs)) )
ABORT("Malloc fails for berr[].");
m = A.nrow;
n = A.ncol;
/* Save a copy of the matrix A. */
Astore = (NRformat_loc *) A.Store;
nnz_loc = Astore->nnz_loc;
m_loc = Astore->m_loc;
fst_row = Astore->fst_row;
nzval = Astore->nzval;
colind = Astore->colind;
rowptr = Astore->rowptr;
nzval1 = doublecomplexMalloc_dist(nnz_loc);
colind1 = intMalloc_dist(nnz_loc);
rowptr1 = intMalloc_dist(m_loc+1);
for (i = 0; i < nnz_loc; ++i) {
nzval1[i] = nzval[i];
colind1[i] = colind[i];
}
for (i = 0; i < m_loc+1; ++i) rowptr1[i] = rowptr[i];
/* ------------------------------------------------------------
WE SOLVE THE LINEAR SYSTEM FOR THE FIRST TIME.
------------------------------------------------------------*/
/* Set the default input options:
options.Fact = DOFACT;
options.Equil = YES;
options.ColPerm = METIS_AT_PLUS_A;
options.RowPerm = LargeDiag_MC64;
options.ReplaceTinyPivot = NO;
options.Trans = NOTRANS;
options.IterRefine = SLU_DOUBLE;
options.SolveInitialized = NO;
options.RefineInitialized = NO;
options.PrintStat = YES;
*/
set_default_options_dist(&options);
if (!iam) {
print_options_dist(&options);
fflush(stdout);
}
/* Initialize ScalePermstruct and LUstruct. */
zScalePermstructInit(m, n, &ScalePermstruct);
zLUstructInit(n, &LUstruct);
/* Initialize the statistics variables. */
PStatInit(&stat);
/* Call the linear equation solver: factorize and solve. */
pzgssvx(&options, &A, &ScalePermstruct, b, ldb, nrhs, &grid,
&LUstruct, &SOLVEstruct, berr, &stat, &info);
if ( info ) { /* Something is wrong */
if ( iam==0 ) {
printf("ERROR: INFO = %d returned from pzgssvx()\n", info);
fflush(stdout);
}
} else {
/* Check the accuracy of the solution. */
pzinf_norm_error(iam, m_loc, nrhs, b, ldb, xtrue, ldx, grid.comm);
}
PStatPrint(&options, &stat, &grid); /* Print the statistics. */
Destroy_CompRowLoc_Matrix_dist(&A); /* Deallocate storage of matrix A. */
SUPERLU_FREE(b); /* Free storage of right-hand side. */
/* ------------------------------------------------------------
NOW WE SOLVE ANOTHER LINEAR SYSTEM.
THE MATRIX A HAS THE SAME SPARSITY PATTERN AND THE SIMILAR
NUMERICAL VALUES AS THAT IN A PREVIOUS SYSTEM.
------------------------------------------------------------*/
options.Fact = SamePattern_SameRowPerm;
PStatClear(&stat); /* clear the statistics variables. */
/* Set up the local A in NR_loc format */
/* Perturb the 1st diagonal of the matrix to larger value.
Intention is to change values of A. */
if (iam == 0) {
nzval1[0].r += 1.0e-8; nzval1[0].i += 1.0e-8;
}
/* Zero the numerical values in L and U. */
zZeroLblocks(iam, n, &grid, &LUstruct);
zZeroUblocks(iam, n, &grid, &LUstruct);
zCreate_CompRowLoc_Matrix_dist(&A, m, n, nnz_loc, m_loc, fst_row,
nzval1, colind1, rowptr1,
SLU_NR_loc, SLU_Z, SLU_GE);
/* Solve the linear system. */
pzgssvx(&options, &A, &ScalePermstruct, b1, ldb, nrhs, &grid,
&LUstruct, &SOLVEstruct, berr, &stat, &info);
if ( info ) { /* Something is wrong */
if ( iam==0 ) {
printf("ERROR: INFO = %d returned from pzgssvx()\n", info);
fflush(stdout);
}
} else {
/* Check the accuracy of the solution. */
if ( !iam )
printf("Solve a system with the same pattern and similar values.\n");
pzinf_norm_error(iam, m_loc, nrhs, b1, ldb, xtrue, ldx, grid.comm);
}
/* Print the statistics. */
PStatPrint(&options, &stat, &grid);
/* ------------------------------------------------------------
DEALLOCATE ALL STORAGE.
------------------------------------------------------------*/
PStatFree(&stat);
Destroy_CompRowLoc_Matrix_dist(&A); /* Deallocate storage of matrix A. */
zDestroy_LU(n, &grid, &LUstruct); /* Deallocate storage associated with
the L and U matrices. */
zScalePermstructFree(&ScalePermstruct);
zLUstructFree(&LUstruct); /* Deallocate the structure of L and U.*/
if ( options.SolveInitialized ) {
zSolveFinalize(&options, &SOLVEstruct);
}
SUPERLU_FREE(b1); /* Free storage of right-hand side. */
SUPERLU_FREE(xtrue); /* Free storage of the exact solution. */
SUPERLU_FREE(berr);
fclose(fp);
/* ------------------------------------------------------------
RELEASE THE SUPERLU PROCESS GRID.
------------------------------------------------------------*/
out:
superlu_gridexit(&grid);
/* ------------------------------------------------------------
TERMINATES THE MPI EXECUTION ENVIRONMENT.
------------------------------------------------------------*/
MPI_Finalize();
#if ( DEBUGlevel>=1 )
CHECK_MALLOC(iam, "Exit main()");
#endif
}
int cpp_defs()
{
printf(".. CPP definitions:\n");
#if ( PRNTlevel>=1 )
printf("\tPRNTlevel = %d\n", PRNTlevel);
#endif
#if ( DEBUGlevel>=1 )
printf("\tDEBUGlevel = %d\n", DEBUGlevel);
#endif
#if ( PROFlevel>=1 )
printf("\tPROFlevel = %d\n", PROFlevel);
#endif
#if ( StaticPivot>=1 )
printf("\tStaticPivot = %d\n", StaticPivot);
#endif
printf("....\n");
return 0;
}