Actual source code: ex45.cxx


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

  4: /*T
  5:    Concepts: introduction to PETSc^Trilinos
  6:    Processors: n

  8:    Example obtained from: http://trilinos.org/docs/dev/packages/tpetra/doc/html/Tpetra_Lesson01.html
  9: T*/

 11: #include <petscsys.h>
 12: #include <Teuchos_DefaultMpiComm.hpp> // wrapper for MPI_Comm
 13: #include <Tpetra_Version.hpp> // Tpetra version string

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

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

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

 65:   PetscFinalize();
 66:   return 0;
 67: }

 69: /*TEST

 71:    build:
 72:      requires: trilinos

 74:    test:
 75:       nsize: 3
 76:       filter: grep -v "Tpetra in Trilinos"

 78: TEST*/