diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 115520a..8b190e5 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -37,6 +37,7 @@ lib boost_mpi mpi/timer.cpp : # Requirements /mpi//mpi + ../../serialization/build//boost_serialization : # Default build shared : # Usage requirements diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 7d333f7..0357948 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -30,7 +30,7 @@ doxygen mpi_autodoc ../../../boost/parallel/mpi/python.hpp : MACRO_EXPANSION=YES MACRO_ONLY_PREDEF=YES - "PREDEFINED=BOOST_MPI_HAS_MEMORY_ALLOCATION= MPI_VERSION=2 BOOST_MPI_DOXYGEN=" + "PREDEFINED=BOOST_MPI_HAS_MEMORY_ALLOCATION= BOOST_MPI_HAS_NOARG_INITIALIZATION= MPI_VERSION=2 BOOST_MPI_DOXYGEN=" ; boostbook mpi : mpi.qbk mpi_autodoc diff --git a/include/boost/mpi/config.hpp b/include/boost/mpi/config.hpp index 99b65e6..f033e34 100644 --- a/include/boost/mpi/config.hpp +++ b/include/boost/mpi/config.hpp @@ -27,11 +27,22 @@ * these memory-allocation routines. */ # define BOOST_MPI_HAS_MEMORY_ALLOCATION + +/** @brief Determine if the MPI implementation has supports initialization + * without command-line arguments. + * + * This macro will be defined when the underlying implementation + * supports initialization of MPI without passing along command-line + * arguments, e.g., @c MPI_Init(NULL, NULL). When defined, the @c + * environment class will provide a default constructor. This macro is + * always defined for MPI-2 implementations. */ +# define BOOST_MPI_HAS_NOARG_INITIALIZATION #endif #if defined(LAM_MPI) // Configuration for LAM/MPI # define BOOST_MPI_HAS_MEMORY_ALLOCATION +# define BOOST_MPI_HAS_NOARG_INITIALIZATION #elif defined(MPICH_NAME) // Configuration for MPICH #endif diff --git a/include/boost/mpi/environment.hpp b/include/boost/mpi/environment.hpp index 8044a4a..28433db 100644 --- a/include/boost/mpi/environment.hpp +++ b/include/boost/mpi/environment.hpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace boost { namespace parallel { namespace mpi { @@ -46,6 +47,23 @@ namespace boost { namespace parallel { namespace mpi { */ class environment : noncopyable { public: +#ifdef BOOST_MPI_HAS_NOARG_INITIALIZATION + /** Initialize the MPI environment. + * + * If the MPI environment has not already been initialized, + * initializes MPI with a call to @c MPI_Init. Since this + * constructor does not take command-line arguments (@c argc and @c + * argv), it is only available when the underlying MPI + * implementation supports calling @c MPI_Init with @c NULL + * arguments, indicated by the macro @c + * BOOST_MPI_HAS_NOARG_INITIALIZATION. + * + * @param abort_on_exception When true, this object will abort the + * program if it is destructed due to an uncaught exception. + */ + explicit environment(bool abort_on_exception = true); +#endif + /** Initialize the MPI environment. * * If the MPI environment has not already been initialized, diff --git a/src/mpi/environment.cpp b/src/mpi/environment.cpp index 53d1189..bd64609 100644 --- a/src/mpi/environment.cpp +++ b/src/mpi/environment.cpp @@ -13,6 +13,20 @@ namespace boost { namespace parallel { namespace mpi { +#ifdef BOOST_MPI_HAS_NOARG_INITIALIZATION +environment::environment(bool abort_on_exception) + : i_initialized(false), + abort_on_exception(abort_on_exception) +{ + if (!initialized()) { + BOOST_MPI_CHECK_RESULT(MPI_Init, (0, 0)); + i_initialized = true; + } + + MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN); +} +#endif + environment::environment(int& argc, char** &argv, bool abort_on_exception) : i_initialized(false), abort_on_exception(abort_on_exception)