63 friend GISMO_EXPORT gsMpi &
gsMpiSingleton(
const int& argc,
char** argv);
65 # ifdef GISMO_WITH_MPI
69 typedef MPI_Comm Communicator;
71 typedef gsSerialComm Communicator;
80 static Communicator worldComm()
82 # ifdef GISMO_WITH_MPI
83 return MPI_COMM_WORLD;
95 static Communicator localComm()
97 return gsSerialComm();
115 static gsMpi& init(
const int& argc = 0,
char** argv = NULL)
117 GISMO_ASSERT( 0 == argc || NULL!=argv,
"Need both argc and argv (or none)");
124 static int worldRank () {
return gsMpiComm(worldComm()).
rank(); }
128 static int worldSize () {
return gsMpiComm(worldComm()).
size(); }
130 static inline double wallTime()
132 # ifdef GISMO_WITH_MPI
139 static inline std::string getProcessorName()
141 # ifdef GISMO_WITH_MPI
142 char processor_name[MPI_MAX_PROCESSOR_NAME];
144 MPI_Get_processor_name(processor_name, &name_len);
145 return std::string(processor_name, name_len);
154 bool initialized()
const
156 # ifdef GISMO_WITH_MPI
158 MPI_Initialized( &init );
169 gsMpi(
const int& argc,
char** argv)
171 initMpi(const_cast<int*>(&argc), argv);
174 void initMpi(
int * argc = NULL,
char** argv = NULL)
const
176 # ifdef GISMO_WITH_MPI
181 char* thread_level = getenv(
"GISMO_MPI_THREAD_LEVEL");
182 const int req_level = ( NULL != thread_level ? atoi(getenv(
"GISMO_MPI_THREAD_LEVEL")) : 0);
183 int MPI_thread_required = MPI_THREAD_SINGLE, MPI_thread_provided;
187 MPI_thread_required = MPI_THREAD_SINGLE;
190 MPI_thread_required = MPI_THREAD_FUNNELED;
193 MPI_thread_required = MPI_THREAD_SERIALIZED;
196 MPI_thread_required = MPI_THREAD_MULTIPLE;
199 GISMO_ERROR(
"Invalid value for environment variable GISMO_MPI_THREAD_LEVEL");
202 const int init = MPI_Init_thread(argc, &argv, MPI_thread_required, &MPI_thread_provided);
204 MPI_thread_required <= MPI_thread_provided,
"MPI failed to initialize");
208 const int init = MPI_Init(argc, &argv);
209 GISMO_ENSURE(MPI_SUCCESS==init,
"MPI failed to initialize");
213 MPI_Comm_create_errhandler(gsMpiComm::ErrCallBack, &gsMpiComm::ErrHandler);
214 MPI_Comm_set_errhandler(worldComm(), gsMpiComm::ErrHandler);
226 # ifdef GISMO_WITH_MPI
227 int wasFinalized = -1;
228 MPI_Finalized( &wasFinalized );
229 if( 0 == wasFinalized)
238 gsMpi& operator=(
const gsMpi&);
int rank() const
return rank of process, i.e. zero
Definition: gsMpiComm.h:297
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Various helper classes derived from from std::binary_function for stl-style functional programming...
~gsMpi()
calls MPI_Finalize
Definition: gsMpi.h:224
A wrapper for MPI communicators.
gsMpi & gsMpiSingleton(const int &argc, char **argv)
Singleton function returning the gsMpi helper object.
Definition: gsMpi.cpp:9
Provides forward declarations of types and structs.
static int size()
return rank of process, i.e. one
Definition: gsMpiComm.h:302
Traits classes for mapping types onto MPI_Datatype.
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
#define GISMO_ERROR(message)
Definition: gsDebug.h:118