Commit c22ccd0a authored by BRAMAS Berenger's avatar BRAMAS Berenger

move to new periodic

parent b1d39835
...@@ -9,7 +9,7 @@ project(Lib_scalfmm) ...@@ -9,7 +9,7 @@ project(Lib_scalfmm)
set(LIBRARY_OUTPUT_PATH ../lib/${CMAKE_BUILD_TYPE}) set(LIBRARY_OUTPUT_PATH ../lib/${CMAKE_BUILD_TYPE})
ADD_DEFINITIONS(${ScaLFMM_CXX_FLAGS}) ADD_DEFINITIONS(${ScaLFMM_CXX_FLAGS})
MESSAGE( ${ScaLFMM_CXX_FLAGS})
# Searching all cpp file # Searching all cpp file
file( file(
GLOB_RECURSE GLOB_RECURSE
......
...@@ -29,111 +29,103 @@ ...@@ -29,111 +29,103 @@
* finally use data pointer as you like * finally use data pointer as you like
*/ */
class FMpiBufferReader : public FAbstractBufferReader { class FMpiBufferReader : public FAbstractBufferReader {
const MPI_Comm comm; //< Communicator needed by MPI_Pack functions const MPI_Comm comm; //< Communicator needed by MPI_Pack functions
const int arrayCapacity; //< Allocated space const int arrayCapacity; //< Allocated space
std::unique_ptr<char[]> array; //< Allocated Array std::unique_ptr<char[]> array; //< Allocated Array
int currentIndex; int currentIndex;
/** Test and exit if not enought space */
void assertRemainingSpace(const size_t requestedSpace) const {
if(int(currentIndex + requestedSpace) > arrayCapacity){
printf("Error FMpiBufferReader has not enough space\n");
exit(0);
}
}
public : public :
/*Constructor with a default arrayCapacity of 512 bytes */ /*Constructor with a default arrayCapacity of 512 bytes */
FMpiBufferReader(const MPI_Comm inComm, const int inCapacity = 512): FMpiBufferReader(const MPI_Comm inComm, const int inCapacity = 512):
comm(inComm), comm(inComm),
arrayCapacity(inCapacity), arrayCapacity(inCapacity),
array(new char[inCapacity]), array(new char[inCapacity]),
currentIndex(0) currentIndex(0)
{} {}
/** Destructor /** Destructor
*/ */
virtual ~FMpiBufferReader(){ virtual ~FMpiBufferReader(){
} }
/** Get allocated memory pointer */ /** Get allocated memory pointer */
char* data(){ char* data(){
return array.get(); return array.get();
} }
/** Get allocated memory pointer */ /** Get allocated memory pointer */
const char* data() const { const char* data() const {
return array.get(); return array.get();
} }
/** get the filled space */ /** get the filled space */
int getSize() const{ int getSize() const{
return currentIndex; return currentIndex;
} }
/** Size of the memory initialized */ /** Size of the memory initialized */
int getCapacity() const{ int getCapacity() const{
return arrayCapacity; return arrayCapacity;
} }
/** Move the read index to a position */ /** Move the read index to a position */
void seek(const int inIndex){ void seek(const int inIndex){
if(inIndex > arrayCapacity){ if(inIndex > arrayCapacity){
printf("FMpiBufferReader :: Aborting :: Can't move index because buffer isn't long enough"); printf("FMpiBufferReader :: Aborting :: Can't move index because buffer isn't long enough");
exit(0); exit(0);
}
else{
currentIndex = inIndex;
}
} }
else{
currentIndex = inIndex; /** Get the read position */
int tell() const {
return currentIndex;
}
/** Get a value with memory cast */
template <class ClassType>
ClassType getValue(){
ClassType value;
int previousIndex = currentIndex;
seek(int(sizeof(value) + previousIndex));
MPI_Unpack(array.get(),arrayCapacity,&previousIndex,&value,1,FMpi::GetType(value),comm);
return value;
}
/** Get a value with memory cast at a specified index */
template <class ClassType>
ClassType getValue(const int ind){
ClassType value;
int previousIndex = ind;
seek(int(sizeof(value)+ind));
MPI_Unpack(array.get(),arrayCapacity,&previousIndex,&value,1,FMpi::GetType(value),comm);
return value;
}
/** Fill a value with memory cast */
template <class ClassType>
void fillValue(ClassType* const inValue){
int previousIndex = currentIndex;
seek(int(sizeof(ClassType) + previousIndex));
MPI_Unpack(array.get(),arrayCapacity,&previousIndex,inValue,1,FMpi::GetType(*inValue),comm);
}
/** Fill one/many value(s) with memcpy */
template <class ClassType>
void fillArray(ClassType* const inArray, const int inSize){
int previousIndex = currentIndex;
seek(int(sizeof(ClassType) * inSize + previousIndex));
MPI_Unpack(array.get(),arrayCapacity,&previousIndex,inArray,inSize,FMpi::GetType(*inArray),comm);
}
/** Same as fillValue */
template <class ClassType>
FMpiBufferReader& operator>>(ClassType& object){
fillValue(&object);
return *this;
} }
}
/** Get the read position */
int tell() const {
return currentIndex;
}
/** Get a value with memory cast */
template <class ClassType>
ClassType getValue(){
ClassType value;
int previousIndex = currentIndex;
seek(sizeof(value) + previousIndex);
MPI_Unpack(array.get(),arrayCapacity,&previousIndex,&value,1,FMpi::GetType(value),comm);
return value;
}
/** Get a value with memory cast at a specified index */
template <class ClassType>
ClassType getValue(const int ind){
ClassType value;
int previousIndex = ind;
seek(sizeof(value)+ind);
MPI_Unpack(array.get(),arrayCapacity,&previousIndex,&value,1,FMpi::GetType(value),comm);
return value;
}
/** Fill a value with memory cast */
template <class ClassType>
void fillValue(ClassType* const inValue){
int previousIndex = currentIndex;
seek(sizeof(ClassType) + previousIndex);
MPI_Unpack(array.get(),arrayCapacity,&previousIndex,inValue,1,FMpi::GetType(*inValue),comm);
}
/** Fill one/many value(s) with memcpy */
template <class ClassType>
void fillArray(ClassType* const inArray, const int inSize){
int previousIndex = currentIndex;
seek(sizeof(ClassType) * inSize + previousIndex);
MPI_Unpack(array.get(),arrayCapacity,&previousIndex,inArray,inSize,FMpi::GetType(*inArray),comm);
}
/** Same as fillValue */
template <class ClassType>
FMpiBufferReader& operator>>(ClassType& object){
fillValue(&object);
return *this;
}
}; };
#endif #endif
......
...@@ -28,102 +28,99 @@ ...@@ -28,102 +28,99 @@
* finally use data pointer as you like * finally use data pointer as you like
*/ */
class FMpiBufferWriter : public FAbstractBufferWriter { class FMpiBufferWriter : public FAbstractBufferWriter {
const MPI_Comm mpiComm; //< Communicator needed by MPI_Pack functions const MPI_Comm mpiComm; //< Communicator needed by MPI_Pack functions
const int arrayCapacity; //< Allocated Space const int arrayCapacity; //< Allocated Space
std::unique_ptr<char[]> array; //< Allocated Array std::unique_ptr<char[]> array; //< Allocated Array
int currentIndex; //< Currently filled space int currentIndex; //< Currently filled space
/** Test and exit if not enought space */ /** Test and exit if not enought space */
void assertRemainingSpace(const size_t requestedSpace) const { void assertRemainingSpace(const size_t requestedSpace) const {
if(int(currentIndex + requestedSpace) > arrayCapacity){ if(int(currentIndex + requestedSpace) > arrayCapacity){
printf("Error FMpiBufferWriter has not enough space\n"); printf("Error FMpiBufferWriter has not enough space\n");
exit(0); exit(0);
}
} }
}
public: public:
/** Constructor with a default arrayCapacity of 512 bytes */ /** Constructor with a default arrayCapacity of 512 bytes */
FMpiBufferWriter(const MPI_Comm inComm, const int inCapacity = 1024): FMpiBufferWriter(const MPI_Comm inComm, const int inCapacity = 1024):
mpiComm(inComm), mpiComm(inComm),
arrayCapacity(inCapacity), arrayCapacity(inCapacity),
array(new char[inCapacity]), array(new char[inCapacity]),
currentIndex(0) currentIndex(0)
{} {}
/** Destructor */ /** Destructor */
virtual ~FMpiBufferWriter(){ virtual ~FMpiBufferWriter(){
} }
/** Get allocated memory pointer */ /** Get allocated memory pointer */
char* data(){ char* data(){
return array.get(); return array.get();
} }
/** Get allocated memory pointer */ /** Get allocated memory pointer */
const char* data() const { const char* data() const {
return array.get(); return array.get();
} }
/** Get the filled space */ /** Get the filled space */
int getSize() const { int getSize() const {
return currentIndex; return currentIndex;
} }
/** Get the allocated space */ /** Get the allocated space */
int getCapacity() const { int getCapacity() const {
return arrayCapacity; return arrayCapacity;
} }
/** Write data by packing cpy */ /** Write data by packing cpy */
template <class ClassType> template <class ClassType>
void write(const ClassType& object){ void write(const ClassType& object){
//printf("Space need in the write : %d, index set on %d \n",sizeof(ClassType),currentIndex); assertRemainingSpace(sizeof(ClassType));
assertRemainingSpace(sizeof(ClassType)); MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &currentIndex, mpiComm);
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &currentIndex, mpiComm); }
}
/**
/**
* Allow to pass rvalue to write * Allow to pass rvalue to write
*/ */
template <class ClassType> template <class ClassType>
void write(const ClassType&& object){ void write(const ClassType&& object){
// printf("Space need in the write : %d \n",sizeof(ClassType)); assertRemainingSpace(sizeof(ClassType));
assertRemainingSpace(sizeof(ClassType)); MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &currentIndex, mpiComm);
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &currentIndex, mpiComm);
}
/** Write back, position + sizeof(object) has to be < size */
template <class ClassType>
void writeAt(const int position, const ClassType& object){
if(position + (int) sizeof(ClassType) > currentIndex){
printf("Not enought space\n");
exit(0);
} }
int noConstPosition = position;
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &noConstPosition, mpiComm);
}
/** Write an array /** Write back, position + sizeof(object) has to be < size */
template <class ClassType>
void writeAt(const int position, const ClassType& object){
if(position + (int) sizeof(ClassType) > currentIndex){
printf("Not enought space\n");
exit(0);
}
int noConstPosition = position;
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &noConstPosition, mpiComm);
}
/** Write an array
* Warning : inSize is a number of ClassType object to write, not a size in bytes * Warning : inSize is a number of ClassType object to write, not a size in bytes
*/ */
template <class ClassType> template <class ClassType>
void write(const ClassType* const objects, const int inSize){ void write(const ClassType* const objects, const int inSize){
// printf("Space need in the write : %d, index set on %d, and capacity is %d \n",sizeof(ClassType)*inSize,currentIndex,arrayCapacity); assertRemainingSpace(sizeof(ClassType) * inSize);
assertRemainingSpace(sizeof(ClassType) * inSize); MPI_Pack( const_cast<ClassType*>(objects), inSize, FMpi::GetType(*objects), array.get(), arrayCapacity, &currentIndex, mpiComm);
MPI_Pack( const_cast<ClassType*>(objects), inSize, FMpi::GetType(*objects), array.get(), arrayCapacity, &currentIndex, mpiComm); }
}
/** Equivalent to write */
/** Equivalent to write */ template <class ClassType>
template <class ClassType> FMpiBufferWriter& operator<<(const ClassType& object){
FMpiBufferWriter& operator<<(const ClassType& object){ write(object);
write(object); return *this;
return *this; }
}
/** Reset the writing index, but do not change the arrayCapacity */
/** Reset the writing index, but do not change the arrayCapacity */ void reset(){
void reset(){ currentIndex = 0;
currentIndex = 0; }
}
}; };
......
...@@ -69,13 +69,13 @@ public: ...@@ -69,13 +69,13 @@ public:
template<class OctreeClass, class CellClass, class ContainerClass, class KernelClass, class LeafClass> template<class OctreeClass, class CellClass, class ContainerClass, class KernelClass, class LeafClass>
static FAbstractAlgorithm* BuildAlgorithm(OctreeClass*const tree, KernelClass*const kernel, static FAbstractAlgorithm* BuildAlgorithm(OctreeClass*const tree, KernelClass*const kernel,
const MPI_Comm mpiComm = (MPI_Comm)0, const bool isPeriodic = false, const MPI_Comm mpiComm = (MPI_Comm)0, const bool isPeriodic = false,
const int periodicUpperlevel = 0, const int inPeriodicDirections = AllDirs){ const int periodicUpperlevel = 0){
#ifdef ScalFMM_USE_MPI #ifdef ScalFMM_USE_MPI
if(isPeriodic == false){ if(isPeriodic == false){
return new FFmmAlgorithmThreadProc<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(FMpi::FComm(mpiComm), tree, kernel); return new FFmmAlgorithmThreadProc<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(FMpi::FComm(mpiComm), tree, kernel);
} }
else{ else{
auto algo = new FFmmAlgorithmThreadProcPeriodic<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(FMpi::FComm(mpiComm), tree, periodicUpperlevel, inPeriodicDirections); auto algo = new FFmmAlgorithmThreadProcPeriodic<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(FMpi::FComm(mpiComm), tree, periodicUpperlevel);
algo->setKernel(kernel); algo->setKernel(kernel);
return algo; return algo;
} }
...@@ -84,7 +84,7 @@ public: ...@@ -84,7 +84,7 @@ public:
return new FFmmAlgorithmThread<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(tree, kernel); return new FFmmAlgorithmThread<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(tree, kernel);
} }
else{ else{
auto algo = new FFmmAlgorithmPeriodic<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(tree, periodicUpperlevel, inPeriodicDirections); auto algo = new FFmmAlgorithmPeriodic<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(tree, periodicUpperlevel);
algo->setKernel(kernel); algo->setKernel(kernel);
return algo; return algo;
} }
......
This diff is collapsed.
...@@ -129,7 +129,7 @@ int main(int argc, char ** argv){ ...@@ -129,7 +129,7 @@ int main(int argc, char ** argv){
} }
else{ else{
FmmClass algo(&tree,PeriodicDeep); FmmClass algo(&tree,PeriodicDeep);
std::cout << "The simulation box is repeated " << algo.repetitions() << " in X/Y/Z" << std::endl; std::cout << "The simulation box is repeated " << algo.theoricalRepetition() << " in X/Y/Z" << std::endl;
KernelClass kernels( DevP, algo.extendedTreeHeight(), algo.extendedBoxWidth(),algo.extendedBoxCenter()); KernelClass kernels( DevP, algo.extendedTreeHeight(), algo.extendedBoxWidth(),algo.extendedBoxCenter());
algo.setKernel(&kernels); algo.setKernel(&kernels);
algo.execute(); algo.execute();
......
...@@ -66,13 +66,6 @@ int main(int argc, char ** argv){ ...@@ -66,13 +66,6 @@ int main(int argc, char ** argv){
const long NbParticles = FParameters::getValue(argc,argv,"-nb", 1000); const long NbParticles = FParameters::getValue(argc,argv,"-nb", 1000);
const int PeriodicDeep = FParameters::getValue(argc,argv,"-per", 2); const int PeriodicDeep = FParameters::getValue(argc,argv,"-per", 2);
// choose in +x dir or -/+x dir or all dirs // choose in +x dir or -/+x dir or all dirs
int PeriodicDirs = (FParameters::existParameter(argc,argv,"-x")?DirMinusX:0) |
(FParameters::existParameter(argc,argv,"+x")?DirPlusX:0) |
(FParameters::existParameter(argc,argv,"-y")?DirMinusY:0) |
(FParameters::existParameter(argc,argv,"+y")?DirPlusY:0) |
(FParameters::existParameter(argc,argv,"-z")?DirMinusZ:0) |
(FParameters::existParameter(argc,argv,"+z")?DirPlusZ:0);
if( PeriodicDirs == 0 ) PeriodicDirs = AllDirs;
FTic counter; FTic counter;
...@@ -106,7 +99,7 @@ int main(int argc, char ** argv){ ...@@ -106,7 +99,7 @@ int main(int argc, char ** argv){
counter.tic(); counter.tic();
KernelClass kernels; KernelClass kernels;
FmmClass algo( &tree, PeriodicDeep, PeriodicDirs); FmmClass algo( &tree, PeriodicDeep);
algo.setKernel(&kernels); algo.setKernel(&kernels);
algo.execute(); algo.execute();
...@@ -134,10 +127,9 @@ int main(int argc, char ** argv){ ...@@ -134,10 +127,9 @@ int main(int argc, char ** argv){
} }
} }
{ {
const FTreeCoordinate repetitions = algo.repetitions(); const long repetitions = algo.theoricalRepetition();
const int totalRepeatedBox = repetitions.getX() * repetitions.getY() * repetitions.getZ(); const long totalRepeatedBox = repetitions * repetitions * repetitions;
std::cout << "The box is repeated " << repetitions.getX() <<" "<< repetitions.getY()<<" "<< std::cout << "The box is repeated " << repetitions << " there are " << totalRepeatedBox << " boxes in total\n";
repetitions.getZ() << " there are " << totalRepeatedBox << " boxes in total\n";
const long long NbParticlesEntireSystem = loader.getNumberOfParticles() * totalRepeatedBox; const long long NbParticlesEntireSystem = loader.getNumberOfParticles() * totalRepeatedBox;
std::cout << "The total number of particles is " << NbParticlesEntireSystem << "\n"; std::cout << "The total number of particles is " << NbParticlesEntireSystem << "\n";
......
...@@ -69,15 +69,7 @@ int main(int argc, char ** argv){ ...@@ -69,15 +69,7 @@ int main(int argc, char ** argv){
const int SizeSubLevels = FParameters::getValue(argc,argv,"-sh", 3); const int SizeSubLevels = FParameters::getValue(argc,argv,"-sh", 3);
const long NbParticles = FParameters::getValue(argc,argv,"-nb", 5); const long NbParticles = FParameters::getValue(argc,argv,"-nb", 5);
const int PeriodicDeep = FParameters::getValue(argc,argv,"-per", 2); const int PeriodicDeep = FParameters::getValue(argc,argv,"-per", 2);
// choose in +x dir or -/+x dir or all dirs
int PeriodicDirs = (FParameters::existParameter(argc,argv,"-x")?DirMinusX:0) |
(FParameters::existParameter(argc,argv,"+x")?DirPlusX:0) |
(FParameters::existParameter(argc,argv,"-y")?DirMinusY:0) |
(FParameters::existParameter(argc,argv,"+y")?DirPlusY:0) |
(FParameters::existParameter(argc,argv,"-z")?DirMinusZ:0) |
(FParameters::existParameter(argc,argv,"+z")?DirPlusZ:0);
if( PeriodicDirs == 0 ) PeriodicDirs = AllDirs;
if( FParameters::existParameter(argc,argv,"-nodir") ) PeriodicDirs = 0;
FMpi app(argc, argv); FMpi app(argc, argv);
...@@ -127,7 +119,7 @@ int main(int argc, char ** argv){ ...@@ -127,7 +119,7 @@ int main(int argc, char ** argv){
counter.tic(); counter.tic();
KernelClass kernels; KernelClass kernels;
FmmClass algo( app.global(), &tree, PeriodicDeep, PeriodicDirs); FmmClass algo( app.global(), &tree, PeriodicDeep);
algo.setKernel(&kernels); algo.setKernel(&kernels);
algo.execute(); algo.execute();
...@@ -138,10 +130,8 @@ int main(int argc, char ** argv){ ...@@ -138,10 +130,8 @@ int main(int argc, char ** argv){
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
{ {
const FTreeCoordinate repetitions = algo.repetitions(); long long totalRepeatedBox = algo.theoricalRepetition();
const int totalRepeatedBox = repetitions.getX() * repetitions.getY() * repetitions.getZ(); totalRepeatedBox = (totalRepeatedBox*totalRepeatedBox*totalRepeatedBox);
std::cout << "The box is repeated " << repetitions.getX() <<" "<< repetitions.getY()<<" "<<
repetitions.getZ() << " there are " << totalRepeatedBox << " boxes in total\n";
const long long NbParticlesEntireSystem = (NbParticles * app.global().processCount()) * totalRepeatedBox; const long long NbParticlesEntireSystem = (NbParticles * app.global().processCount()) * totalRepeatedBox;
std::cout << "The total number of particles is " << NbParticlesEntireSystem << "\n"; std::cout << "The total number of particles is " << NbParticlesEntireSystem << "\n";
FTreeCoordinate min, max; FTreeCoordinate min, max;
...@@ -177,7 +167,7 @@ int main(int argc, char ** argv){ ...@@ -177,7 +167,7 @@ int main(int argc, char ** argv){
} }
} }
FmmClassSeq algoSeq( &treeSeq, PeriodicDeep, PeriodicDirs); FmmClassSeq algoSeq( &treeSeq, PeriodicDeep);
algoSeq.setKernel(&kernels); algoSeq.setKernel(&kernels);
algoSeq.execute(); algoSeq.execute();
......
...@@ -75,7 +75,7 @@ class TestRotationDirectPeriodic : public FUTester<TestRotationDirectPeriodic> { ...@@ -75,7 +75,7 @@ class TestRotationDirectPeriodic : public FUTester<TestRotationDirectPeriodic> {
// Run FMM // Run FMM
Print("Fmm..."); Print("Fmm...");
FmmClass algo(&tree,PeriodicDeep, DirX | DirMinusY | DirPlusZ); FmmClass algo(&tree,PeriodicDeep);
KernelClass kernels( algo.extendedTreeHeight(), algo.extendedBoxWidth(), algo.extendedBoxCenter()); KernelClass kernels( algo.extendedTreeHeight(), algo.extendedBoxWidth(), algo.extendedBoxCenter());
algo.setKernel(&kernels); algo.setKernel(&kernels);
algo.execute(); algo.execute();
......
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