1*c4762a1bSJed Brown 2*c4762a1bSJed Brown static char help[] = "Demonstrates call PETSc first and then Trilinos in the same program.\n\n"; 3*c4762a1bSJed Brown 4*c4762a1bSJed Brown /*T 5*c4762a1bSJed Brown Concepts: introduction to PETSc^Trilinos 6*c4762a1bSJed Brown Processors: n 7*c4762a1bSJed Brown 8*c4762a1bSJed Brown Example obtained from: http://trilinos.org/docs/dev/packages/tpetra/doc/html/Tpetra_Lesson01.html 9*c4762a1bSJed Brown T*/ 10*c4762a1bSJed Brown 11*c4762a1bSJed Brown 12*c4762a1bSJed Brown 13*c4762a1bSJed Brown #include <petscsys.h> 14*c4762a1bSJed Brown #include <Teuchos_DefaultMpiComm.hpp> // wrapper for MPI_Comm 15*c4762a1bSJed Brown #include <Tpetra_Version.hpp> // Tpetra version string 16*c4762a1bSJed Brown 17*c4762a1bSJed Brown // Do something with the given communicator. In this case, we just 18*c4762a1bSJed Brown // print Tpetra's version to stdout on Process 0 in the given 19*c4762a1bSJed Brown // communicator. 20*c4762a1bSJed Brown void 21*c4762a1bSJed Brown exampleRoutine (const Teuchos::RCP<const Teuchos::Comm<int> >& comm) 22*c4762a1bSJed Brown { 23*c4762a1bSJed Brown if (comm->getRank () == 0) { 24*c4762a1bSJed Brown // On (MPI) Process 0, print out the Tpetra software version. 25*c4762a1bSJed Brown std::cout << Tpetra::version () << std::endl << std::endl; 26*c4762a1bSJed Brown } 27*c4762a1bSJed Brown } 28*c4762a1bSJed Brown 29*c4762a1bSJed Brown int main(int argc,char **argv) 30*c4762a1bSJed Brown { 31*c4762a1bSJed Brown PetscErrorCode ierr; 32*c4762a1bSJed Brown // These "using" declarations make the code more concise, in that 33*c4762a1bSJed Brown // you don't have to write the namespace along with the class or 34*c4762a1bSJed Brown // object name. This is especially helpful with commonly used 35*c4762a1bSJed Brown // things like std::endl or Teuchos::RCP. 36*c4762a1bSJed Brown using std::cout; 37*c4762a1bSJed Brown using std::endl; 38*c4762a1bSJed Brown using Teuchos::Comm; 39*c4762a1bSJed Brown using Teuchos::MpiComm; 40*c4762a1bSJed Brown using Teuchos::RCP; 41*c4762a1bSJed Brown using Teuchos::rcp; 42*c4762a1bSJed Brown 43*c4762a1bSJed Brown /* 44*c4762a1bSJed Brown Every PETSc routine should begin with the PetscInitialize() routine. 45*c4762a1bSJed Brown argc, argv - These command line arguments are taken to extract the options 46*c4762a1bSJed Brown supplied to PETSc and options supplied to MPI. 47*c4762a1bSJed Brown help - When PETSc executable is invoked with the option -help, 48*c4762a1bSJed Brown it prints the various options that can be applied at 49*c4762a1bSJed Brown runtime. The user can use the "help" variable place 50*c4762a1bSJed Brown additional help messages in this printout. 51*c4762a1bSJed Brown */ 52*c4762a1bSJed Brown ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; 53*c4762a1bSJed Brown RCP<const Comm<int> > comm (new MpiComm<int> (PETSC_COMM_WORLD)); 54*c4762a1bSJed Brown // Get my process' rank, and the total number of processes. 55*c4762a1bSJed Brown // Equivalent to MPI_Comm_rank resp. MPI_Comm_size. 56*c4762a1bSJed Brown const int myRank = comm->getRank (); 57*c4762a1bSJed Brown const int size = comm->getSize (); 58*c4762a1bSJed Brown if (myRank == 0) { 59*c4762a1bSJed Brown cout << "Total number of processes: " << size << endl; 60*c4762a1bSJed Brown } 61*c4762a1bSJed Brown // Do something with the new communicator. 62*c4762a1bSJed Brown exampleRoutine (comm); 63*c4762a1bSJed Brown // This tells the Trilinos test framework that the test passed. 64*c4762a1bSJed Brown if (myRank == 0) { 65*c4762a1bSJed Brown cout << "End Result: TEST PASSED" << endl; 66*c4762a1bSJed Brown } 67*c4762a1bSJed Brown 68*c4762a1bSJed Brown ierr = PetscFinalize(); 69*c4762a1bSJed Brown return ierr; 70*c4762a1bSJed Brown } 71*c4762a1bSJed Brown 72*c4762a1bSJed Brown 73*c4762a1bSJed Brown /*TEST 74*c4762a1bSJed Brown 75*c4762a1bSJed Brown build: 76*c4762a1bSJed Brown requires: trilinos 77*c4762a1bSJed Brown 78*c4762a1bSJed Brown test: 79*c4762a1bSJed Brown nsize: 3 80*c4762a1bSJed Brown filter: grep -v "Tpetra in Trilinos" 81*c4762a1bSJed Brown 82*c4762a1bSJed Brown TEST*/ 83