|
Tpetra Matrix/Vector Services
Version of the Day
|
00001 00008 // ... Your other include files go here ... 00009 #include <Tpetra_DefaultPlatform.hpp> 00010 #include <Teuchos_DefaultSerialComm.hpp> 00011 #include <Tpetra_Version.hpp> 00012 #include <Teuchos_oblackholestream.hpp> 00013 00014 // Do something with the given communicator. In this case, we just 00015 // print Tpetra's version to stdout on Process 0. 00016 void 00017 exampleRoutine (const Teuchos::RCP<const Teuchos::Comm<int> >& comm) 00018 { 00019 if (comm->getRank () == 0) { 00020 // On Process 0, print out the Tpetra software version. 00021 std::cout << Tpetra::version () << std::endl << std::endl; 00022 } 00023 } 00024 00025 int 00026 main (int argc, char *argv[]) 00027 { 00028 using std::cout; 00029 using std::endl; 00030 using Teuchos::Comm; 00031 using Teuchos::SerialComm; 00032 using Teuchos::RCP; 00033 using Teuchos::rcp; 00034 00035 // Make a "serial" (non-MPI) communicator. 00036 // It doesn't actually "communicate," because it only has one process. 00037 RCP<const Comm<int> > comm = rcp (new SerialComm<int> ()); 00038 00039 // With a "serial" communicator, the rank is always 0, 00040 // and the number of processes is always 1. 00041 const int myRank = comm->getRank(); 00042 const int numProcs = comm->getSize(); 00043 00044 if (myRank == 0) { 00045 cout << "Total number of processes: " << numProcs << endl; 00046 } 00047 00048 // Test the two assertions in the previous comment. 00049 // TEUCHOS_TEST_FOR_EXCEPTION is a macro defined in the Teuchos 00050 // package that takes three arguments: a bool expression, an 00051 // exception to throw if the expression evaluates to true, and a 00052 // message (interpreted as if it follows a "<<" after an 00053 // std::ostream) to include in the exception. The macro includes 00054 // useful line number and file information in the exception message, 00055 // as well as a place where you can set a breakpoint in a debugger 00056 // right before the exception is thrown. 00057 00058 TEUCHOS_TEST_FOR_EXCEPTION( 00059 myRank != 0, std::logic_error, 00060 "This is a serial (non-MPI) example, but the rank of the calling process " 00061 "the Teuchos::Comm is " << myRank << " != 0. Please report this bug."); 00062 00063 TEUCHOS_TEST_FOR_EXCEPTION( 00064 numProcs != 1, std::logic_error, 00065 "This is a serial (non-MPI) example, but the number of processes in " 00066 "the Teuchos::Comm is " << numProcs << " != 1. Please report this bug."); 00067 00068 // Do something with the new communicator. 00069 exampleRoutine (comm); 00070 00071 // This tells the Trilinos test framework that the test passed. 00072 if (myRank == 0) { 00073 cout << "End Result: TEST PASSED" << endl; 00074 } 00075 00076 return 0; 00077 }
1.7.6.1