30 #ifndef __Application_H
31 #define __Application_H 1
34 #include <boost/archive/binary_iarchive.hpp>
35 #include <boost/archive/binary_oarchive.hpp>
36 #include <boost/archive/text_iarchive.hpp>
37 #include <boost/archive/text_oarchive.hpp>
38 #include <boost/serialization/string.hpp>
40 #include <boost/mpi.hpp>
41 #include <feel/feelconfig.h>
43 #if defined(FEELPP_HAS_MPI_H)
49 #include <feel/feelcore/feel.hpp>
54 namespace mpi = boost::mpi;
64 class Application :
public Application
66 typedef Application super;
89 #if defined( FEELPP_HAS_MPI )
90 Application(
int argc,
char** argv, AboutData
const& ad, MPI_Comm Comm = MPI_COMM_WORLD );
92 Application(
int argc,
char** argv, AboutData
const& ad );
104 #if defined( FEELPP_HAS_MPI )
105 Application(
int argc,
char** argv, AboutData
const& ad, po::options_description
const& od, MPI_Comm Comm = MPI_COMM_WORLD );
107 Application(
int argc,
char** argv, AboutData
const& ad, po::options_description
const& od );
131 return _S_is_mpi_initialized;
142 return mpi::environment::initialized();
153 return mpi::environment::finalized();
167 #if defined( FEELPP_HAS_MPI )
168 return mpi::environment::processor_name();
171 return std::string(
"localhost" );
192 #if defined( FEELPP_HAS_MPI )
194 static void Send(
const T& obj,
int proc,
int tag,
const MPI_Comm&
comm = COMM_WORLD )
196 std::ostringstream oss;
197 boost::archive::binary_oarchive oa( oss );
200 std::string str( oss.str() );
201 int size = str.size();
202 MPI_Ssend( &size, 1, MPI_INT, proc, tag,
comm );
203 MPI_Ssend( &str[0], size, MPI_CHAR, proc, tag,
comm );
207 static void Send(
const T& obj,
int proc,
int tag )
211 #endif // FEELPP_HAS_MPI
214 #if defined( FEELPP_HAS_MPI )
216 static void Broadcast( T& obj,
int root = 0,
const MPI_Comm&
comm = COMM_WORLD )
218 std::ostringstream oss;
219 boost::archive::binary_oarchive oa( oss );
222 std::string str( oss.str() );
223 int size = str.size();
224 MPI_Bcast( &size, 1, MPI_INT, root,
comm );
229 DVLOG(2) <<
"[Application::Broadcast] str.size = " << str.size() <<
"\n";
230 DVLOG(2) <<
"[Application::Broadcast] before str = " << str <<
"\n";
232 MPI_Bcast( &str[0], size, MPI_CHAR, root,
comm );
233 DVLOG(2) <<
"[Application::Broadcast] after str = " << str <<
"\n";
238 std::istringstream iss( str );
239 boost::archive::binary_iarchive ia( iss );
245 static void Broadcast( T& obj )
249 #endif // FEELPP_HAS_MP
254 #if defined( FEELPP_HAS_MPI )
256 static void Recv( T& obj,
int proc,
int tag,
const MPI_Comm&
comm = COMM_WORLD )
261 MPI_Recv( &size, 1, MPI_INT, proc, tag,
comm, &status );
262 std::string buf( size,
' ' );
263 MPI_Recv( &buf[0], size, MPI_CHAR, proc, tag,
comm, &status );
265 std::istringstream iss( buf );
266 boost::archive::binary_iarchive ia( iss );
271 static void Recv( T& obj,
int proc,
int tag )
275 #endif // FEELPP_HAS_MPI
278 #if defined( FEELPP_HAS_MPI )
279 static MPI_Comm COMM_WORLD;
280 #endif // FEELPP_HAS_MPI
285 static mpi::communicator
const&
comm()
310 static bool _S_is_mpi_initialized;
311 boost::shared_ptr<mpi::environment> M_env;
312 static mpi::communicator S_world;
static mpi::communicator const & comm()
Definition: applicationmpi.hpp:285
provides information about the Application
Definition: application.hpp:71
static bool initialized()
Definition: applicationmpi.hpp:140
static bool finalized()
Definition: applicationmpi.hpp:151
WorldComm & comm()
Definition: application.hpp:356
static std::string processorName()
Definition: applicationmpi.hpp:165
static void barrier()
Definition: applicationmpi.hpp:293
bool isMPIInitialized() const
Definition: applicationmpi.hpp:129
uint16_type processId()
Definition: application.hpp:227