Commit 15ffd99b authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille

Forgot to commit this one

parent ea5984ac
...@@ -24,66 +24,66 @@ ...@@ -24,66 +24,66 @@
#include "FAbstractLoader.hpp" #include "FAbstractLoader.hpp"
#include "../Utils/FPoint.hpp" #include "../Utils/FPoint.hpp"
#include "../Utils/FMpi.hpp" #include "../Utils/FMpi.hpp"
#include "../Utils/FLog.hpp"
/** /**
* @author Berenger Bramas (berenger.bramas@inria.fr) * @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FMpiFmaLoader * @class FMpiFmaLoader
* Please read the license * Please read the license
* *
* Load a file with a format like : * Load a file with a format like :
* NB_particles Box_width Box_X Box_Y Box_Z // init * NB_particles Box_width Box_X Box_Y Box_Z // init
* X Y Z // one particle by line * X Y Z // one particle by line
* .... * ....
* @code * @code
* FMpiFmaLoader<FBasicParticle> loader("../ADir/Tests/particles.basic.txt"); <br> * FMpiFmaLoader<FBasicParticle> loader("../ADir/Tests/particles.basic.txt"); <br>
* if(!loader.isOpen()){ <br> * if(!loader.isOpen()){ <br>
* std::cout << "Loader Error\n"; <br> * std::cout << "Loader Error\n"; <br>
* return 1; <br> * return 1; <br>
* } <br> * } <br>
* <br> * <br>
* FOctree<FBasicParticle, TestCell, FSimpleLeaf> tree(loader.getBoxWidth(),loader.getCenterOfBox()); <br> * FOctree<FBasicParticle, TestCell, FSimpleLeaf> tree(loader.getBoxWidth(),loader.getCenterOfBox()); <br>
* <br> * <br>
* for(int idx = 0 ; idx < loader.getNumberOfParticles() ; ++idx){ <br> * for(int idx = 0 ; idx < loader.getNumberOfParticles() ; ++idx){ <br>
* FBasicParticle* const part = new FBasicParticle(); <br> * FBasicParticle* const part = new FBasicParticle(); <br>
* loader.fillParticle(part); <br> * loader.fillParticle(part); <br>
* tree.insert(part); <br> * tree.insert(part); <br>
* } <br> * } <br>
* @endcode * @endcode
* *
* Particle has to extend {FExtendPhysicalValue,FExtendPosition} * Particle has to extend {FExtendPhysicalValue,FExtendPosition}
*/ */
class FMpiFmaLoader : public FAbstractLoader { class FMpiFmaLoader : public FAbstractLoader {
protected: protected:
FPoint centerOfBox; //< The center of box read from file FPoint centerOfBox; //< The center of box read from file
FReal boxWidth; //< the box width read from file FReal boxWidth; //< the box width read from file
FSize totalNbParticles; //< the number of particles read from file FSize totalNbParticles; //< the number of particles read from file
FSize nbParticles; //< the number of particles read from file FSize nbParticles; //< the number of particles read from file for this proc
bool isOpenFlag; //< to knwo if the file is open now bool isOpenFlag; //< to knwo if the file is open now
FReal* particles; //< the particles loaded from the binary file FReal* particles; //< the particles loaded from the binary file
MPI_Offset idxParticles; //< to iterate on the particles array MPI_Offset idxParticles; //< to iterate on the particles array
int start;
public: public:
/** /**
* The constructor need the file name * The constructor need txhe file name
* @param filename the name of the file to open * @param filename the name of the file to open
* you can test if file is successfuly open by calling hasNotFinished() * you can test if file is successfuly open by calling hasNotFinished()
*/ */
FMpiFmaLoader(const char* const filename, const FMpi::FComm& comm, const bool useMpiIO = false) FMpiFmaLoader(const char* const filename, const FMpi::FComm& comm, const bool useMpiIO = false)
: boxWidth(0), totalNbParticles(0), nbParticles(0), isOpenFlag(false), particles(0), idxParticles(0) { : boxWidth(0), totalNbParticles(0), nbParticles(0), isOpenFlag(false), particles(0), idxParticles(0), start(0) {
if( useMpiIO ){ if( useMpiIO ){
char nonConstFilename[512]; char nonConstFilename[512];
strcpy(nonConstFilename,filename); strcpy(nonConstFilename,filename);
MPI_File file; MPI_File file;
if(MPI_File_open(comm.getComm(), nonConstFilename, MPI_MODE_RDONLY, MPI_INFO_NULL, &file) == MPI_SUCCESS){ if(MPI_File_open(comm.getComm(), nonConstFilename, MPI_MODE_RDONLY, MPI_INFO_NULL, &file) == MPI_SUCCESS){
int sizeOfElement(0); int sizeOfElement(0);
FReal xyzBoxWidth[4]; FReal xyzBoxWidth[4];
MPI_Status status; MPI_Status status;
if( MPI_File_read(file, &sizeOfElement, 1, MPI_INT, &status) == MPI_SUCCESS if( MPI_File_read(file, &sizeOfElement, 1, MPI_INT, &status) == MPI_SUCCESS
&& MPI_File_read(file, &this->totalNbParticles, 1, MPI_LONG_LONG, &status) == MPI_SUCCESS && MPI_File_read(file, &this->totalNbParticles, 1, MPI_LONG_LONG, &status) == MPI_SUCCESS
&& MPI_File_read(file, xyzBoxWidth, 4, FMpi::GetType(xyzBoxWidth[0]), &status) == MPI_SUCCESS ){ && MPI_File_read(file, xyzBoxWidth, 4, FMpi::GetType(xyzBoxWidth[0]), &status) == MPI_SUCCESS ){
FLOG(if(sizeOfElement != sizeof(FReal)){) FLOG(if(sizeOfElement != sizeof(FReal)){)
FLOG( FLog::Controller.writeFromLine("Warning type size between file and FReal are differents\n", __LINE__, __FILE__); ) FLOG( FLog::Controller.writeFromLine("Warning type size between file and FReal are differents\n", __LINE__, __FILE__); )
FLOG(}) FLOG(})
...@@ -106,6 +106,7 @@ public: ...@@ -106,6 +106,7 @@ public:
const FSize startPart = comm.getLeft(this->totalNbParticles); const FSize startPart = comm.getLeft(this->totalNbParticles);
const FSize endPart = comm.getRight(this->totalNbParticles); const FSize endPart = comm.getRight(this->totalNbParticles);
nbParticles = (endPart - startPart); nbParticles = (endPart - startPart);
this->start = int(startPart);
const FSize bufsize = nbParticles * 4; const FSize bufsize = nbParticles * 4;
// local number to read // local number to read
particles = new FReal[bufsize]; particles = new FReal[bufsize];
...@@ -160,10 +161,11 @@ public: ...@@ -160,10 +161,11 @@ public:
const FSize startPart = comm.getLeft(this->totalNbParticles); const FSize startPart = comm.getLeft(this->totalNbParticles);
const FSize endPart = comm.getRight(this->totalNbParticles); const FSize endPart = comm.getRight(this->totalNbParticles);
nbParticles = (endPart - startPart); nbParticles = (endPart - startPart);
this->start = int(startPart);
const FSize bufsize = nbParticles * 4; const FSize bufsize = nbParticles * 4;
// local number to read // local number to read
particles = new FReal[bufsize]; particles = new FReal[bufsize];
fseek(file, long(headDataOffSet + startPart * 4 * sizeof(FReal)), SEEK_SET); fseek(file, long(headDataOffSet + startPart * 4 * sizeof(FReal)), SEEK_SET);
if( fread(particles, sizeof(FReal), int(bufsize), file) != unsigned(bufsize)){ if( fread(particles, sizeof(FReal), int(bufsize), file) != unsigned(bufsize)){
...@@ -194,13 +196,21 @@ public: ...@@ -194,13 +196,21 @@ public:
} }
/** /**
* To get the number of particles from this loader * To get the number of particles to be used by this proc from this loader
* @param the number of particles the loader can fill * @param the number of particles for this proc the loader can fill
*/ */
FSize getNumberOfParticles() const{ FSize getNumberOfParticles() const{
return this->nbParticles; return this->nbParticles;
} }
/**
* To get the number of particles to be used by this proc from this loader
* @param the number of particles for this proc the loader can fill
*/
FSize getTotalNumberOfParticles() const{
return this->totalNbParticles;
}
/** /**
* The center of the box from the simulation file opened by the loader * The center of the box from the simulation file opened by the loader
* @return box center * @return box center
...@@ -217,6 +227,15 @@ public: ...@@ -217,6 +227,15 @@ public:
return this->boxWidth; return this->boxWidth;
} }
/**
* The starting index of calling processus
* @return start
*/
int getStart() const{
return int(this->start);
}
/** /**
* Fill a particle * Fill a particle
* @warning to work with the loader, particles has to expose a setPosition method * @warning to work with the loader, particles has to expose a setPosition method
......
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