11#include "Teuchos_Assert.hpp" 
   20#ifdef HAVE_TEUCHOSCORE_KOKKOS 
   21#  include "Kokkos_Core.hpp" 
   29bool GlobalMPISession::haveMPIState_ = 
false;
 
   30bool GlobalMPISession::mpiIsFinalized_ = 
false;
 
   31int GlobalMPISession::rank_ = 0 ;
 
   32int GlobalMPISession::nProc_ = 1 ;
 
   34#ifdef HAVE_TEUCHOSCORE_KOKKOS 
   38std::vector<std::string> GlobalMPISession::argvCopy_;
 
   45  std::ostringstream 
oss;
 
   59      *out << 
"GlobalMPISession(): Error, MPI_Intialized() return true," 
   60           << 
" calling std::terminate()!\n" 
   70      *out << 
"GlobalMPISession(): Error, MPI_Init() returned error code=" 
   71           << 
mpierr << 
"!=0, calling std::terminate()!\n" 
   84      *out << 
"GlobalMPISession():  Error, MPI_Get_processor_name() error code=" 
   85           << 
mpierr << 
"!=0, calling std::terminate()!\n" 
   91  oss << 
"Teuchos::GlobalMPISession::GlobalMPISession(): started processor with name " 
   92      << 
procName << 
" and rank " << rank_ << 
"!" << std::endl;
 
   96  oss << 
"Teuchos::GlobalMPISession::GlobalMPISession(): started serial run" 
  101#ifndef TEUCHOS_SUPPRESS_PROC_STARTUP_BANNER 
  105  const std::string 
suppress_option(
"--teuchos-suppress-startup-banner");
 
  113        (*
argv)[
i] = (*argv)[
i+1];
 
  118    *out << 
oss.str() << std::flush;
 
  123#ifdef HAVE_TEUCHOSCORE_KOKKOS 
 
  147#ifdef HAVE_TEUCHOSCORE_KOKKOS   
  148std::vector<std::string> GlobalMPISession::getArgv ()
 
  158#ifdef HAVE_TEUCHOSCORE_KOKKOS 
  160    if (Kokkos::is_initialized())
 
  163  catch (
const std::runtime_error& 
e) {
 
  164    std::cerr << 
"Kokkos::finalize failed:\n" 
  169  haveMPIState_ = 
false;
 
  171  const int mpierr = ::MPI_Finalize();
 
  172  mpiIsFinalized_ = (
mpierr == 0);
 
  174    std::cerr << 
"Error code " << 
mpierr << 
" returned from MPI_Finalize()\n";
 
  176  mpiIsFinalized_ = 
true;
 
 
  181  justInTimeInitialize();
 
 
  190  justInTimeInitialize();
 
  191  return haveMPIState_;
 
 
  197  return mpiIsFinalized_;
 
 
  203  justInTimeInitialize();
 
 
  209  justInTimeInitialize();
 
 
  216  justInTimeInitialize();
 
 
  225  justInTimeInitialize();
 
 
  238  justInTimeInitialize();
 
 
  252void GlobalMPISession::initialize( std::ostream *out )
 
  256  if(mpiIsFinalized_) {
 
  271  int mpiHasBeenStarted = 0;
 
  272  MPI_Initialized(&mpiHasBeenStarted);
 
  274  if(!mpiHasBeenStarted)
 
  282  mpierr = ::MPI_Comm_rank( MPI_COMM_WORLD, &rank_ );
 
  284    *out << 
"Error code=" << mpierr << 
" detected in MPI_Comm_rank()" 
  288  mpierr = ::MPI_Comm_size( MPI_COMM_WORLD, &nProc_ );
 
  290    *out << 
"Error code=" << mpierr << 
" detected in MPI_Comm_size()" 
  294  haveMPIState_ = 
true;
 
  295  mpiIsFinalized_ = 
false;
 
  302void GlobalMPISession::justInTimeInitialize()
 
  305    initialize(&std::cerr);
 
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
 
static int sum(int localVal)
Sum a set of integers across processes.
 
static void abort()
abort the program
 
static void barrier()
Call MPI_Barrier() on MPI_COMM_WORLD.
 
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
 
GlobalMPISession(int *argc, char ***argv, std::ostream *out=&std::cout)
Calls MPI_Init() if MPI is enabled.
 
static int getNProc()
The number of processes in MPI_COMM_WORLD.
 
static bool mpiIsInitialized()
Return whether MPI was initialized.
 
static bool mpiIsFinalized()
Return whether MPI was already finalized.
 
static void allGather(int localVal, const ArrayView< int > &allVals)
Global all-to-all of a set of integers across processes.
 
~GlobalMPISession()
Call MPI_Finalize() if MPI is enabled.
 
Smart reference counting pointer class for automatic garbage collection.
 
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
 
#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 ...
 
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...