Skip to content
Snippets Groups Projects
Commit 715bbf7e authored by Markus Blatt's avatar Markus Blatt
Browse files

Only use MPI_Initialzed with MPI2.

Added check before MPI_Finalize, too.

[[Imported from SVN: r6233]]
parent c3e8b330
No related branches found
No related tags found
No related merge requests found
......@@ -205,23 +205,19 @@ namespace Dune
int size_;
void prevent_warning(int){}
static bool wasInitialized ()
{
int wasInitialized = -1;
MPI_Initialized( &wasInitialized );
return bool( wasInitialized );
}
//! \brief calls MPI_Init with argc and argv as parameters
MPIHelper(int& argc, char**& argv)
{
rank_ = -1;
size_ = -1;
#if MPI_2
int wasInitialized = -1;
MPI_Initialized( &wasInitialized );
if(!wasInitialized) {
rank_ = -1;
size_ = -1;
assert( !wasInitialized() );
#endif
static int is_initialized = MPI_Init(&argc, &argv);
prevent_warning(is_initialized);
assert( wasInitialized() );
MPI_Comm_rank(MPI_COMM_WORLD,&rank_);
MPI_Comm_size(MPI_COMM_WORLD,&size_);
......@@ -230,12 +226,24 @@ namespace Dune
assert( size_ >= 1 );
dverb << "Called MPI_Init on p=" << rank_ << "!" << std::endl;
#if MPI_2
}
#endif
}
//! \brief calls MPI_Finalize
~MPIHelper()
{
#ifdef MPI_2
int wasFinalized = -1;
MPI_Finalized( &wasFinalized );
if(!wasFinalized) {
#endif
MPI_Finalize();
dverb << "Called MPI_Finalize on p=" << rank_ << "!" <<std::endl;
#ifdef MPI_2
}
#endif
}
MPIHelper(const MPIHelper&);
MPIHelper& operator=(const MPIHelper);
......
......@@ -58,3 +58,4 @@ paramtreetest
tags
pathtest
TAGS
mpihelpertest2
......@@ -21,6 +21,7 @@ TESTPROGS = \
mpicollcomm \
mpiguardtest \
mpihelpertest \
mpihelpertest2 \
nullptr-test \
pathtest \
paramtreetest \
......@@ -135,6 +136,11 @@ mpihelpertest_CPPFLAGS = $(AM_CPPFLAGS) $(DUNEMPICPPFLAGS)
mpihelpertest_LDADD = $(DUNEMPILIBS) $(LDADD)
mpihelpertest_LDFLAGS = $(AM_LDFLAGS) $(DUNEMPILDFLAGS)
mpihelpertest2_SOURCES = mpihelpertest.cc
mpihelpertest2_CPPFLAGS = $(AM_CPPFLAGS) $(DUNEMPICPPFLAGS) -DMPIHELPER_PREINITIALZE
mpihelpertest2_LDADD = $(DUNEMPILIBS) $(LDADD)
mpihelpertest2_LDFLAGS = $(AM_LDFLAGS) $(DUNEMPILDFLAGS)
mpicollcomm_SOURCES = mpicollectivecommunication.cc
mpicollcomm_CPPFLAGS = $(AM_CPPFLAGS) $(DUNEMPICPPFLAGS)
mpicollcomm_LDADD = $(DUNEMPILIBS) $(LDADD)
......
......@@ -8,6 +8,11 @@
#include <iostream>
int main(int argc, char** argv)
{
#ifdef MPIHELPER_PREINITIALZE
MPI_Init(&argc, &argv);
#endif
typedef Dune::MPIHelper Helper;
{
......@@ -22,6 +27,10 @@ int main(int argc, char** argv)
Helper::MPICommunicator comm= mpi.getCommunicator();
comm= mpi.getCommunicator();
#ifdef MPIHELPER_PREINITIALZE
MPI_Finalize();
#endif
}
std::cout << "We are at the end!"<<std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment