Skip to content

Use MPI interfaces to check MPI env. #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions c++/src/mpicommons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ bool finalized__ = false;
//
void MPICommons::init()
{
if (inited__)
int is_inited;
initialized(&is_inited);

if (is_inited)
{
return;
}
Expand All @@ -34,9 +37,18 @@ void MPICommons::init()

// Make the init call.
MPI_Init( &argc, &argv );
#endif
}

// Set the flag to prevent further calls.
inited__ = true;

// -----------------------------------------------------------------------------
//
void MPICommons::initialized(int* flag)
{
#if RUNMPI == true
MPI_Initialized(flag);
#else
*flag = 1;
#endif
}

Expand All @@ -45,14 +57,28 @@ void MPICommons::init()
//
void MPICommons::finalize()
{
if (finalized__)
int is_finalized;
finalized(&is_finalized);

if (is_finalized)
{
return;
}

#if RUNMPI == true
MPI_Finalize();
finalized__ = true;
MPI_Finalize();
#endif
}


// -----------------------------------------------------------------------------
//
void MPICommons::finalized(int* flag)
{
#if RUNMPI == true
MPI_Finalized(flag);
#else
*flag = 0;
#endif
}

Expand Down
8 changes: 8 additions & 0 deletions c++/src/mpicommons.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ struct MPICommons {
*/
static void init();

/*! \brief Wrapps MPI_Initialzed
*/
static void initialized(int* flag);

/*! \brief Wrapps MPI_FINALIZE
*/
static void finalize();

/*! \brief Wrapps MPI_Finalized
*/
static void finalized(int* flag);

/*! \brief Wrapps MPI_COMM_RANK
* \param comm: The communicator to use.
* \return: The rank of this process withing the given communicator.
Expand Down