Loading...
Searching...
No Matches
environment.cc
Go to the documentation of this file.
// boost::mpi::environment-like interface, with thread options for scotch lib
#include "rheolef/environment.h"
#ifndef _RHEOLEF_HAVE_MPI
namespace rheolef {
environment::environment (int& argc, char**& argv, const environment_option_type& opt)
: _oldcw(0)
{
}
environment::~environment()
{
}
} // namespace rheolef
#else // _RHEOLEF_HAVE_MPI
// support MPI-2 (with warnings, but changed to error by the compiler flags)
#ifdef MPI_VERSION
# if (MPI_VERSION >= 2)
# ifndef MPI_Errhandler_set
# define MPI_Errhandler_set MPI_Comm_set_errhandler
# endif
# ifndef MPI_Attr_get
# define MPI_Attr_get MPI_Comm_get_attr
# endif
# endif
#endif
namespace rheolef {
bool environment::initialized() {
int flag;
MPI_Initialized(&flag);
return flag != 0;
}
bool environment::finalized() {
int flag;
MPI_Finalized(&flag);
return flag != 0;
}
environment::environment (int& argc, char**& argv, const environment_option_type& opt)
: _rheolef_has_init(false), _oldcw(0)
{
if (!initialized()) {
int status = 0;
if (opt.thread_level == environment_option_type::no_thread) {
status = MPI_Init (&argc, &argv);
} else {
int obtained_thread_level;
status = MPI_Init_thread (&argc, &argv, opt.thread_level, &obtained_thread_level);
if (obtained_thread_level != opt.thread_level) {
warning_macro ("mpi_init: obtained thread level="<<obtained_thread_level <<" while asking for thread level="<<opt.thread_level);
}
}
check_macro (status == MPI_SUCCESS, "mpi init failed");
}
if (!_rheolef_has_init) {
#ifdef _RHEOLEF_HAVE_OBSOLETE_MPI_V1
MPI_Errhandler_set (MPI_COMM_WORLD, MPI_ERRORS_RETURN);
#else
MPI_Comm_set_errhandler (MPI_COMM_WORLD, MPI_ERRORS_RETURN);
#endif
_rheolef_has_init = true;
}
}
environment::~environment()
{
if (_rheolef_has_init && !finalized()) {
boost::mpi::detail::mpi_datatype_cache().clear();
MPI_Finalize();
}
}
void environment::abort(int errcode)
{
MPI_Abort(MPI_COMM_WORLD, errcode);
}
int environment::max_tag()
{
int* max_tag_value;
int found = 0;
MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &max_tag_value, &found);
assert_macro (found != 0, "MPI_Attr_get: error");
return *max_tag_value - _num_reserved_tags;
}
int environment::collectives_tag()
{
return max_tag() + 1;
}
boost::optional<int> environment::host_rank()
{
int* host;
int found = 0;
MPI_Attr_get(MPI_COMM_WORLD, MPI_HOST, &host, &found);
if (!found || *host == MPI_PROC_NULL) {
return boost::optional<int>();
} else {
return *host;
}
}
boost::optional<int> environment::io_rank()
{
int* io;
int found = 0;
MPI_Attr_get(MPI_COMM_WORLD, MPI_IO, &io, &found);
if (!found || *io == MPI_PROC_NULL) {
return boost::optional<int>();
} else {
return *io;
}
}
std::string environment::processor_name()
{
char name[MPI_MAX_PROCESSOR_NAME];
int len;
MPI_Get_processor_name(name, &len);
return std::string(name, len);
}
} // namespace rheolef
#endif // _RHEOLEF_HAVE_MPI
rheolef::environment::processor_name
static std::string processor_name()
Definition environment.cc:134
rheolef::environment::initialized
static bool initialized()
Definition environment.cc:54
rheolef::environment::io_rank
static boost::optional< int > io_rank()
Definition environment.cc:123
rheolef::environment::environment
environment(int &argc, char **&argv, const environment_option_type &opt=environment_option_type())
Definition environment.cc:64
rheolef::environment::host_rank
static boost::optional< int > host_rank()
Definition environment.cc:112
rheolef::environment::abort
static void abort(int errcode)
Definition environment.cc:96
rheolef::environment::~environment
~environment()
Definition environment.cc:89
rheolef::environment::max_tag
static int max_tag()
Definition environment.cc:100
rheolef::environment::finalized
static bool finalized()
Definition environment.cc:59
rheolef::environment::collectives_tag
static int collectives_tag()
Definition environment.cc:108
assert_macro
#define assert_macro(ok_condition, message)
Definition dis_macros.h:113
warning_macro
#define warning_macro(message)
Definition dis_macros.h:53
check_macro
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
rheolef::io
Definition rheostream.h:170
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::environment_option_type
Definition environment.h:91
rheolef::environment_option_type::thread_level
int thread_level
Definition environment.h:103
rheolef::environment_option_type::no_thread
static const int no_thread
Definition environment.h:92