Actual source code: ex13.cxx

petsc-3.6.1 2015-08-06
Report Typos and Errors
  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: {
 30:   // These "using" declarations make the code more concise, in that
 31:   // you don't have to write the namespace along with the class or
 32:   // object name.  This is especially helpful with commonly used
 33:   // things like std::endl or Teuchos::RCP.
 34:   using std::cout;
 35:   using std::endl;
 36:   using Teuchos::Comm;
 37:   using Teuchos::MpiComm;
 38:   using Teuchos::RCP;
 39:   using Teuchos::rcp;

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

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