Commit af62847e authored by BRAMAS Berenger's avatar BRAMAS Berenger
Browse files

update mpi stuffs

parent 12ddcfcb
......@@ -29,21 +29,35 @@
* finally use data pointer as you like
*/
class FMpiBufferReader : public FAbstractBufferReader {
const MPI_Comm comm; //< Communicator needed by MPI_Pack functions
const int arrayCapacity; //< Allocated space
MPI_Comm comm; //< Communicator needed by MPI_Pack functions
int arrayCapacity; //< Allocated space
std::unique_ptr<char[]> array; //< Allocated Array
int currentIndex;
public :
/*Constructor with a default arrayCapacity of 512 bytes */
FMpiBufferReader(const MPI_Comm inComm, const int inCapacity = 512):
explicit FMpiBufferReader(const MPI_Comm inComm = MPI_COMM_WORLD, const int inDefaultCapacity = 512):
comm(inComm),
arrayCapacity(inCapacity),
array(new char[inCapacity]),
arrayCapacity(inDefaultCapacity),
array(new char[inDefaultCapacity]),
currentIndex(0){
FAssertLF(array, "Cannot allocate array");
}
/** Change the comm (or to set it later) */
void setComm(const MPI_Comm inComm){
comm = inComm;
}
/** To change the capacity (but reset the head to 0) */
void cleanAndResize(const int newCapacity){
if(newCapacity != arrayCapacity){
arrayCapacity = newCapacity;
array.reset(new char[newCapacity]);
}
currentIndex = 0;
}
/** Destructor
*/
virtual ~FMpiBufferReader(){
......
......@@ -29,25 +29,47 @@
* finally use data pointer as you like
*/
class FMpiBufferWriter : public FAbstractBufferWriter {
const MPI_Comm mpiComm; //< Communicator needed by MPI_Pack functions
const int arrayCapacity; //< Allocated Space
MPI_Comm mpiComm; //< Communicator needed by MPI_Pack functions
int arrayCapacity; //< Allocated Space
std::unique_ptr<char[]> array; //< Allocated Array
int currentIndex; //< Currently filled space
/** Test and exit if not enought space */
void assertRemainingSpace(const size_t requestedSpace) const {
FAssertLF(int(currentIndex + requestedSpace) <= arrayCapacity, "Error FMpiBufferWriter has not enough space");
void expandIfNeeded(const size_t requestedSpace) {
if( arrayCapacity < int(currentIndex + requestedSpace) ){
arrayCapacity = int((currentIndex + requestedSpace + 1) * 1.5);
char* arrayTmp = new char[arrayCapacity];
memcpy(arrayTmp, array.get(), sizeof(char)*currentIndex);
array.reset(arrayTmp);
}
}
public:
/** Constructor with a default arrayCapacity of 512 bytes */
FMpiBufferWriter(const MPI_Comm inComm, const int inCapacity = 1024):
explicit FMpiBufferWriter(const MPI_Comm inComm, const int inDefaultCapacity = 1024):
mpiComm(inComm),
arrayCapacity(inCapacity),
array(new char[inCapacity]),
arrayCapacity(inDefaultCapacity),
array(new char[inDefaultCapacity]),
currentIndex(0)
{}
/** Change the comm (or to set it later) */
void setComm(const MPI_Comm inComm){
mpiComm = inComm;
}
/** To change the capacity (but reset the head to 0 if size if lower) */
void resize(const int newCapacity){
if(newCapacity != arrayCapacity){
arrayCapacity = newCapacity;
char* arrayTmp = new char[arrayCapacity];
currentIndex = (currentIndex < arrayCapacity ? currentIndex : arrayCapacity-1);
memcpy(arrayTmp, array.get(), sizeof(char)*currentIndex);
array.reset(arrayTmp);
}
}
/** Destructor */
virtual ~FMpiBufferWriter(){
}
......@@ -75,7 +97,7 @@ public:
/** Write data by packing cpy */
template <class ClassType>
void write(const ClassType& object){
assertRemainingSpace(sizeof(ClassType));
expandIfNeeded(sizeof(ClassType));
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &currentIndex, mpiComm);
}
......@@ -84,7 +106,7 @@ public:
*/
template <class ClassType>
void write(const ClassType&& object){
assertRemainingSpace(sizeof(ClassType));
expandIfNeeded(sizeof(ClassType));
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &currentIndex, mpiComm);
}
......@@ -101,7 +123,7 @@ public:
*/
template <class ClassType>
void write(const ClassType* const objects, const int inSize){
assertRemainingSpace(sizeof(ClassType) * inSize);
expandIfNeeded(sizeof(ClassType) * inSize);
MPI_Pack( const_cast<ClassType*>(objects), inSize, FMpi::GetType(*objects), array.get(), arrayCapacity, &currentIndex, mpiComm);
}
......
......@@ -68,6 +68,7 @@ public:
// FMM
TagFmmM2M = 1000,
TagFmmM2MSize = 1500,
TagFmmL2L = 2000,
TagFmmP2P = 3000,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment