1 #ifndef MPI_Environment_H
2 #define MPI_Environment_H
5 #include "MPI_Object.h"
44 tMPICoreId mCoresNumber;
49 tBoolean mIsRootEnvironment;
73 if (isOpenMPEnabled) {
74 int provided, required=MPI_THREAD_FUNNELED;
75 MPI_Init_thread(&argc,&argv,required,&provided);
77 MPI_Init(&argc,&argv);
79 mWorld=MPI_COMM_WORLD;
80 mIsRootEnvironment=
false;
88 if (mWorld==MPI_COMM_WORLD) {
90 }
else if (mWorld!=MPI_COMM_NULL) {
91 MPI_Comm_free(&mWorld);
92 if (mIsRootEnvironment) {
104 MPI_Comm_size(mWorld,&mCoresNumber);
105 MPI_Comm_rank(mWorld,&mCoreId);
116 inline static CORE_UniquePointer<MPI_Environment>
New(
int argc,
char *argv[],
const tBoolean& isOpenMPEnabled) {
117 CORE_UniquePointer<MPI_Environment> p(
new MPI_Environment(argc,argv,isOpenMPEnabled),
127 inline static CORE_UniquePointer<MPI_Environment>
New(
int argc,
char *argv[]) {
128 return New(argc,argv,
false);
157 mIsRootEnvironment=isRoot;
187 MPI_Comm_size(MPI_COMM_WORLD,&coresNumber);
194 MPI_Comm_size(env.
getWorld(),&coresNumber);
211 MPI_Comm_rank(MPI_COMM_WORLD,&
id);
241 return MPI_Abort(env.
getWorld(),errCode);
247 inline static tMPIError
Abort(
const tMPIError& errCode) {
248 return MPI_Abort(MPI_COMM_WORLD,errCode);
255 inline tMPIError
abort(
const tMPIError& errCode)
const {
256 return MPI_Abort(mWorld,errCode);
267 return (MPI_Barrier(env.
getWorld())==MPI_SUCCESS);
274 return (MPI_Barrier(MPI_COMM_WORLD)==MPI_SUCCESS);
282 return (MPI_Barrier(
getWorld())==MPI_SUCCESS);
293 inline static tBoolean
Wait(tMPIRequest& request,tMPIStatus& status) {
294 return (MPI_Wait(&request,&status)==MPI_SUCCESS);
299 static inline tBoolean
Wait(tMPIRequest& request) {
300 return (MPI_Wait(&request,MPI_STATUS_IGNORE)==MPI_SUCCESS);
308 inline static tBoolean
WaitAll(
const tMPICount& nRequests,tMPIRequest requests[],tMPIStatus statuses[]) {
309 return (MPI_Waitall(nRequests,requests,statuses)==MPI_SUCCESS);
316 static inline tBoolean
WaitAll(std::valarray<tMPIRequest>& requests) {
317 return (MPI_Waitall(requests.size(),
319 MPI_STATUSES_IGNORE)==MPI_SUCCESS);
327 static inline tBoolean
WaitAll(std::array<tMPIRequest,D>& requests) {
328 return (MPI_Waitall(D,
330 MPI_STATUSES_IGNORE)==MPI_SUCCESS);
337 static inline tBoolean
WaitAll(
const tMPICount& nRequests,tMPIRequest* requests) {
338 return (MPI_Waitall(nRequests,
340 MPI_STATUSES_IGNORE)==MPI_SUCCESS);
351 static inline tBoolean
IsFinished(tMPIRequest& request,tMPIInteger& isFinished) {
352 MPI_Test(&request,&isFinished,MPI_STATUS_IGNORE);
353 return (isFinished==1);
360 static inline tBoolean
IsAllFinished(std::valarray<tMPIRequest>& requests,tMPIInteger& isFinished) {
361 tBoolean isAllFinished=
true;
362 for(
auto& req:requests) {
363 MPI_Test(&req,&isFinished,MPI_STATUS_IGNORE);
364 isAllFinished=isAllFinished && (isFinished==1);
366 return isAllFinished;
374 inline static tBoolean
IsFinished(tMPIRequest& request,tMPIStatus& status,tMPIInteger& isFinished) {
375 MPI_Test(&request,&isFinished,&status);
376 return (isFinished==1);
388 tMPIBoolean& isAvailable,
389 tMPIStatus& status)
const {
404 tMPIBoolean& isAvailable,
405 tMPIStatus& status) {
407 MPI_Iprobe(MPI_ANY_SOURCE,MPI_ANY_TAG,env.
getWorld(),&isAvailable,&status);
408 if (isAvailable==1) {
409 source=status.MPI_SOURCE;
424 const tMPICoreId& source,
425 tMPIBoolean& isAvailable) {
426 return (MPI_Iprobe(source,tag,env.
getWorld(),&isAvailable,MPI_STATUS_IGNORE)==MPI_SUCCESS);
440 tMPIBoolean& isAvailable,
441 tMPIStatus& status) {
442 MPI_Iprobe(MPI_ANY_SOURCE,tag,env.
getWorld(),&isAvailable,&status);
443 if (isAvailable==1) {
444 source=status.MPI_SOURCE;
457 inline static tBoolean
GetCount(
const tMPIStatus& status,tMPICount& nElements) {
458 return (MPI_Get_count(&status,MPI_Type::GetPrimaryType<T>(),&nElements)==MPI_SUCCESS);
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
This class is a Environment class to define MPI world.
Definition: MPI_Environment.h:36
static tBoolean IsTagMessageAvaliable(const MPI_Environment &env, const tMPITag &tag, tMPICoreId &source, tMPIBoolean &isAvailable, tMPIStatus &status)
test if the message with tag is avalaible
Definition: MPI_Environment.h:437
const tMPICoreId & getCoreId() const
get the id of the current process of this environment
Definition: MPI_Environment.h:200
static void GetCoreId(tMPICoreId &id)
get the id of the current process of common environment
Definition: MPI_Environment.h:210
tMPIComm & getWorld()
get the world of the environment for reading
Definition: MPI_Environment.h:172
tBoolean isMessageAvaliable(tMPICoreId &source, tMPITag &tag, tMPIBoolean &isAvailable, tMPIStatus &status) const
test if the message is available frm the environment this
Definition: MPI_Environment.h:386
const tMPICoreId & getCoresNumber() const
get the number of cores of this environment of common environment
Definition: MPI_Environment.h:180
static tBoolean Wait(tMPIRequest &request)
wait for the request is finished
Definition: MPI_Environment.h:299
static tBoolean Synchronize()
wait that all the cores has finished her job
Definition: MPI_Environment.h:272
static CORE_UniquePointer< MPI_Environment > New(int argc, char *argv[], const tBoolean &isOpenMPEnabled)
create a test class
Definition: MPI_Environment.h:116
void setIsRootEnvironment(const tBoolean &isRoot)
set true when the environemnt created is a root one but not a common world
Definition: MPI_Environment.h:156
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: MPI_Environment.h:136
tMPIError abort(const tMPIError &errCode) const
abort the process on all cores with the error code
Definition: MPI_Environment.h:255
static tBoolean WaitAll(std::array< tMPIRequest, D > &requests)
wait for all the requests are finished
Definition: MPI_Environment.h:327
static CORE_UniquePointer< MPI_Environment > New(int argc, char *argv[])
create a test class
Definition: MPI_Environment.h:127
static void GetCoresNumber(tMPICoreId &coresNumber)
get the number of cores
Definition: MPI_Environment.h:186
MPI_Environment(int &argc, char *argv[], const tBoolean &isOpenMPEnabled)
create a root environment
Definition: MPI_Environment.h:72
static tBoolean Wait(tMPIRequest &request, tMPIStatus &status)
wait the end the the communication by blocking
Definition: MPI_Environment.h:293
static tBoolean IsMessageAvaliable(const MPI_Environment &env, const tMPITag &tag, const tMPICoreId &source, tMPIBoolean &isAvailable)
test if the message with tag from source is available
Definition: MPI_Environment.h:422
static tBoolean WaitAll(const tMPICount &nRequests, tMPIRequest requests[], tMPIStatus statuses[])
wait the end the the communication by blocking
Definition: MPI_Environment.h:308
static tBoolean IsMessageAvaliable(const MPI_Environment &env, tMPICoreId &source, tMPITag &tag, tMPIBoolean &isAvailable, tMPIStatus &status)
test if a message is available form any tag and any source
Definition: MPI_Environment.h:401
static tBoolean IsFinished(tMPIRequest &request, tMPIStatus &status, tMPIInteger &isFinished)
return true if the communication is finished
Definition: MPI_Environment.h:374
static tBoolean Synchronize(const MPI_Environment &env)
wait that all the core of an environment has finished her job
Definition: MPI_Environment.h:265
static tMPIError Abort(const MPI_Environment &env, const tMPIError &errCode)
abort the process on all cores of the environment with the eroor code
Definition: MPI_Environment.h:240
virtual ~MPI_Environment(void)
destroy
Definition: MPI_Environment.h:86
static tReal GetTime()
get the time
Definition: MPI_Environment.h:227
static void GetCoreId(const MPI_Environment &env, tMPICoreId &id)
get the id of the current process of common environment
Definition: MPI_Environment.h:217
static tBoolean IsAllFinished(std::valarray< tMPIRequest > &requests, tMPIInteger &isFinished)
test if the requets is finished
Definition: MPI_Environment.h:360
tBoolean synchronize() const
wait that all the cores has finished her job
Definition: MPI_Environment.h:280
static void GetCoresNumber(const MPI_Environment &env, tMPICoreId &coresNumber)
get the number of cores
Definition: MPI_Environment.h:193
const tMPIComm & getWorld() const
get the world of the environment for reading
Definition: MPI_Environment.h:165
static tBoolean WaitAll(std::valarray< tMPIRequest > &requests)
wait for all the requests are finished
Definition: MPI_Environment.h:316
static tBoolean GetCount(const tMPIStatus &status, tMPICount &nElements)
get the number of element of the message
Definition: MPI_Environment.h:457
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: MPI_Environment.h:148
MPI_Environment()
create a root environment
Definition: MPI_Environment.h:56
virtual void initialize()
initialize the environment Sets the cores number and the core id of the environment
Definition: MPI_Environment.h:103
static tBoolean WaitAll(const tMPICount &nRequests, tMPIRequest *requests)
wait for all the requests are finished
Definition: MPI_Environment.h:337
static tBoolean IsFinished(tMPIRequest &request, tMPIInteger &isFinished)
test if the requets is finished
Definition: MPI_Environment.h:351
static tMPIError Abort(const tMPIError &errCode)
abort the process on all cores with the error code
Definition: MPI_Environment.h:247
This class is a base class of E-MicromM core package.
Definition: MPI_Object.h:32
This class is a Test class for EMicroM package which uses the module tests.
Definition: MPI_Test.h:15