Commit c22ccd0a authored by BRAMAS Berenger's avatar BRAMAS Berenger

move to new periodic

parent b1d39835
......@@ -9,7 +9,7 @@ project(Lib_scalfmm)
set(LIBRARY_OUTPUT_PATH ../lib/${CMAKE_BUILD_TYPE})
ADD_DEFINITIONS(${ScaLFMM_CXX_FLAGS})
MESSAGE( ${ScaLFMM_CXX_FLAGS})
# Searching all cpp file
file(
GLOB_RECURSE
......
......@@ -29,111 +29,103 @@
* 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
std::unique_ptr<char[]> array; //< Allocated Array
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);
}
}
const MPI_Comm comm; //< Communicator needed by MPI_Pack functions
const 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):
comm(inComm),
arrayCapacity(inCapacity),
array(new char[inCapacity]),
currentIndex(0)
{}
/** Destructor
/*Constructor with a default arrayCapacity of 512 bytes */
FMpiBufferReader(const MPI_Comm inComm, const int inCapacity = 512):
comm(inComm),
arrayCapacity(inCapacity),
array(new char[inCapacity]),
currentIndex(0)
{}
/** Destructor
*/
virtual ~FMpiBufferReader(){
}
/** Get allocated memory pointer */
char* data(){
return array.get();
}
/** Get allocated memory pointer */
const char* data() const {
return array.get();
}
/** get the filled space */
int getSize() const{
return currentIndex;
}
/** Size of the memory initialized */
int getCapacity() const{
return arrayCapacity;
}
/** Move the read index to a position */
void seek(const int inIndex){
if(inIndex > arrayCapacity){
printf("FMpiBufferReader :: Aborting :: Can't move index because buffer isn't long enough");
exit(0);
virtual ~FMpiBufferReader(){
}
/** Get allocated memory pointer */
char* data(){
return array.get();
}
/** Get allocated memory pointer */
const char* data() const {
return array.get();
}
/** get the filled space */
int getSize() const{
return currentIndex;
}
/** Size of the memory initialized */
int getCapacity() const{
return arrayCapacity;
}
/** Move the read index to a position */
void seek(const int inIndex){
if(inIndex > arrayCapacity){
printf("FMpiBufferReader :: Aborting :: Can't move index because buffer isn't long enough");
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
......
......@@ -28,102 +28,99 @@
* 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
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 {
if(int(currentIndex + requestedSpace) > arrayCapacity){
printf("Error FMpiBufferWriter has not enough space\n");
exit(0);
const MPI_Comm mpiComm; //< Communicator needed by MPI_Pack functions
const 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 {
if(int(currentIndex + requestedSpace) > arrayCapacity){
printf("Error FMpiBufferWriter has not enough space\n");
exit(0);
}
}
}
public:
/** Constructor with a default arrayCapacity of 512 bytes */
FMpiBufferWriter(const MPI_Comm inComm, const int inCapacity = 1024):
mpiComm(inComm),
arrayCapacity(inCapacity),
array(new char[inCapacity]),
currentIndex(0)
{}
/** Destructor */
virtual ~FMpiBufferWriter(){
}
/** Get allocated memory pointer */
char* data(){
return array.get();
}
/** Get allocated memory pointer */
const char* data() const {
return array.get();
}
/** Get the filled space */
int getSize() const {
return currentIndex;
}
/** Get the allocated space */
int getCapacity() const {
return arrayCapacity;
}
/** Write data by packing cpy */
template <class ClassType>
void write(const ClassType& object){
//printf("Space need in the write : %d, index set on %d \n",sizeof(ClassType),currentIndex);
assertRemainingSpace(sizeof(ClassType));
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &currentIndex, mpiComm);
}
/**
/** Constructor with a default arrayCapacity of 512 bytes */
FMpiBufferWriter(const MPI_Comm inComm, const int inCapacity = 1024):
mpiComm(inComm),
arrayCapacity(inCapacity),
array(new char[inCapacity]),
currentIndex(0)
{}
/** Destructor */
virtual ~FMpiBufferWriter(){
}
/** Get allocated memory pointer */
char* data(){
return array.get();
}
/** Get allocated memory pointer */
const char* data() const {
return array.get();
}
/** Get the filled space */
int getSize() const {
return currentIndex;
}
/** Get the allocated space */
int getCapacity() const {
return arrayCapacity;
}
/** Write data by packing cpy */
template <class ClassType>
void write(const ClassType& object){
assertRemainingSpace(sizeof(ClassType));
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &currentIndex, mpiComm);
}
/**
* Allow to pass rvalue to write
*/
template <class ClassType>
void write(const ClassType&& object){
// printf("Space need in the write : %d \n",sizeof(ClassType));
assertRemainingSpace(sizeof(ClassType));
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);
template <class ClassType>
void write(const ClassType&& object){
assertRemainingSpace(sizeof(ClassType));
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &currentIndex, mpiComm);
}
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
*/
template <class ClassType>
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);
MPI_Pack( const_cast<ClassType*>(objects), inSize, FMpi::GetType(*objects), array.get(), arrayCapacity, &currentIndex, mpiComm);
}
/** Equivalent to write */
template <class ClassType>
FMpiBufferWriter& operator<<(const ClassType& object){
write(object);
return *this;
}
/** Reset the writing index, but do not change the arrayCapacity */
void reset(){
currentIndex = 0;
}
template <class ClassType>
void write(const ClassType* const objects, const int inSize){
assertRemainingSpace(sizeof(ClassType) * inSize);
MPI_Pack( const_cast<ClassType*>(objects), inSize, FMpi::GetType(*objects), array.get(), arrayCapacity, &currentIndex, mpiComm);
}
/** Equivalent to write */
template <class ClassType>
FMpiBufferWriter& operator<<(const ClassType& object){
write(object);
return *this;
}
/** Reset the writing index, but do not change the arrayCapacity */
void reset(){
currentIndex = 0;
}
};
......
......@@ -69,13 +69,13 @@ public:
template<class OctreeClass, class CellClass, class ContainerClass, class KernelClass, class LeafClass>
static FAbstractAlgorithm* BuildAlgorithm(OctreeClass*const tree, KernelClass*const kernel,
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
if(isPeriodic == false){
return new FFmmAlgorithmThreadProc<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(FMpi::FComm(mpiComm), tree, kernel);
}
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);
return algo;
}
......@@ -84,7 +84,7 @@ public:
return new FFmmAlgorithmThread<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(tree, kernel);
}
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);
return algo;
}
......
This diff is collapsed.
......@@ -129,7 +129,7 @@ int main(int argc, char ** argv){
}
else{
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());
algo.setKernel(&kernels);
algo.execute();
......
......@@ -66,13 +66,6 @@ int main(int argc, char ** argv){
const long NbParticles = FParameters::getValue(argc,argv,"-nb", 1000);
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;
FTic counter;
......@@ -106,7 +99,7 @@ int main(int argc, char ** argv){
counter.tic();
KernelClass kernels;
FmmClass algo( &tree, PeriodicDeep, PeriodicDirs);
FmmClass algo( &tree, PeriodicDeep);
algo.setKernel(&kernels);
algo.execute();
......@@ -134,10 +127,9 @@ int main(int argc, char ** argv){
}
}
{
const FTreeCoordinate repetitions = algo.repetitions();
const int totalRepeatedBox = repetitions.getX() * repetitions.getY() * repetitions.getZ();
std::cout << "The box is repeated " << repetitions.getX() <<" "<< repetitions.getY()<<" "<<
repetitions.getZ() << " there are " << totalRepeatedBox << " boxes in total\n";
const long repetitions = algo.theoricalRepetition();
const long totalRepeatedBox = repetitions * repetitions * repetitions;
std::cout << "The box is repeated " << repetitions << " there are " << totalRepeatedBox << " boxes in total\n";
const long long NbParticlesEntireSystem = loader.getNumberOfParticles() * totalRepeatedBox;
std::cout << "The total number of particles is " << NbParticlesEntireSystem << "\n";
......
......@@ -69,15 +69,7 @@ int main(int argc, char ** argv){
const int SizeSubLevels = FParameters::getValue(argc,argv,"-sh", 3);
const long NbParticles = FParameters::getValue(argc,argv,"-nb", 5);
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);
......@@ -127,7 +119,7 @@ int main(int argc, char ** argv){
counter.tic();
KernelClass kernels;
FmmClass algo( app.global(), &tree, PeriodicDeep, PeriodicDirs);
FmmClass algo( app.global(), &tree, PeriodicDeep);
algo.setKernel(&kernels);
algo.execute();
......@@ -138,10 +130,8 @@ int main(int argc, char ** argv){
//////////////////////////////////////////////////////////////////////////////////
{
const FTreeCoordinate repetitions = algo.repetitions();
const int totalRepeatedBox = repetitions.getX() * repetitions.getY() * repetitions.getZ();
std::cout << "The box is repeated " << repetitions.getX() <<" "<< repetitions.getY()<<" "<<
repetitions.getZ() << " there are " << totalRepeatedBox << " boxes in total\n";
long long totalRepeatedBox = algo.theoricalRepetition();
totalRepeatedBox = (totalRepeatedBox*totalRepeatedBox*totalRepeatedBox);
const long long NbParticlesEntireSystem = (NbParticles * app.global().processCount()) * totalRepeatedBox;
std::cout << "The total number of particles is " << NbParticlesEntireSystem << "\n";
FTreeCoordinate min, max;
......@@ -177,7 +167,7 @@ int main(int argc, char ** argv){
}
}
FmmClassSeq algoSeq( &treeSeq, PeriodicDeep, PeriodicDirs);
FmmClassSeq algoSeq( &treeSeq, PeriodicDeep);
algoSeq.setKernel(&kernels);
algoSeq.execute();
......
......@@ -75,7 +75,7 @@ class TestRotationDirectPeriodic : public FUTester<TestRotationDirectPeriodic> {
// Run FMM
Print("Fmm...");
FmmClass algo(&tree,PeriodicDeep, DirX | DirMinusY | DirPlusZ);
FmmClass algo(&tree,PeriodicDeep);
KernelClass kernels( algo.extendedTreeHeight(), algo.extendedBoxWidth(), algo.extendedBoxCenter());
algo.setKernel(&kernels);
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