25 #ifndef PAGMO_MPI_ENVIRONMENT_H
26 #define PAGMO_MPI_ENVIRONMENT_H
28 #include <boost/archive/text_iarchive.hpp>
29 #include <boost/archive/text_oarchive.hpp>
30 #include <boost/numeric/conversion/cast.hpp>
31 #include <boost/utility.hpp>
179 static bool is_multithread();
180 static int get_size();
181 static int get_rank();
191 static void recv(T &retval,
int source)
197 MPI_Recv(static_cast<void *>(&size),1,MPI_INT,source,0,MPI_COMM_WORLD,&status);
199 std::vector<char> buffer_char(boost::numeric_cast<std::vector<char>::size_type>(size),0);
201 MPI_Recv(static_cast<void *>(&buffer_char[0]),size,MPI_CHAR,source,1,MPI_COMM_WORLD,&status);
203 const std::string buffer_str(buffer_char.begin(),buffer_char.end());
205 std::stringstream ss(buffer_str);
206 boost::archive::text_iarchive ia(ss);
218 static void send(
const T &payload,
int destination)
221 std::stringstream ss;
222 boost::archive::text_oarchive oa(ss);
224 const std::string buffer_str(ss.str());
225 std::vector<char> buffer_char(buffer_str.begin(),buffer_str.end());
227 int size = boost::numeric_cast<
int>(buffer_char.size());
228 MPI_Send(static_cast<void *>(&size),1,MPI_INT,destination,0,MPI_COMM_WORLD);
230 MPI_Send(static_cast<void *>(&buffer_char[0]),size,MPI_CHAR,destination,1,MPI_COMM_WORLD);
232 static bool iprobe(
int);
234 static void listen();
235 static void check_init();
236 static bool m_initialised;
237 static bool m_multithread;
static void recv(T &retval, int source)
Receive MPI payload.
static void send(const T &payload, int destination)
Send MPI payload.