32#ifndef MADNESS_WORLD_WORLDMPI_H__INCLUDED
33#define MADNESS_WORLD_WORLDMPI_H__INCLUDED
62#ifdef MADNESS_USE_BSEND_ACKS
64#define MADNESS_ACK_BUFF_SIZE 1000
71#define MPI_THREAD_STRING(level) \
72 ( level==MPI_THREAD_SERIALIZED ? "THREAD_SERIALIZED" : \
73 ( level==MPI_THREAD_MULTIPLE ? "THREAD_MULTIPLE" : \
74 ( level==MPI_THREAD_FUNNELED ? "THREAD_FUNNELED" : \
75 ( level==MPI_THREAD_SINGLE ? "THREAD_SINGLE" : "THREAD_UNKNOWN" ) ) ) )
89 class WorldMpiRuntime;
108#ifdef MADNESS_USE_BSEND_ACKS
110 static char* mpi_ack_buffer[MADNESS_ACK_BUFF_SIZE];
131#ifdef MADNESS_USE_BSEND_ACKS
147#ifdef MADNESS_USE_BSEND_ACKS
149 void* buff =
nullptr;
165 std::cout <<
"!! MPI Error: " << mpi_error_string <<
"\n";
184 static void initialize(
int& argc,
char**& argv,
int requested) {
200 if((provided < requested) && (rank == 0)) {
201 std::cout <<
"!! Error: MPI_Init_thread did not provide requested functionality: "
203 <<
"!! Error: The MPI standard makes no guarantee about the correctness of a program in such circumstances. \n"
204 <<
"!! Error: Please reconfigure your MPI to provide the proper thread support. \n"
207 }
else if((provided > requested) && (rank == 0)) {
208 std::cout <<
"!! Warning: MPI_Init_thread provided more than the requested functionality: "
210 <<
"!! Warning: You are likely using an MPI implementation with mediocre thread support. \n"
214#if defined(MVAPICH2_VERSION)
216 char * mv2_string =
nullptr;
217 int mv2_affinity = 1;
219 if ((mv2_string = getenv(
"MV2_ENABLE_AFFINITY")) !=
nullptr) {
220 mv2_affinity = atoi(mv2_string);
223 if (mv2_affinity!=0) {
224 std::cout <<
"!! Error: You are using MVAPICH2 with affinity enabled, probably by default. \n"
225 <<
"!! Error: This will cause catastrophic performance issues in MADNESS. \n"
226 <<
"!! Error: Rerun your job with MV2_ENABLE_AFFINITY=0 \n"
306 template <
typename T>
319 template <
typename T>
332 template <
typename T>
359 template <
typename T>
360 typename std::enable_if<!std::is_pointer<T>::value,
void>
::type
373 template <
typename T>
374 void Recv(
T* buf,
long lenbuf,
int src,
int tag)
const {
386 template <
typename T>
398 template <
typename T>
399 typename std::enable_if<!std::is_pointer<T>::value,
void>
::type
415 template <
typename T>
416 void Bcast(
T* buffer,
int count,
int root)
const {
430 template <
typename T>
431 typename std::enable_if<!std::is_pointer<T>::value,
void>
::type
Wrapper around MPI_Comm. Has a shallow copy constructor; use Create(Get_group()) for deep copy.
Definition safempi.h:490
Request Irecv(void *buf, const int count, const MPI_Datatype datatype, const int src, const int tag) const
Definition safempi.h:740
void Bcast(void *buf, size_t count, const MPI_Datatype datatype, const int root) const
Definition safempi.h:775
Request Isend(const void *buf, const int count, const MPI_Datatype datatype, const int dest, const int tag) const
Definition safempi.h:724
int Get_rank() const
Definition safempi.h:714
void Send(const void *buf, const int count, const MPI_Datatype datatype, int dest, int tag) const
Definition safempi.h:748
void Recv(void *buf, const int count, const MPI_Datatype datatype, const int source, const int tag, MPI_Status &status) const
Definition safempi.h:763
int Get_size() const
Definition safempi.h:719
Intracomm()
Definition safempi.h:573
This class wraps/extends the MPI interface for World.
Definition worldmpi.h:266
void Recv(T *buf, long lenbuf, int src, int tag, SafeMPI::Status &status) const
Receive data of up to lenbuf elements from process dest with status.
Definition worldmpi.h:387
int nproc() const
Access the total number of processes.
Definition worldmpi.h:444
std::enable_if<!std::is_pointer< T >::value, SafeMPI::Request >::type Isend(const T &datum, int dest, int tag=SafeMPI::DEFAULT_SEND_RECV_TAG) const
Isend one element.
Definition worldmpi.h:308
std::enable_if<!std::is_pointer< T >::value, SafeMPI::Request >::type Irecv(T &buf, int source, int tag=SafeMPI::DEFAULT_SEND_RECV_TAG) const
Async receive datum from process source with default tag=1.
Definition worldmpi.h:334
std::enable_if<!std::is_pointer< T >::value, void >::type Send(const T &datum, int dest, int tag=SafeMPI::DEFAULT_SEND_RECV_TAG) const
Send element to process dest with default tag=1001.
Definition worldmpi.h:361
void Bcast(T *buffer, int count, int root) const
MPI broadcast an array of count elements.
Definition worldmpi.h:416
SafeMPI::Request Irecv(T *buf, int count, int source, int tag=SafeMPI::DEFAULT_SEND_RECV_TAG) const
Async receive data of up to count elements from process source.
Definition worldmpi.h:321
WorldMpiInterface(const WorldMpiInterface &)=delete
~WorldMpiInterface()=default
SafeMPI::Intracomm & comm()
Returns the associated SafeMPI communicator.
Definition worldmpi.h:286
int size() const
Access the total number of processes.
Definition worldmpi.h:449
void Send(const T *buf, long lenbuf, int dest, int tag=SafeMPI::DEFAULT_SEND_RECV_TAG) const
Send array of lenbuf elements to process dest.
Definition worldmpi.h:347
std::enable_if<!std::is_pointer< T >::value, void >::type Bcast(T &buffer, int root) const
MPI broadcast a datum.
Definition worldmpi.h:432
std::enable_if<!std::is_pointer< T >::value, void >::type Recv(T &buf, int src, int tag=SafeMPI::DEFAULT_SEND_RECV_TAG) const
Receive datum from process src.
Definition worldmpi.h:400
int rank() const
Access the rank of this process.
Definition worldmpi.h:439
void Recv(T *buf, long lenbuf, int src, int tag) const
Receive data of up to lenbuf elements from process src.
Definition worldmpi.h:374
WorldMpiInterface(const SafeMPI::Intracomm &comm)
Constructs an interface in the specified SafeMPI communicator.
Definition worldmpi.h:277
WorldMpiInterface & operator=(const WorldMpiInterface &)=delete
MPI runtime reference counter.
Definition worldmpi.h:247
std::shared_ptr< WorldMpi > world_mpi
A pointer to WorldMpi::world_mpi. Used to help manage the lifetime of MPI.
Definition worldmpi.h:250
WorldMpiRuntime()
Constructor.
Definition worldmpi.h:254
~WorldMpiRuntime()
Destructor.
Definition worldmpi.h:257
MPI singleton that manages MPI setup and teardown for MADNESS.
Definition worldmpi.h:95
WorldMpi(int &argc, char **&argv, int requested)
WorldMpi constructor.
Definition worldmpi.h:121
WorldMpi & operator=(const WorldMpi &)=delete
static void initialize(int &argc, char **&argv, int requested)
Initialize the MPI runtime.
Definition worldmpi.h:184
static void finalize()
Finalize the MPI runtime.
Definition worldmpi.h:238
WorldMpi(const WorldMpi &)=delete
~WorldMpi()
WorldMpi destructor.
Definition worldmpi.h:146
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
#define MPI_THREAD_STRING(level)
String description of the MPI thread level.
Definition worldmpi.h:71
static bool own_mpi
Flag storing if MADNESS is responsible for MPI.
Definition worldmpi.h:106
static std::shared_ptr< WorldMpi > world_mpi
Pointer to help MADNESS manage MPI.
Definition worldmpi.h:105
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
void init_comm_world()
Initialize SafeMPI::COMM_WORLD.
Definition safempi.h:863
Intracomm COMM_WORLD
Definition safempi.cc:67
int Init_thread(int &argc, char **&argv, int requested)
Analogous to MPI_Init_thread.
Definition safempi.h:878
void Attach_buffer(void *buffer, int size)
Set buffer for Bsend .
Definition safempi.h:942
int Query_thread()
Analogous to MPI_Query_thread.
Definition safempi.h:927
int Finalize()
Analogous to MPI_Finalize.
Definition safempi.h:918
bool Is_initialized()
Check MPI initialization status.
Definition safempi.h:116
static const int DEFAULT_SEND_RECV_TAG
Definition safempi.h:106
int Detach_buffer(void *&buffer)
Unset the Bsend buffer.
Definition safempi.h:949
bool Is_finalized()
Check MPI finalization status.
Definition safempi.h:125
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
void finalize()
Call this once at the very end of your main program instead of MPI_Finalize().
Definition world.cc:232
static const Tag DYNAMIC_TAG_BASE
Definition worldmpi.h:85
World & initialize(int &argc, char **&argv, bool quiet)
Definition world.cc:145
std::string type(const PairType &n)
Definition PNOParameters.h:18
Serializes calls to MPI in case it does not support THREAD_MULTIPLE.
#define MPI_SUCCESS
Definition stubmpi.h:36
int MPI_Error_string(int errorcode, char *string, int *resultlen)
Definition stubmpi.h:296
#define MPI_COMM_WORLD
Definition stubmpi.h:25
#define MPI_BYTE
Definition stubmpi.h:77
int MPI_Abort(MPI_Comm, int code)
Definition stubmpi.h:266
#define MPI_MAX_ERROR_STRING
Definition stubmpi.h:41
double source(const coordT &r)
Definition testperiodic.cc:48
const char * status[2]
Definition testperiodic.cc:43
Defines types used by the parallel runtime.
int Tag
Used to clearly identify message tag/type.
Definition worldtypes.h:44