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