Commit 1b7971f9 authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille

FMpiBuffer reader and writer are ok. There are only used by...

FMpiBuffer reader and writer are ok. There are only used by FFmmAlgorithmThreadProc :: M2M for the test. Changes will be spread out everywhere.
parent 52fab931
......@@ -51,6 +51,18 @@ public:
FExtendCoordinate::restore(buffer);
}
/** Save the current cell in a buffer */
void save(FMpiBufferWriter& buffer) const{
FExtendMortonIndex::save(buffer);
FExtendCoordinate::save(buffer);
}
/** Restore the current cell from a buffer */
void restore(FMpiBufferReader& buffer){
FExtendMortonIndex::restore(buffer);
FExtendCoordinate::restore(buffer);
}
/** Do nothing */
void resetToInitialState(){
}
......
......@@ -16,7 +16,8 @@
#ifndef FTESTCELL_HPP
#define FTESTCELL_HPP
#include "../Containers/FMpiBufferReader.hpp"
#include "../Containers/FMpiBufferWriter.hpp"
#include "FBasicCell.hpp"
/**
......@@ -93,6 +94,44 @@ public:
void deserializeDown(FBufferReader& buffer){
buffer >> this->dataDown;
}
/////////////////////////////////////////////////////
/////////////// Test with FMpiBuffer* /////////////
/////////////////////////////////////////////////////
/** Save the current cell in a buffer */
void save(FMpiBufferWriter& buffer) const{
FBasicCell::save(buffer);
buffer << dataDown << dataUp;
}
/** Restore the current cell from a buffer */
void restore(FMpiBufferReader& buffer){
FBasicCell::restore(buffer);
buffer >> dataDown >> dataUp;
}
/////////////////////////////////////////////////
/** Serialize only up data in a buffer */
void serializeUp(FMpiBufferWriter& buffer) const {
buffer << this->dataUp;
}
/** Deserialize only up data in a buffer */
void deserializeUp(FMpiBufferReader& buffer){
buffer >> this->dataUp;
}
/** Serialize only down data in a buffer */
void serializeDown(FMpiBufferWriter& buffer) const {
buffer << this->dataDown;
}
/** Deserialize only up data in a buffer */
void deserializeDown(FMpiBufferReader& buffer){
buffer >> this->dataDown;
}
};
......
......@@ -124,7 +124,6 @@ public :
/** Destructor
*/
virtual ~FMpiBufferReader(){
delete &array;
}
/** Get the memory area */
......@@ -156,9 +155,9 @@ public :
template <class ClassType>
ClassType getValue(){
ClassType value;
long int currentIndex = array.getSize();
int currentIndex = array.getSize();
array.incIndex(sizeof(value));
MPI_Unpack(array.data(),sizeof(ClassType),&currentIndex,&value,1,FMpi::GetType(value),*comm);
MPI_Unpack(array.data(),sizeof(ClassType),&currentIndex,&value,1,FMpi::GetType(value),comm);
return value;
}
......@@ -167,7 +166,7 @@ public :
void fillValue(ClassType* const inValue){
int currentIndex = array.getSize();
array.incIndex(sizeof(ClassType));
MPI_Pack(inValue,1,FMpi::GetType(inValue),array.data(),array.getCapacity(),&currentIndex,*comm);
MPI_Pack(inValue,1,FMpi::GetType(*inValue),array.data(),array.getCapacity(),&currentIndex,comm);
}
/** Fill one/many value(s) with memcpy */
......@@ -175,12 +174,12 @@ public :
void fillArray(ClassType* const inArray, const int inSize){
int currentIndex = array.getSize();
array.incIndex(sizeof(ClassType) * inSize);
MPI_Pack(inArray,inSize,FMpi::GetType(inArray),array.data(),array.getCapacity(),&currentIndex,*comm);
MPI_Pack(inArray,inSize,FMpi::GetType(*inArray),array.data(),array.getCapacity(),&currentIndex,comm);
}
/** Same as fillValue */
template <class ClassType>
FBufferReader& operator>>(ClassType& object){
FMpiBufferReader& operator>>(ClassType& object){
fillValue(&object);
return *this;
}
......
......@@ -124,7 +124,6 @@ public:
/** Destructor */
virtual ~FMpiBufferWriter(){
delete &array;
}
/** Get allocated memory pointer */
......@@ -165,17 +164,17 @@ public:
/** Write back, position + sizeof(object) has to be < size */
template <class ClassType>
void writeAt(const int position, const ClassType& object){
//(*reinterpret_cast<ClassType*>(&buffer[position])) = object;
if(position < array.getSize()){
fprintf(stderr,"Aborting : writeAt is overwritting data\n");
}
else{
int temp = position;
if(position + FMpi::GetType(object) < array.getCapacity()){
MPI_Pack(&object,1,FMpi::GetType(object),array.data(),array.getCapacity(),&temp,comm);
}
array.setIndex(temp);
// //(*reinterpret_cast<ClassType*>(&buffer[position])) = object;
// if(position < array.getSize()){
// fprintf(stderr,"Aborting : writeAt is overwritting data\n");
// }
// else{
int temp = position;
if(position + ((int)sizeof(ClassType)) < array.getCapacity()){
MPI_Pack(const_cast<ClassType*>(&object),1,FMpi::GetType(object),array.data(),array.getCapacity(),&temp,comm);
}
array.setIndex(temp);
// }
}
/** Write an array
......
......@@ -93,14 +93,16 @@ class FOctree : protected FAssertable, public FNoCopyable {
* @return the box num at the leaf level that contains inRelativePosition
*/
int getTreeCoordinate(const FReal inRelativePosition) const {
FLOG( fassert(inRelativePosition >= 0 && inRelativePosition < this->boxWidth, "Particle out of box", __LINE__, __FILE__) );
const FReal indexFReal = inRelativePosition / this->boxWidthAtLevel[this->leafIndex];
/*const int index = int(FMath::dfloor(indexFReal));
if(!(inRelativePosition >= 0 && inRelativePosition < this->boxWidth))
printf("inRelativePosition : %f\n",inRelativePosition);
FLOG( fassert(inRelativePosition >= 0 && inRelativePosition < this->boxWidth, "Particle out of box", __LINE__, __FILE__) );
const FReal indexFReal = inRelativePosition / this->boxWidthAtLevel[this->leafIndex];
/*const int index = int(FMath::dfloor(indexFReal));
if( index && FMath::LookEqual(inRelativePosition, this->boxWidthAtLevel[this->leafIndex] * FReal(index) ) ){
return index - 1;
}
return index - 1;
}
return index;*/
return static_cast<int>(indexFReal);
return static_cast<int>(indexFReal);
}
public:
......
......@@ -21,6 +21,9 @@
#include "../Utils/FGlobal.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
#include "../Containers/FMpiBufferReader.hpp"
#include "../Containers/FMpiBufferWriter.hpp"
#include "../Utils/FMath.hpp"
/**
......@@ -256,6 +259,21 @@ public:
buffer >> data[0] >> data[1] >> data[2];
}
/////////////////////////////////////////////////////
/////////////// Test with FMpiBuffer* /////////////
/////////////////////////////////////////////////////
/** Save current object */
void save(FMpiBufferWriter& buffer) const {
buffer << data[0] << data[1] << data[2];
}
/** Retrieve current object */
void restore(FMpiBufferReader& buffer) {
buffer >> data[0] >> data[1] >> data[2];
}
static std::string MortonToBinary(MortonIndex index, int level){
std::string str;
int bits = 1 << ((level * 3) - 1);
......
......@@ -31,6 +31,8 @@
#include "../Containers/FBufferWriter.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FMpiBufferWriter.hpp"
#include "../Containers/FMpiBufferReader.hpp"
#include "../Utils/FMpi.hpp"
......@@ -200,6 +202,7 @@ public:
if(operationsToProceed & FFmmP2M) bottomPass();
if(operationsToProceed & FFmmM2M) upwardPass();
printf("So far so good \n");
if(operationsToProceed & FFmmM2L) transferPass();
......@@ -248,6 +251,7 @@ private:
FLOG( FLog::Controller << "\tFinished (@Bottom Pass (P2M) = " << counterTime.tacAndElapsed() << "s)\n" );
FLOG( FLog::Controller << "\t\t Computation : " << computationCounter.elapsed() << " s\n" );
}
/////////////////////////////////////////////////////////////////////////////
......@@ -278,9 +282,9 @@ private:
MPI_Status status[14];
// Maximum data per message is:
FBufferWriter sendBuffer;
FMpiBufferWriter sendBuffer(comm.getComm());
const int recvBufferOffset = 8 * MaxSizePerCell + 1;
FBufferReader recvBuffer(nbProcess * recvBufferOffset);
FMpiBufferReader recvBuffer(comm.getComm(), nbProcess * recvBufferOffset);
CellClass recvBufferCells[8];
int firstProcThatSend = idProcess + 1;
......@@ -333,7 +337,7 @@ private:
--sendToProc;
}
MPI_Isend(sendBuffer.data(), sendBuffer.getSize(), MPI_BYTE, sendToProc, FMpi::TagFmmM2M, comm.getComm(), &requests[iterRequests++]);
MPI_Isend(sendBuffer.data(), sendBuffer.getSize(), MPI_PACKED, sendToProc, FMpi::TagFmmM2M, comm.getComm(), &requests[iterRequests++]);
}
// We may need to receive something
......@@ -361,7 +365,7 @@ private:
hasToReceive = true;
for(int idxProc = firstProcThatSend ; idxProc < endProcThatSend ; ++idxProc ){
MPI_Irecv(&recvBuffer.data()[idxProc * recvBufferOffset], recvBufferOffset, MPI_BYTE,
MPI_Irecv(&recvBuffer.data()[idxProc * recvBufferOffset], recvBufferOffset, MPI_PACKED,
idxProc, FMpi::TagFmmM2M, comm.getComm(), &requests[iterRequests++]);
}
}
......@@ -425,7 +429,6 @@ private:
firstProcThatSend = endProcThatSend - 1;
}
}
sendBuffer.reset();
recvBuffer.seek(0);
}
......@@ -435,7 +438,7 @@ private:
FLOG( FLog::Controller << "\t\t Computation : " << computationCounter.cumulated() << " s\n" );
FLOG( FLog::Controller << "\t\t Prepare : " << prepareCounter.cumulated() << " s\n" );
FLOG( FLog::Controller << "\t\t Wait : " << waitCounter.cumulated() << " s\n" );
printf("Almost finished\n");
}
/////////////////////////////////////////////////////////////////////////////
......@@ -1064,14 +1067,14 @@ private:
}
// Prepare receive
//Prepare receive
for(int idxProc = 0 ; idxProc < nbProcess ; ++idxProc){
if(globalReceiveMap[idxProc * nbProcess + idProcess]){ //if idxProc has sth for me.
//allocate buffer of right size
recvBuffer[idxProc] = new FBufferReader(globalReceiveMap[idxProc * nbProcess + idProcess]);
FMpi::MpiAssert( MPI_Irecv(recvBuffer[idxProc]->data(), recvBuffer[idxProc]->getSize(), MPI_BYTE,
idxProc, FMpi::TagFmmP2P, comm.getComm(), &requests[iterRequest++]) , __LINE__ );
}
if(globalReceiveMap[idxProc * nbProcess + idProcess]){ //if idxProc has sth for me.
//allocate buffer of right size
recvBuffer[idxProc] = new FBufferReader(globalReceiveMap[idxProc * nbProcess + idProcess]);
FMpi::MpiAssert( MPI_Irecv(recvBuffer[idxProc]->data(), recvBuffer[idxProc]->getSize(), MPI_BYTE,
idxProc, FMpi::TagFmmP2P, comm.getComm(), &requests[iterRequest++]) , __LINE__ );
}
}
nbMessagesToRecv = iterRequest;
......@@ -1080,7 +1083,7 @@ private:
if(toSend[idxProc].getSize() != 0){
//sendBuffer[idxProc] = new FBufferWriter(partsToSend[idxProc]); //Could be read out of globalReceiveMap
sendBuffer[idxProc] = new FBufferWriter(globalReceiveMap[idProcess*nbProcess+idxProc]);
// << is equivalent of write().
// << is equivalent to write().
(*sendBuffer[idxProc]) << toSend[idxProc].getSize();
for(int idxLeaf = 0 ; idxLeaf < toSend[idxProc].getSize() ; ++idxLeaf){
(*sendBuffer[idxProc]) << toSend[idxProc][idxLeaf].getCurrentGlobalIndex();
......@@ -1089,22 +1092,12 @@ private:
//TEST BERENGER
//if(sendBuffer[idxProc]->getSize() != partsToSend[idxProc]){
// {
// MPI_Barrier(MPI_COMM_WORLD);
// printf("Proc %d :: \t sizeof SendBuffer %d \t sizeof partToSend%d \t diff %d \t sizeof RecvBuffer%d\n",
// idProcess,sendBuffer[idxProc]->getSize(),partsToSend[idxProc],sendBuffer[idxProc]->getSize() - partsToSend[idxProc],
// recvBuffer[idxProc]->getSize()+1032);
// MPI_Barrier(MPI_COMM_WORLD);
// }
FMpi::MpiAssert( MPI_Isend( sendBuffer[idxProc]->data(), sendBuffer[idxProc]->getSize() , MPI_BYTE ,
idxProc, FMpi::TagFmmP2P, comm.getComm(), &requests[iterRequest++]) , __LINE__ );
}
}
delete[] toSend;
}
FLOG(prepareCounter.tac());
......
......@@ -21,6 +21,8 @@
#include "../Containers/FTreeCoordinate.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
#include "../Containers/FMpiBufferReader.hpp"
#include "../Containers/FMpiBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -74,6 +76,20 @@ public:
void restore(FBufferReader& buffer) {
coordinate.restore(buffer);
}
/////////////////////////////////////////////////////
/////////////// Test with FMpiBuffer* /////////////
/////////////////////////////////////////////////////
/** Save current object */
void save(FMpiBufferWriter& buffer) const {
coordinate.save(buffer);
}
/** Retrieve current object */
void restore(FMpiBufferReader& buffer) {
coordinate.restore(buffer);
}
};
......
......@@ -21,6 +21,9 @@
#include "../Containers/FTreeCoordinate.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
#include "../Containers/FMpiBufferReader.hpp"
#include "../Containers/FMpiBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -66,6 +69,21 @@ public:
void restore(FBufferReader& buffer) {
buffer >> mortonIndex;
}
/////////////////////////////////////////////////////
/////////////// Test with FMpiBuffer* /////////////
/////////////////////////////////////////////////////
/** Save current object */
void save(FMpiBufferWriter& buffer) const {
buffer << mortonIndex;
}
/** Retrieve current object */
void restore(FMpiBufferReader& buffer) {
buffer >> mortonIndex;
}
};
......
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