43 int main(
int argc,
char **argv){
47 #ifdef THIS_SHOULD_NOT_BE_DEFINED 65 #include "Teuchos_FileInputSource.hpp" 66 #include "Teuchos_XMLObject.hpp" 67 #include "Teuchos_XMLParameterListReader.hpp" 68 #include "EpetraExt_BlockMapIn.h" 69 #include "EpetraExt_CrsMatrixIn.h" 70 #include "EpetraExt_VectorIn.h" 71 #include "EpetraExt_MultiVectorIn.h" 79 void ML_Exit(
int mypid,
const char *msg,
int code);
81 void ML_Read_Matrix_Dimensions(
const char *filename,
int *numGlobalRows,
Epetra_Comm &
Comm);
83 int main(
int argc,
char *argv[])
86 MPI_Init(&argc,&argv);
88 int mypid =
Comm.MyPID();
95 ParameterList masterList;
97 if (strncmp(
"-h",argv[1],2) == 0) {
98 cout <<
"help" << endl;
100 ML_Exit(mypid,0,EXIT_SUCCESS);
104 FILE* fid = fopen(argv[1],
"r");
109 Comm.SumAll(&i, &j, 1);
110 if (j!=
Comm.NumProc()) {
111 cout <<
"Could not open input file." << endl;
113 ML_Exit(mypid,0,EXIT_FAILURE);
115 FileInputSource fileSrc(argv[1]);
116 XMLObject fileXML = fileSrc.getObject();
117 XMLParameterListReader ListReader;
118 masterList = ListReader.toParameterList(fileXML);
121 cout <<
"No input file specified." << endl;
123 ML_Exit(mypid,0,EXIT_SUCCESS);
126 ParameterList *fileList, *AztecOOList;
127 try {fileList = &(masterList.sublist(
"data files",
true));}
128 catch(...) {ML_Exit(mypid,
"Missing \"data files\" sublist.",EXIT_FAILURE);}
129 try {AztecOOList = &(masterList.sublist(
"AztecOO"));}
130 catch(...) {ML_Exit(mypid,
"Missing \"AztecOO\" sublist.",EXIT_FAILURE);}
134 enum {total, probBuild, precBuild, solve};
135 ml_DblLoc timeVec[ntimers], maxTime[ntimers], minTime[ntimers];
137 for (
int i=0; i<ntimers; i++) timeVec[i].rank =
Comm.MyPID();
138 timeVec[total].value = MPI_Wtime();
140 string matrixfile = fileList->get(
"matrix input file",
"A.dat");
141 const char *datafile = matrixfile.c_str();
143 ML_Read_Matrix_Dimensions(datafile, &numGlobalRows,
Comm);
146 timeVec[probBuild].value = MPI_Wtime();
153 if (!mypid) printf(
"reading %s\n",datafile); fflush(stdout);
159 errCode=EpetraExt::MatrixMarketFileToCrsMatrix(datafile,
Comm, Amat);
160 if (errCode) ML_Exit(mypid,
"error reading matrix", EXIT_FAILURE);
168 timeVec[probBuild].value = MPI_Wtime() - timeVec[probBuild].value;
174 timeVec[precBuild].value = MPI_Wtime();
180 timeVec[precBuild].value = MPI_Wtime() - timeVec[precBuild].value;
186 timeVec[solve].value = MPI_Wtime();
188 solver.SetParameters(*AztecOOList);
189 int maxits = AztecOOList->get(
"Aztec iterations",250);
190 double tol = AztecOOList->get(
"Aztec tolerance",1e-10);
192 timeVec[solve].value = MPI_Wtime() - timeVec[solve].value;
197 LHS.Norm2(&residual);
199 if(
Comm.MyPID()==0 ) {
200 cout <<
"||b-Ax||_2 = " << residual << endl;
207 timeVec[total].value = MPI_Wtime() - timeVec[total].value;
210 double dupTime[ntimers],avgTime[ntimers];
211 for (
int i=0; i<ntimers; i++) dupTime[i] = timeVec[i].value;
212 MPI_Reduce(dupTime,avgTime,ntimers,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);
213 for (
int i=0; i<ntimers; i++) avgTime[i] = avgTime[i]/
Comm.NumProc();
215 MPI_Reduce(timeVec,minTime,ntimers,MPI_DOUBLE_INT,MPI_MINLOC,0,MPI_COMM_WORLD);
217 MPI_Reduce(timeVec,maxTime,ntimers,MPI_DOUBLE_INT,MPI_MAXLOC,0,MPI_COMM_WORLD);
219 if (
Comm.MyPID() == 0) {
220 printf(
"timing : max (pid) min (pid) avg\n");
221 printf(
"Problem build : %2.3e (%d) %2.3e (%d) %2.3e \n",
222 maxTime[probBuild].value,maxTime[probBuild].rank,
223 minTime[probBuild].value,minTime[probBuild].rank,
225 printf(
"Preconditioner build : %2.3e (%d) %2.3e (%d) %2.3e \n",
226 maxTime[precBuild].value,maxTime[precBuild].rank,
227 minTime[precBuild].value,minTime[precBuild].rank,
229 printf(
"Solve : %2.3e (%d) %2.3e (%d) %2.3e \n",
230 maxTime[solve].value,maxTime[solve].rank,
231 minTime[solve].value,minTime[solve].rank,
233 printf(
"Total : %2.3e (%d) %2.3e (%d) %2.3e \n",
234 maxTime[total].value,maxTime[total].rank,
235 minTime[total].value,minTime[total].rank,
245 return(EXIT_SUCCESS);
248 void ML_Exit(
int mypid,
const char *msg,
int code)
250 if (!mypid && msg != 0)
260 printf(
"Usage: ml_scaling.exe [XML input file]\n");
261 printf(
" The XML input file must have three sublists:\n");
262 printf(
" 1) \"data files\" -- input file names\n");
263 printf(
" 2) \"AztecOO\" -- outer Krylov options\n");
266 void ML_Read_Matrix_Dimensions(
const char *filename,
int *numGlobalRows,
Epetra_Comm &
Comm)
268 char line[35], token1[35], token2[35], token3[35], token4[35], token5[35];
269 int lineLength = 1025;
270 FILE *fid = fopen(filename,
"r");
272 if(fgets(line, lineLength, fid)==0) {
273 if (fid!=0) fclose(fid);
274 ML_Exit(
Comm.MyPID(),
"error opening matrix file", EXIT_FAILURE);
276 if(sscanf(line,
"%s %s %s %s %s", token1, token2, token3, token4, token5 )==0) {
277 if (fid!=0) fclose(fid);
278 ML_Exit(
Comm.MyPID(),
"error reading matrix file header", EXIT_FAILURE);
280 if (strcmp(token1,
"%%MatrixMarket") || strcmp(token2,
"matrix") ||
281 strcmp(token3,
"coordinate") || strcmp(token4,
"real") ||
282 strcmp(token5,
"general"))
284 if (fid!=0) fclose(fid);
285 ML_Exit(
Comm.MyPID(),
"error reading matrix file header", EXIT_FAILURE);
289 if(fgets(line, lineLength, fid)==0) {
290 if (fid!=0) fclose(fid);
291 ML_Exit(
Comm.MyPID(),
"error reading matrix file comments", EXIT_FAILURE);
293 }
while (line[0] ==
'%');
296 if(sscanf(line,
"%d %d %d", numGlobalRows, &N, &NZ)==0) {
297 if (fid!=0) fclose(fid);
298 ML_Exit(
Comm.MyPID(),
"error reading matrix file dimensions", EXIT_FAILURE);
const Epetra_Map & RowMap() const
Returns the Epetra_Map object associated with the rows of this matrix.
int Random()
Set multi-vector values to random numbers.
int PutScalar(double ScalarConstant)
Initialize all values in a multi-vector with constant value.
Epetra_Vector: A class for constructing and using dense vectors on a parallel computer.
Epetra_MpiComm: The Epetra MPI Communication Class.
Epetra_Comm: The Epetra Communication Abstract Base Class.
int OptimizeStorage()
Make consecutive row index sections contiguous, minimize internal storage used for constructing graph...
Epetra_SerialComm: The Epetra Serial Communication Class.
Epetra_CrsMatrix: A class for constructing and using real-valued double-precision sparse compressed r...
Epetra_LinearProblem: The Epetra Linear Problem Class.
int main(int argc, char **argv)