62 std::ostringstream oss;
69 int mpiHasBeenStarted = 0, mpierr = 0;
70 MPI_Initialized(&mpiHasBeenStarted);
72 mpiHasBeenStarted, std::runtime_error
73 ,
"Error, you can only call this constructor once!" 77 mpierr = ::MPI_Init (argc, (
char ***) argv);
79 mpierr != 0, std::runtime_error
80 ,
"Error code=" << mpierr <<
" detected in GlobalMPISession::GlobalMPISession(argc,argv)" 87 char procName[MPI_MAX_PROCESSOR_NAME];
88 mpierr = ::MPI_Get_processor_name(procName,&nameLen);
90 mpierr != 0, std::runtime_error
91 ,
"Error code=" << mpierr <<
" detected in MPI_Get_processor_name()" 95 oss <<
"Teuchos::GlobalMPISession::GlobalMPISession(): started processor with name " 96 << procName <<
" and rank " <<
rank_ <<
"!" << std::endl;
99 oss <<
"Teuchos::GlobalMPISession::GlobalMPISession(): started serial run" << std::endl;
101 #ifndef TEUCHOS_SUPPRESS_PROC_STARTUP_BANNER 103 bool printStartupBanner =
true;
104 const std::string suppress_option(
"--teuchos-suppress-startup-banner");
105 for(
int opt_i = 0; opt_i < *argc; ++opt_i ) {
106 if( suppress_option == (*argv)[opt_i] ) {
108 printStartupBanner =
false;
111 for(
int i = opt_i; i < *argc; ++i )
112 (*argv)[i] = (*argv)[i+1];
116 if( out && printStartupBanner )
117 *out << oss.str() << std::flush;
126 int mpierr = ::MPI_Finalize();
128 mpierr != 0, std::runtime_error
129 ,
"Error code=" << mpierr <<
" detected in MPI_Finalize()" 165 MPI_Barrier(MPI_COMM_WORLD);
175 MPI_Allreduce(&localVal, &globalSum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
188 MPI_Allgather( &localVal, 1, MPI_INT, allVals.
getRawPtr(), 1, MPI_INT,
191 allVals[0] = localVal;
217 int mpiHasBeenStarted = 0, mpierr = 0;
218 MPI_Initialized(&mpiHasBeenStarted);
220 if(!mpiHasBeenStarted)
225 mpierr = ::MPI_Comm_rank( MPI_COMM_WORLD, &
rank_ );
227 mpierr != 0, std::runtime_error
228 ,
"Error code=" << mpierr <<
" detected in MPI_Comm_rank()" 232 mpierr = ::MPI_Comm_size( MPI_COMM_WORLD, &
nProc_ );
234 mpierr != 0, std::runtime_error
235 ,
"Error code=" << mpierr <<
" detected in MPI_Comm_size()" static int getRank()
Returns the process rank relative to MPI_COMM_WORLD
static int getNProc()
Returns the number of processors relative to MPI_COMM_WORLD
size_type size() const
The total number of items in the managed array.
static bool mpiIsFinalized_
static bool mpiIsFinalized()
Return whether MPI was already finalized.
GlobalMPISession(int *argc, char ***argv, std::ostream *out=&std::cout)
Calls MPI_Init() if MPI is enabled.
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
static int sum(int localVal)
Sum a set of integers across processes.
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
static void barrier()
Perform a barrier so that all processes line up.
static void justInTimeInitialize()
static bool mpiIsInitialized()
Return whether MPI was initialized.
#define TEUCHOS_TEST_FOR_EXCEPTION_PRINT(throw_exception_test, Exception, msg, out_ptr)
This macro is the same as TEUCHOS_TEST_FOR_EXCEPTION() except that the exception will be caught...
static void allGather(int localVal, const ArrayView< int > &allVals)
Global all-to-all of a set of integers across processes.
static bool haveMPIState_
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
This macro is checks that to numbers are equal and if not then throws an exception with a good error ...
static void initialize(std::ostream *out)
~GlobalMPISession()
Call MPI_Finalize() if MPI is enabled.