fix(MPI): resolved cyclic inclusion and MPI issue
This commit is contained in:
parent
d3a2ab5e84
commit
77148b5a97
1 changed files with 246 additions and 248 deletions
|
|
@ -22,7 +22,7 @@ Authors:
|
|||
#ifndef __EO_IMPL_MPI_HPP__
|
||||
#define __EO_IMPL_MPI_HPP__
|
||||
|
||||
#include "eoMpi.h"
|
||||
#include <mpi.h>
|
||||
#include "../serial/eoSerial.h"
|
||||
|
||||
/**
|
||||
|
|
@ -43,8 +43,8 @@ Authors:
|
|||
*/
|
||||
namespace eo
|
||||
{
|
||||
namespace mpi
|
||||
{
|
||||
namespace mpi
|
||||
{
|
||||
/**
|
||||
* @ingroup Parallel
|
||||
* @{
|
||||
|
|
@ -69,14 +69,13 @@ namespace mpi
|
|||
class environment
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Inits MPI context.
|
||||
*
|
||||
* @param argc Number of params in command line (same as one in main)
|
||||
* @param argv Strings containing params (same as one in main)
|
||||
*/
|
||||
environment(int argc, char**argv);
|
||||
environment(int argc, char **argv);
|
||||
|
||||
/**
|
||||
* @brief Closes MPI context.
|
||||
|
|
@ -84,13 +83,14 @@ namespace mpi
|
|||
~environment();
|
||||
};
|
||||
|
||||
struct MPI_Status {
|
||||
/* struct MPI_Status
|
||||
{
|
||||
int count;
|
||||
int cancelled;
|
||||
int MPI_SOURCE;
|
||||
int MPI_TAG;
|
||||
int MPI_ERROR;
|
||||
};
|
||||
}; */
|
||||
|
||||
/**
|
||||
* @brief Wrapper class for MPI_Status
|
||||
|
|
@ -100,11 +100,10 @@ namespace mpi
|
|||
class status
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Converts a MPI_Status into a status.
|
||||
*/
|
||||
status( const MPI_Status & s );
|
||||
status(const MPI_Status &s);
|
||||
|
||||
/**
|
||||
* @brief Returns the tag of the associated communication.
|
||||
|
|
@ -134,13 +133,12 @@ namespace mpi
|
|||
class communicator
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates the communicator, using the whole world as a MPI_Comm.
|
||||
*
|
||||
* @todo Allow the user to precise which MPI_Comm to use
|
||||
*/
|
||||
communicator( );
|
||||
communicator();
|
||||
|
||||
~communicator();
|
||||
|
||||
|
|
@ -165,7 +163,7 @@ namespace mpi
|
|||
* @param tag MPI tag of message
|
||||
* @param n The integer to send
|
||||
*/
|
||||
void send( int dest, int tag, int n );
|
||||
void send(int dest, int tag, int n);
|
||||
|
||||
/*
|
||||
* @brief Receives an integer from src on channel "tag".
|
||||
|
|
@ -174,7 +172,7 @@ namespace mpi
|
|||
* @param tag MPI tag of message
|
||||
* @param n Where to save the received integer
|
||||
*/
|
||||
void recv( int src, int tag, int& n );
|
||||
void recv(int src, int tag, int &n);
|
||||
|
||||
/*
|
||||
* SEND / RECV STRING
|
||||
|
|
@ -187,7 +185,7 @@ namespace mpi
|
|||
* @param tag MPI tag of message
|
||||
* @param str The std::string to send
|
||||
*/
|
||||
void send( int dest, int tag, const std::string& str );
|
||||
void send(int dest, int tag, const std::string &str);
|
||||
|
||||
/*
|
||||
* @brief Receives a string from src on channel "tag".
|
||||
|
|
@ -196,7 +194,7 @@ namespace mpi
|
|||
* @param tag MPI tag of message
|
||||
* @param std::string Where to save the received string
|
||||
*/
|
||||
void recv( int src, int tag, std::string& str );
|
||||
void recv(int src, int tag, std::string &str);
|
||||
|
||||
/*
|
||||
* SEND / RECV Objects
|
||||
|
|
@ -209,7 +207,7 @@ namespace mpi
|
|||
* @param tag MPI tag of message
|
||||
* @param persistent The object to send (it must absolutely implement eoserial::Persistent)
|
||||
*/
|
||||
void send( int dest, int tag, const eoserial::Persistent & persistent );
|
||||
void send(int dest, int tag, const eoserial::Persistent &persistent);
|
||||
|
||||
/**
|
||||
* @brief Sends an array of eoserial::Persistent to dest on channel "tag".
|
||||
|
|
@ -220,26 +218,26 @@ namespace mpi
|
|||
* @param size The number of elements to send (no check is done, the user has to be sure that the size won't
|
||||
* overflow!)
|
||||
*/
|
||||
template< class T >
|
||||
void send( int dest, int tag, T* table, int size )
|
||||
template <class T>
|
||||
void send(int dest, int tag, T *table, int size)
|
||||
{
|
||||
// Puts all the values into an array
|
||||
eoserial::Array* array = new eoserial::Array;
|
||||
eoserial::Array *array = new eoserial::Array;
|
||||
|
||||
for( int i = 0; i < size; ++i )
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
array->push_back( table[i].pack() );
|
||||
array->push_back(table[i].pack());
|
||||
}
|
||||
|
||||
// Encapsulates the array into an object
|
||||
eoserial::Object* obj = new eoserial::Object;
|
||||
obj->add( "array", array );
|
||||
eoserial::Object *obj = new eoserial::Object;
|
||||
obj->add("array", array);
|
||||
std::stringstream ss;
|
||||
obj->print( ss );
|
||||
obj->print(ss);
|
||||
delete obj;
|
||||
|
||||
// Sends the object as a string
|
||||
send( dest, tag, ss.str() );
|
||||
send(dest, tag, ss.str());
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -249,7 +247,7 @@ namespace mpi
|
|||
* @param tag MPI tag of message
|
||||
* @param persistent Where to unpack the serialized object?
|
||||
*/
|
||||
void recv( int src, int tag, eoserial::Persistent & persistent );
|
||||
void recv(int src, int tag, eoserial::Persistent &persistent);
|
||||
|
||||
/*
|
||||
* @brief Receives an array of eoserial::Persistent from src on channel "tag".
|
||||
|
|
@ -261,21 +259,21 @@ namespace mpi
|
|||
* @param size The number of elements to receive (no check is done, the user has to be sure that the size won't
|
||||
* overflow!)
|
||||
*/
|
||||
template< class T >
|
||||
void recv( int src, int tag, T* table, int size )
|
||||
template <class T>
|
||||
void recv(int src, int tag, T *table, int size)
|
||||
{
|
||||
// Receives the string which contains the object
|
||||
std::string asText;
|
||||
recv( src, tag, asText );
|
||||
recv(src, tag, asText);
|
||||
|
||||
// Parses the object and retrieves the table
|
||||
eoserial::Object* obj = eoserial::Parser::parse( asText );
|
||||
eoserial::Array* array = static_cast<eoserial::Array*>( (*obj)["array"] );
|
||||
eoserial::Object *obj = eoserial::Parser::parse(asText);
|
||||
eoserial::Array *array = static_cast<eoserial::Array *>((*obj)["array"]);
|
||||
|
||||
// Retrieves all the values from the array
|
||||
for( int i = 0; i < size; ++i )
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
eoserial::unpackObject( *array, i, table[i] );
|
||||
eoserial::unpackObject(*array, i, table[i]);
|
||||
}
|
||||
delete obj;
|
||||
}
|
||||
|
|
@ -293,7 +291,7 @@ namespace mpi
|
|||
* @param src MPI rank of the sender (any_source if it can be any sender)
|
||||
* @param tag MPI tag of the expected message (any_tag if it can be any tag)
|
||||
*/
|
||||
status probe( int src = any_source, int tag = any_tag );
|
||||
status probe(int src = any_source, int tag = any_tag);
|
||||
|
||||
/**
|
||||
* @brief Wrapper for MPI_Barrier
|
||||
|
|
@ -306,7 +304,7 @@ namespace mpi
|
|||
int _rank;
|
||||
int _size;
|
||||
|
||||
char* _buf; // temporary buffer for sending and receiving strings. Avoids reallocations
|
||||
char *_buf; // temporary buffer for sending and receiving strings. Avoids reallocations
|
||||
int _bufsize; // size of the above temporary buffer
|
||||
};
|
||||
|
||||
|
|
@ -321,12 +319,12 @@ namespace mpi
|
|||
*
|
||||
* @todo Actually comm isn't used and broadcast is performed on the whole MPI_COMM_WORLD. TODO: Use comm instead
|
||||
*/
|
||||
void broadcast( communicator & comm, int value, int root );
|
||||
void broadcast(communicator &comm, int value, int root);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
} // namespace mpi
|
||||
} // namespace mpi
|
||||
} // namespace eo
|
||||
|
||||
# endif //__EO_IMPL_MPI_HPP__
|
||||
#endif //__EO_IMPL_MPI_HPP__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue