Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::mpi::environment Class Reference

Initialize, finalize, and query the MPI environment. More...

#include <environment.hpp>

Inheritance diagram for boost::mpi::environment:
Collaboration diagram for boost::mpi::environment:

Public Member Functions

 environment (int &argc, char **&argv, bool abort_on_exception=true)
 Initialize the MPI environment. More...
 
 environment (int &argc, char **&argv, threading::level mt_level, bool abort_on_exception=true)
 Initialize the MPI environment. More...
 
 ~environment ()
 Shuts down the MPI environment. More...
 

Static Public Member Functions

static void abort (int errcode)
 Abort all MPI processes. More...
 
static bool initialized ()
 Determine if the MPI environment has already been initialized. More...
 
static bool finalized ()
 Determine if the MPI environment has already been finalized. More...
 
static int max_tag ()
 Retrieves the maximum tag value. More...
 
static int collectives_tag ()
 The tag value used for collective operations. More...
 
static optional< int > host_rank ()
 Retrieves the rank of the host process, if one exists. More...
 
static optional< int > io_rank ()
 Retrieves the rank of a process that can perform input/output. More...
 
static std::string processor_name ()
 Retrieve the name of this processor. More...
 
static threading::level thread_level ()
 Query the current level of thread support. More...
 
static bool is_main_thread ()
 Are we in the main thread? More...
 

Detailed Description

Initialize, finalize, and query the MPI environment.

The environment class is used to initialize, finalize, and query the MPI environment. It will typically be used in the main() function of a program, which will create a single instance of environment initialized with the arguments passed to the program:

int main(int argc, char* argv[])
{
mpi::environment env(argc, argv);
}

The instance of environment will initialize MPI (by calling MPI_Init) in its constructor and finalize MPI (by calling MPI_Finalize for normal termination or MPI_Abort for an uncaught exception) in its destructor.

The use of environment is not mandatory. Users may choose to invoke MPI_Init and MPI_Finalize manually. In this case, no environment object is needed. If one is created, however, it will do nothing on either construction or destruction.

Constructor & Destructor Documentation

boost::mpi::environment::environment ( int &  argc,
char **&  argv,
bool  abort_on_exception = true 
)

Initialize the MPI environment.

If the MPI environment has not already been initialized, initializes MPI with a call to MPI_Init.

Parameters
argcThe number of arguments provided in argv, as passed into the program's main function.
argvThe array of argument strings passed to the program via main.
abort_on_exceptionWhen true, this object will abort the program if it is destructed due to an uncaught exception.
boost::mpi::environment::environment ( int &  argc,
char **&  argv,
threading::level  mt_level,
bool  abort_on_exception = true 
)

Initialize the MPI environment.

If the MPI environment has not already been initialized, initializes MPI with a call to MPI_Init_thread.

Parameters
argcThe number of arguments provided in argv, as passed into the program's main function.
argvThe array of argument strings passed to the program via main.
mt_levelthe required level of threading support
abort_on_exceptionWhen true, this object will abort the program if it is destructed due to an uncaught exception.
boost::mpi::environment::~environment ( )

Shuts down the MPI environment.

If this environment object was used to initialize the MPI environment, and the MPI environment has not already been shut down (finalized), this destructor will shut down the MPI environment. Under normal circumstances, this only involves invoking MPI_Finalize. However, if destruction is the result of an uncaught exception and the abort_on_exception parameter of the constructor had the value true, this destructor will invoke MPI_Abort with MPI_COMM_WORLD to abort the entire MPI program with a result code of -1.

Member Function Documentation

static void boost::mpi::environment::abort ( int  errcode)
static

Abort all MPI processes.

Aborts all MPI processes and returns to the environment. The precise behavior will be defined by the underlying MPI implementation. This is equivalent to a call to MPI_Abort with MPI_COMM_WORLD.

Parameters
errcodeThe error code to return to the environment.
Returns
Will not return.
static int boost::mpi::environment::collectives_tag ( )
static

The tag value used for collective operations.

Returns the reserved tag value used by the Boost.MPI implementation for collective operations. Although users are not permitted to use this tag to send or receive messages, it may be useful when monitoring communication patterns.

Returns
the tag value used for collective operations.

Referenced by boost::mpi::detail::gather_impl(), boost::mpi::detail::scatter_impl(), boost::mpi::detail::tree_reduce_impl(), and boost::mpi::detail::upper_lower_scan().

static bool boost::mpi::environment::finalized ( )
static

Determine if the MPI environment has already been finalized.

The routine is equivalent to a call to MPI_Finalized.

Returns
true if the MPI environment has been finalized.
static optional<int> boost::mpi::environment::host_rank ( )
static

Retrieves the rank of the host process, if one exists.

If there is a host process, this routine returns the rank of that process. Otherwise, it returns an empty optional<int>. MPI does not define the meaning of a "host" process: consult the documentation for the MPI implementation. This routine examines the MPI_HOST attribute of MPI_COMM_WORLD.

Returns
The rank of the host process, if one exists.
static bool boost::mpi::environment::initialized ( )
static

Determine if the MPI environment has already been initialized.

This routine is equivalent to a call to MPI_Initialized.

Returns
true if the MPI environment has been initialized.
static optional<int> boost::mpi::environment::io_rank ( )
static

Retrieves the rank of a process that can perform input/output.

This routine returns the rank of a process that can perform input/output via the standard C and C++ I/O facilities. If every process can perform I/O using the standard facilities, this routine will return any_source; if no process can perform I/O, this routine will return no value (an empty optional). This routine examines the MPI_IO attribute of MPI_COMM_WORLD.

Returns
the rank of the process that can perform I/O, any_source if every process can perform I/O, or no value if no process can perform I/O.
static bool boost::mpi::environment::is_main_thread ( )
static

Are we in the main thread?

static int boost::mpi::environment::max_tag ( )
static

Retrieves the maximum tag value.

Returns the maximum value that may be used for the tag parameter of send/receive operations. This value will be somewhat smaller than the value of MPI_TAG_UB, because the Boost.MPI implementation reserves some tags for collective operations.

Returns
the maximum tag value.
static std::string boost::mpi::environment::processor_name ( )
static

Retrieve the name of this processor.

This routine returns the name of this processor. The actual form of the name is unspecified, but may be documented by the underlying MPI implementation. This routine is implemented as a call to MPI_Get_processor_name.

Returns
the name of this processor.
static threading::level boost::mpi::environment::thread_level ( )
static

Query the current level of thread support.


The documentation for this class was generated from the following file: