-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpslinsol.cpp
289 lines (255 loc) · 6.86 KB
/
pslinsol.cpp
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
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <ctime>
using namespace std;
# include "pssp_defs.h"
int main ( int argc, char *argv[] );
void parse_command_line ( int argc, char *argv[], int *procs, int *n,
int *b, int *w, int *r, int *maxsup );
void timestamp ( );
//****************************************************************************80
int main ( int argc, char *argv[] )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for PSLINSOL.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 11 March 2014
//
// Author:
//
// Xiaoye Li
//
{
SuperMatrix A;
NCformat *Astore;
float *a;
int *asub, *xa;
int *perm_r; /* row permutations from partial pivoting */
int *perm_c; /* column permutation vector */
SuperMatrix L; /* factor L */
SCPformat *Lstore;
SuperMatrix U; /* factor U */
NCPformat *Ustore;
SuperMatrix B;
int nrhs, ldx, info, m, n, nnz, b;
int nprocs; /* maximum number of processors to use. */
int panel_size, relax, maxsup;
int permc_spec;
trans_t trans;
float *xact, *rhs;
superlu_memusage_t superlu_memusage;
timestamp ( );
cout << "\n";
cout << "PSLINSOL:\n";
cout << " C++/OpenMP version\n";
cout << " Call the OpenMP version of SuperLU to solve a linear system.\n";
nrhs = 1;
trans = NOTRANS;
nprocs = 1;
n = 1000;
b = 1;
panel_size = sp_ienv(1);
relax = sp_ienv(2);
maxsup = sp_ienv(3);
//
// Check for any commandline input.
//
parse_command_line ( argc, argv, &nprocs, &n, &b, &panel_size, &relax,
&maxsup );
#if ( PRNTlevel>=1 || DEBUGlevel>=1 )
cpp_defs();
#endif
#define HB
#if defined( DEN )
m = n;
nnz = n * n;
sband(n, n, nnz, &a, &asub, &xa);
#elif defined( BAND )
m = n;
nnz = (2*b+1) * n;
sband(n, b, nnz, &a, &asub, &xa);
#elif defined( BD )
nb = 5;
bs = 200;
m = n = bs * nb;
nnz = bs * bs * nb;
sblockdiag(nb, bs, nnz, &a, &asub, &xa);
#elif defined( HB )
sreadhb(&m, &n, &nnz, &a, &asub, &xa);
#else
sreadmt(&m, &n, &nnz, &a, &asub, &xa);
#endif
sCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_S, SLU_GE);
//
// I had to add the ( NCformat* )...
//
Astore = ( NCformat* ) A.Store;
cout << "Dimension " << A.nrow << "x" << A.ncol << "; # nonzeros " << Astore->nnz << "\n";
if (!(rhs = floatMalloc(m * nrhs)))
{
SUPERLU_ABORT("Malloc fails for rhs[].");
}
sCreate_Dense_Matrix(&B, m, nrhs, rhs, m, SLU_DN, SLU_S, SLU_GE);
xact = floatMalloc(n * nrhs);
ldx = n;
sGenXtrue(n, nrhs, xact, ldx);
sFillRHS(trans, nrhs, xact, ldx, &A, &B);
if (!(perm_r = intMalloc(m)))
{
SUPERLU_ABORT("Malloc fails for perm_r[].");
}
if (!(perm_c = intMalloc(n)))
{
SUPERLU_ABORT("Malloc fails for perm_c[].");
}
//
// Get column permutation vector perm_c[], according to permc_spec:
// 0: natural ordering
// 1: minimum degree ordering on structure of A'*A
// 2: minimum degree ordering on structure of A'+A
// 3: approximate minimum degree for unsymmetric matrices
//
permc_spec = 1;
get_perm_c(permc_spec, &A, perm_c);
psgssv ( nprocs, &A, perm_c, perm_r, &L, &U, &B, &info );
/*
Inf. norm of the error
*/
if ( info == 0 )
{
sinf_norm_error ( nrhs, &B, xact );
Lstore = ( SCPformat * ) L.Store;
Ustore = ( NCPformat * ) U.Store;
cout << "#NZ in factor L = " << Lstore->nnz << "\n";
cout << "#NZ in factor U = " << Ustore->nnz << "\n";
cout << "#NZ in L+U = " << Lstore->nnz + Ustore->nnz - L.ncol << "\n";
superlu_sQuerySpace(nprocs, &L, &U, panel_size, &superlu_memusage);
cout << "L\\U MB " << superlu_memusage.for_lu/1024/1024
<< " total MB needed " << superlu_memusage.total_needed/1024/1024
<< " expansions " << superlu_memusage.expansions << "\n";
}
SUPERLU_FREE (rhs);
SUPERLU_FREE (xact);
SUPERLU_FREE (perm_r);
SUPERLU_FREE (perm_c);
Destroy_CompCol_Matrix(&A);
Destroy_SuperMatrix_Store(&B);
Destroy_SuperNode_SCP(&L);
Destroy_CompCol_NCP(&U);
//
// Terminate.
//
cout << "\n";
cout << "PSLINSOL:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
void parse_command_line ( int argc, char *argv[], int *procs, int *n,
int *b, int *w, int *r, int *maxsup )
//****************************************************************************80
//
// Purpose:
//
// PARSE_COMMAND_LINE parses the command line.
//
// Discussion:
//
// The user can include command line arguments to get relaxed snode
// size, panel size, etc.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 11 March 2014
//
// Author:
//
// Xiaoye Li
//
{
register int c;
extern char *optarg;
while ( (c = getopt(argc, argv, "ht:p:n:b:w:x:s:")) != EOF ) {
switch (c) {
case 'h':
cout << "Options: (default values are in parenthesis)\n";
cout << "-p <int> - number of processes ( " << *procs << " )\n";
cout << "-n <int> - dimension ( " << *n << " )\n";
cout << "-b <int> - semi-bandwidth ( " << *b << " )\n";
cout << "-w <int> - panel size ( " << *w << " )\n";
cout << "-x <int> - relax ( " << *r << " )\n";
cout << "-s <int> - maximum supernode size ( " << *maxsup << " )\n";
exit(1);
break;
case 'p': *procs = atoi(optarg);
break;
case 'n': *n = atoi(optarg);
break;
case 'b': *b = atoi(optarg);
break;
case 'w': *w = atoi(optarg);
break;
case 'x': *r = atoi(optarg);
break;
case 's': *maxsup = atoi(optarg);
break;
}
}
return;
}
//****************************************************************************80
void timestamp ( )
//****************************************************************************80
//
// Purpose:
//
// TIMESTAMP prints the current YMDHMS date as a time stamp.
//
// Example:
//
// 31 May 2001 09:45:54 AM
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 08 July 2009
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// None
//
{
# define TIME_SIZE 40
static char time_buffer[TIME_SIZE];
const struct std::tm *tm_ptr;
size_t len;
std::time_t now;
now = std::time ( NULL );
tm_ptr = std::localtime ( &now );
len = std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr );
std::cout << time_buffer << "\n";
return;
# undef TIME_SIZE
}