#include "ml_include.h"
#if defined(HAVE_ML_EPETRA) && defined(HAVE_ML_TEUCHOS) && defined(HAVE_ML_GALERI) && defined(HAVE_ML_AZTECOO)
#ifdef HAVE_MPI
#include "mpi.h"
#include "Epetra_MpiComm.h"
#else
#include "Epetra_SerialComm.h"
#endif
#include "Epetra_Map.h"
#include "Epetra_Vector.h"
#include "Epetra_CrsMatrix.h"
#include "Epetra_LinearProblem.h"
#include "Galeri_Maps.h"
#include "Galeri_CrsMatrices.h"
#include "AztecOO.h"
using namespace Teuchos;
using namespace Galeri;
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
#else
#endif
#ifdef ML_SCALING
const int ntimers=4;
enum {total, probBuild, precBuild, solve};
ml_DblLoc timeVec[ntimers], maxTime[ntimers], minTime[ntimers];
for (
int i=0; i<ntimers; i++) timeVec[i].rank = Comm.
MyPID();
timeVec[total].value = MPI_Wtime();
#endif
int nx;
if (argc > 1)
nx = (int) strtol(argv[1],NULL,10);
else
nx = 256;
GaleriList.
set(
"nx", nx);
GaleriList.
set(
"ny", ny);
#ifdef ML_SCALING
timeVec[probBuild].value = MPI_Wtime();
#endif
Epetra_Map* Map = CreateMap(
"Cartesian2D", Comm, GaleriList);
AztecOO solver(Problem);
#ifdef ML_SCALING
timeVec[probBuild].value = MPI_Wtime() - timeVec[probBuild].value;
#endif
#ifdef ML_SCALING
timeVec[precBuild].value = MPI_Wtime();
#endif
MLList.
set(
"ML output", 10);
MLList.
set(
"max levels",5);
MLList.
set(
"increasing or decreasing",
"increasing");
MLList.
set(
"aggregation: type",
"Uncoupled");
MLList.
set(
"smoother: type",
"Chebyshev");
MLList.
set(
"smoother: sweeps",3);
MLList.
set(
"smoother: pre or post",
"both");
#ifdef HAVE_ML_AMESOS
MLList.
set(
"coarse: type",
"Amesos-KLU");
#else
MLList.
set(
"coarse: type",
"Jacobi");
#endif
#ifdef ML_SCALING
timeVec[precBuild].value = MPI_Wtime() - timeVec[precBuild].value;
#endif
#ifdef ML_SCALING
timeVec[solve].value = MPI_Wtime();
#endif
solver.SetPrecOperator(MLPrec);
solver.SetAztecOption(AZ_solver, AZ_cg);
solver.SetAztecOption(AZ_output, 32);
solver.Iterate(500, 1e-12);
#ifdef ML_SCALING
timeVec[solve].value = MPI_Wtime() - timeVec[solve].value;
#endif
delete MLPrec;
double residual;
LHS.Norm2(&residual);
cout << "||b-Ax||_2 = " << residual << endl;
}
if (residual > 1e-5)
exit(EXIT_FAILURE);
delete A;
delete Map;
#ifdef ML_SCALING
timeVec[total].value = MPI_Wtime() - timeVec[total].value;
double dupTime[ntimers],avgTime[ntimers];
for (int i=0; i<ntimers; i++) dupTime[i] = timeVec[i].value;
MPI_Reduce(dupTime,avgTime,ntimers,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);
for (
int i=0; i<ntimers; i++) avgTime[i] = avgTime[i]/Comm.
NumProc();
MPI_Reduce(timeVec,minTime,ntimers,MPI_DOUBLE_INT,MPI_MINLOC,0,MPI_COMM_WORLD);
MPI_Reduce(timeVec,maxTime,ntimers,MPI_DOUBLE_INT,MPI_MAXLOC,0,MPI_COMM_WORLD);
printf("timing : max (pid) min (pid) avg\n");
printf("Problem build : %2.3e (%d) %2.3e (%d) %2.3e \n",
maxTime[probBuild].value,maxTime[probBuild].rank,
minTime[probBuild].value,minTime[probBuild].rank,
avgTime[probBuild]);
printf("Preconditioner build : %2.3e (%d) %2.3e (%d) %2.3e \n",
maxTime[precBuild].value,maxTime[precBuild].rank,
minTime[precBuild].value,minTime[precBuild].rank,
avgTime[precBuild]);
printf("Solve : %2.3e (%d) %2.3e (%d) %2.3e \n",
maxTime[solve].value,maxTime[solve].rank,
minTime[solve].value,minTime[solve].rank,
avgTime[solve]);
printf("Total : %2.3e (%d) %2.3e (%d) %2.3e \n",
maxTime[total].value,maxTime[total].rank,
minTime[total].value,minTime[total].rank,
avgTime[total]);
}
#endif
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return(EXIT_SUCCESS);
}
#else
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_MPI
#include "mpi.h"
#endif
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
#endif
puts("Please configure ML with:");
puts("--enable-epetra");
puts("--enable-teuchos");
puts("--enable-aztecoo");
puts("--enable-galeri");
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return(EXIT_SUCCESS);
}
#endif