Actual source code: ex45.cxx


  2: static char help[] = "Demonstrates call PETSc first and then Trilinos in the same program.\n\n";

  4: /*
  5:    Example obtained from: http://trilinos.org/docs/dev/packages/tpetra/doc/html/Tpetra_Lesson01.html
  6: */

  8: #include <petscsys.h>
  9: #include <Teuchos_DefaultMpiComm.hpp> // wrapper for MPI_Comm
 10: #include <Tpetra_Version.hpp> // Tpetra version string

 12: // Do something with the given communicator.  In this case, we just
 13: // print Tpetra's version to stdout on Process 0 in the given
 14: // communicator.
 15: void
 16: exampleRoutine (const Teuchos::RCP<const Teuchos::Comm<int> >& comm)
 17: {
 18:   if (comm->getRank () == 0) {
 19:     // On (MPI) Process 0, print out the Tpetra software version.
 20:     std::cout << Tpetra::version () << std::endl << std::endl;
 21:   }
 22: }

 24: int main(int argc,char **argv)
 25: {
 26:   // These "using" declarations make the code more concise, in that
 27:   // you don't have to write the namespace along with the class or
 28:   // object name.  This is especially helpful with commonly used
 29:   // things like std::endl or Teuchos::RCP.
 30:   using std::cout;
 31:   using std::endl;
 32:   using Teuchos::Comm;
 33:   using Teuchos::MpiComm;
 34:   using Teuchos::RCP;
 35:   using Teuchos::rcp;

 37:   /*
 38:     Every PETSc routine should begin with the PetscInitialize() routine.
 39:     argc, argv - These command line arguments are taken to extract the options
 40:                  supplied to PETSc and options supplied to MPI.
 41:     help       - When PETSc executable is invoked with the option -help,
 42:                  it prints the various options that can be applied at
 43:                  runtime.  The user can use the "help" variable place
 44:                  additional help messages in this printout.
 45:   */
 46:   PetscInitialize(&argc,&argv,(char*)0,help);
 47:   RCP<const Comm<int> > comm (new MpiComm<int> (PETSC_COMM_WORLD));
 48:   // Get my process' rank, and the total number of processes.
 49:   // Equivalent to MPI_Comm_rank resp. MPI_Comm_size.
 50:   const int myRank = comm->getRank ();
 51:   const int size = comm->getSize ();
 52:   if (myRank == 0) {
 53:     cout << "Total number of processes: " << size << endl;
 54:   }
 55:   // Do something with the new communicator.
 56:   exampleRoutine (comm);
 57:   // This tells the Trilinos test framework that the test passed.
 58:   if (myRank == 0) {
 59:     cout << "End Result: TEST PASSED" << endl;
 60:   }

 62:   PetscFinalize();
 63:   return 0;
 64: }

 66: /*TEST

 68:    build:
 69:      requires: trilinos

 71:    test:
 72:       nsize: 3
 73:       filter: grep -v "Tpetra in Trilinos"

 75: TEST*/