// ====================================================================== int main(int argc, char *argv[]) { #ifdef HAVE_MPI MPI_Init(&argc,&argv); Epetra_MpiComm Comm( MPI_COMM_WORLD ); #else Epetra_SerialComm Comm; #endif verbose = (Comm.MyPID() == 0); for (int i = 1 ; i < argc ; ++i) { if (strcmp(argv[i],"-s") == 0) { SymmetricGallery = true; Solver = AZ_cg; } } // size of the global matrix. Teuchos::ParameterList GaleriList; int nx = 30; GaleriList.set("nx", nx); GaleriList.set("ny", nx * Comm.NumProc()); GaleriList.set("mx", 1); GaleriList.set("my", Comm.NumProc()); Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Cartesian2D", Comm, GaleriList) ); Teuchos::RefCountPtr<Epetra_CrsMatrix> A; if (SymmetricGallery) A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) ); else A = Teuchos::rcp( Galeri::CreateCrsMatrix("Recirc2D", &*Map, GaleriList) ); // coordinates Teuchos::RCP<Epetra_MultiVector> coord = Teuchos::rcp( Galeri::CreateCartesianCoordinates("2D",&*Map,GaleriList)); // test the preconditioner int TestPassed = true; // ======================================== // // first verify that we can get convergence // // with all point relaxation methods // // ======================================== // if(!BasicTest("Jacobi",A,false)) TestPassed = false; if(!BasicTest("symmetric Gauss-Seidel",A,false)) TestPassed = false; if(!BasicTest("symmetric Gauss-Seidel",A,false,true)) TestPassed = false; if (!SymmetricGallery) { if(!BasicTest("Gauss-Seidel",A,false)) TestPassed = false; if(!BasicTest("Gauss-Seidel",A,true)) TestPassed = false; if(!BasicTest("Gauss-Seidel",A,false,true)) TestPassed = false; if(!BasicTest("Gauss-Seidel",A,true,true)) TestPassed = false; } // ============================= // // check uses as preconditioners // // ============================= // if(!KrylovTest("symmetric Gauss-Seidel",A,false)) TestPassed = false; if(!KrylovTest("symmetric Gauss-Seidel",A,false,true)) TestPassed = false; if (!SymmetricGallery) { if(!KrylovTest("Gauss-Seidel",A,false)) TestPassed = false; if(!KrylovTest("Gauss-Seidel",A,true)) TestPassed = false; if(!KrylovTest("Gauss-Seidel",A,false,true)) TestPassed = false; if(!KrylovTest("Gauss-Seidel",A,true,true)) TestPassed = false; } // ================================== // // compare point and block relaxation // // ================================== // //TestPassed = TestPassed && // ComparePointAndBlock("Jacobi",A,1); TestPassed = TestPassed && ComparePointAndBlock("Jacobi",A,10); //TestPassed = TestPassed && //ComparePointAndBlock("symmetric Gauss-Seidel",A,1); TestPassed = TestPassed && ComparePointAndBlock("symmetric Gauss-Seidel",A,10); if (!SymmetricGallery) { //TestPassed = TestPassed && //ComparePointAndBlock("Gauss-Seidel",A,1); TestPassed = TestPassed && ComparePointAndBlock("Gauss-Seidel",A,10); } // ============================ // // verify effect of # of blocks // // ============================ // { int Iters4, Iters8, Iters16; Iters4 = CompareBlockSizes("Jacobi",A,4); Iters8 = CompareBlockSizes("Jacobi",A,8); Iters16 = CompareBlockSizes("Jacobi",A,16); if ((Iters16 > Iters8) && (Iters8 > Iters4)) { if (verbose) cout << "CompareBlockSizes Test passed" << endl; } else { if (verbose) cout << "CompareBlockSizes TEST FAILED!" << endl; TestPassed = TestPassed && false; } } // ================================== // // verify effect of overlap in Jacobi // // ================================== // { int Iters0, Iters2, Iters4; Iters0 = CompareBlockOverlap(A,0); Iters2 = CompareBlockOverlap(A,2); Iters4 = CompareBlockOverlap(A,4); if ((Iters4 < Iters2) && (Iters2 < Iters0)) { if (verbose) cout << "CompareBlockOverlap Test passed" << endl; } else { if (verbose) cout << "CompareBlockOverlap TEST FAILED!" << endl; TestPassed = TestPassed && false; } } // ================================== // // check if line smoothing works // // ================================== // { int Iters1= CompareLineSmoother(A,coord); printf(" comparelinesmoother iters %d \n",Iters1); } // ================================== // // check if All singleton version of CompareLineSmoother // // ================================== // { AllSingle(A,coord); } // ================================== // // test variable blocking // // ================================== // { TestPassed = TestPassed && TestVariableBlocking(A->Comm()); } // ================================== // // test variable blocking // // ================================== // { TestPassed = TestPassed && TestTriDiVariableBlocking(A->Comm()); } // ============ // // final output // // ============ // if (!TestPassed) { cout << "Test `TestRelaxation.exe' failed!" << endl; exit(EXIT_FAILURE); } #ifdef HAVE_MPI MPI_Finalize(); #endif cout << endl; cout << "Test `TestRelaxation.exe' passed!" << endl; cout << endl; return(EXIT_SUCCESS); }
// ====================================================================== int main(int argc, char *argv[]) { #ifdef HAVE_MPI MPI_Init(&argc,&argv); Epetra_MpiComm Comm( MPI_COMM_WORLD ); #else Epetra_SerialComm Comm; #endif verbose = (Comm.MyPID() == 0); int nx = 60; for (int i = 1 ; i < argc ; ++i) { if (strcmp(argv[i],"-s") == 0) { SymmetricGallery = true; Solver = AZ_cg; } if(strcmp(argv[i],"-n") == 0 && i+1 < argc) { i++; nx = atoi(argv[i]); } } // size of the global matrix. Teuchos::ParameterList GaleriList; GaleriList.set("nx", nx); GaleriList.set("ny", nx * Comm.NumProc()); GaleriList.set("mx", 1); GaleriList.set("my", Comm.NumProc()); Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Cartesian2D", Comm, GaleriList) ); Teuchos::RefCountPtr<Epetra_CrsMatrix> A; if (SymmetricGallery) A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) ); else A = Teuchos::rcp( Galeri::CreateCrsMatrix("Recirc2D", &*Map, GaleriList) ); // coordinates Teuchos::RCP<Epetra_MultiVector> coord = Teuchos::rcp( Galeri::CreateCartesianCoordinates("2D",&*Map,GaleriList)); // test the preconditioner int TestPassed = true; int who = RUSAGE_SELF; struct rusage usage; //int ret; //ret = getrusage(who, &usage); struct timeval ru_utime; // struct timeval ru_stime; ru_utime = usage.ru_utime; // ================================== // // compare point and block relaxation // // ================================== // TestPassed = TestPassed && ComparePointAndBlock("Jacobi",A,10); if(verbose) printf(" Jacobi Finished \n"); //ret = getrusage(who, &usage); int sec = usage.ru_utime.tv_sec -ru_utime.tv_sec; int usec = usage.ru_utime.tv_usec -ru_utime.tv_usec; double tt = (double)sec + 1e-6*(double)usec; ru_utime = usage.ru_utime; if(verbose) printf(" Jacobi time %f \n",tt); TestPassed = TestPassed && ComparePointAndBlock("symmetric Gauss-Seidel",A,10); if(verbose) printf(" sGS finished \n"); //ret = getrusage(who, &usage); sec = usage.ru_utime.tv_sec -ru_utime.tv_sec; usec = usage.ru_utime.tv_usec -ru_utime.tv_usec; tt = (double)sec + 1e-6*(double)usec; ru_utime = usage.ru_utime; if(verbose) printf(" sGS time %f \n",tt); if (!SymmetricGallery) { TestPassed = TestPassed && ComparePointAndBlock("Gauss-Seidel",A,10); //ret = getrusage(who, &usage); sec = usage.ru_utime.tv_sec -ru_utime.tv_sec; usec = usage.ru_utime.tv_usec -ru_utime.tv_usec; tt = (double)sec + 1e-6*(double)usec; ru_utime = usage.ru_utime; if(verbose) printf(" GS time %f \n",tt); if(verbose) printf(" GS Finished \n"); } if (!TestPassed) { cout << "Test `Performance.exe' failed!" << endl; exit(EXIT_FAILURE); } #ifdef HAVE_MPI MPI_Finalize(); #endif cout << endl; cout << "Test `Performance.exe' passed!" << endl; cout << endl; return(EXIT_SUCCESS); }