diff --git a/Src/Core/FCoreCommon.hpp b/Src/Core/FCoreCommon.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7d92550a33ff73e938cddf28c4f50197a607c48a --- /dev/null +++ b/Src/Core/FCoreCommon.hpp @@ -0,0 +1,18 @@ +#ifndef FCORECOMMON_HPP +#define FCORECOMMON_HPP + +enum FFmmOperations { + FFmmP2P = (1 << 0), + FFmmP2M = (1 << 1), + FFmmM2M = (1 << 2), + FFmmM2L = (1 << 3), + FFmmL2L = (1 << 4), + FFmmL2P = (1 << 5), + + FFmmNearField = FFmmP2P, + FFmmFarField = (FFmmP2M|FFmmM2M|FFmmM2L|FFmmL2L|FFmmL2P), + + FFmmNearAndFarFields = (FFmmNearField|FFmmFarField) +}; + +#endif // FCORECOMMON_HPP diff --git a/Src/Core/FFmmAlgorithm.hpp b/Src/Core/FFmmAlgorithm.hpp index aa0027ad81405080310c9a36ff6f715cc64ed48a..317b9cc54674bc2ac0feb37366ae18d682e1de77 100755 --- a/Src/Core/FFmmAlgorithm.hpp +++ b/Src/Core/FFmmAlgorithm.hpp @@ -26,6 +26,7 @@ #include "../Containers/FOctree.hpp" #include "../Containers/FVector.hpp" +#include "FCoreCommon.hpp" /** * @author Berenger Bramas (berenger.bramas@inria.fr) @@ -69,18 +70,18 @@ public: * To execute the fmm algorithm * Call this function to run the complete algorithm */ - void execute(){ + void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){ FTRACE( FTrace::FFunction functionTrace(__FUNCTION__, "Fmm" , __FILE__ , __LINE__) ); - bottomPass(); + if(operationsToProceed & FFmmP2M) bottomPass(); - upwardPass(); + if(operationsToProceed & FFmmM2M) upwardPass(); - transferPass(); + if(operationsToProceed & FFmmM2L) transferPass(); - downardPass(); + if(operationsToProceed & FFmmL2L) downardPass(); - directPass(); + if(operationsToProceed & FFmmP2P || operationsToProceed & FFmmL2P) directPass(); } private: diff --git a/Src/Core/FFmmAlgorithmPeriodic.hpp b/Src/Core/FFmmAlgorithmPeriodic.hpp index fe858a67313a80c5597260a9ad0b01f49af29537..82ee2adf8579c5200f1f1225765d6ff319b80312 100755 --- a/Src/Core/FFmmAlgorithmPeriodic.hpp +++ b/Src/Core/FFmmAlgorithmPeriodic.hpp @@ -28,6 +28,7 @@ #include "../Containers/FOctree.hpp" #include "../Containers/FVector.hpp" +#include "FCoreCommon.hpp" /** * @author Berenger Bramas (berenger.bramas@inria.fr) @@ -51,11 +52,6 @@ class FFmmAlgorithmPeriodic : protected FAssertable{ const int offsetRealTree; //< nbLevelsAboveRoot GetFackLevel const int periodicDirections; - static int GetFackLevel(const int inLevelAboveRequiered){ - if( inLevelAboveRequiered == -1 ) return 1; - if( inLevelAboveRequiered == 0 ) return 2; - return inLevelAboveRequiered + 3; - } public: /** The constructor need the octree and the kernels used for computation @@ -67,7 +63,7 @@ public: */ FFmmAlgorithmPeriodic(OctreeClass* const inTree, const int inUpperLevel = 0, const int inPeriodicDirections = AllDirs) : tree(inTree) , kernels(0), OctreeHeight(tree->getHeight()), - nbLevelsAboveRoot(inUpperLevel), offsetRealTree(GetFackLevel(inUpperLevel)), + nbLevelsAboveRoot(inUpperLevel), offsetRealTree(inUpperLevel + 3), periodicDirections(inPeriodicDirections) { fassert(tree, "tree cannot be null", __LINE__, __FILE__); @@ -88,21 +84,23 @@ public: * To execute the fmm algorithm * Call this function to run the complete algorithm */ - void execute(){ + void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){ fassert(kernels, "kernels cannot be null", __LINE__, __FILE__); - FTRACE( FTrace::FFunction functionTrace(__FUNCTION__, "Fmm" , __FILE__ , __LINE__) ); + FTRACE( FTrace::FFunction functionTrace(__FUNCTION__, "Fmm" , __FILE__ , __LINE__) ); - bottomPass(); + if(operationsToProceed & FFmmP2M) bottomPass(); - upwardPass(); + if(operationsToProceed & FFmmM2M) upwardPass(); - transferPass(); - // before downward pass we have to perform the periodicity - processPeriodicLevels(); + if(operationsToProceed & FFmmM2L){ + transferPass(); + // before downward pass we have to perform the periodicity + processPeriodicLevels(); + } - downardPass(); + if(operationsToProceed & FFmmL2L) downardPass(); - directPass(); + if(operationsToProceed & FFmmP2P || operationsToProceed & FFmmL2P) directPass(); } @@ -166,7 +164,7 @@ public: avoidGotoLeftIterator.moveUp(); octreeIterator = avoidGotoLeftIterator;// equal octreeIterator.moveUp(); octreeIterator.gotoLeft(); - FDEBUG( FDebug::Controller << "\t\t>> Level " << idxLevel << " = " << counterTimeLevel.tacAndElapsed() << "s\n" ); + FDEBUG( FDebug::Controller << "\t\t>> Level " << idxLevel << "(" << fackLevel << ") = " << counterTimeLevel.tacAndElapsed() << "s\n" ); } @@ -208,7 +206,7 @@ public: FDEBUG(computationCounter.tic()); kernels->finishedLevelM2L(fackLevel); FDEBUG(computationCounter.tac()); - FDEBUG( FDebug::Controller << "\t\t>> Level " << idxLevel << " = " << counterTimeLevel.tacAndElapsed() << "s\n" ); + FDEBUG( FDebug::Controller << "\t\t>> Level " << idxLevel << "(" << fackLevel << ") = " << counterTimeLevel.tacAndElapsed() << "s\n" ); } FDEBUG( FDebug::Controller << "\tFinished (@Downward Pass (M2L) = " << counterTime.tacAndElapsed() << "s)\n" ); FDEBUG( FDebug::Controller << "\t\t Computation : " << computationCounter.cumulated() << " s\n" ); @@ -243,7 +241,7 @@ public: avoidGotoLeftIterator.moveDown(); octreeIterator = avoidGotoLeftIterator; - FDEBUG( FDebug::Controller << "\t\t>> Level " << idxLevel << " = " << counterTimeLevel.tacAndElapsed() << "s\n" ); + FDEBUG( FDebug::Controller << "\t\t>> Level " << idxLevel << "(" << fackLevel << ") = " << counterTimeLevel.tacAndElapsed() << "s\n" ); } FDEBUG( FDebug::Controller << "\tFinished (@Downward Pass (L2L) = " << counterTime.tacAndElapsed() << "s)\n" ); @@ -463,8 +461,8 @@ public: * because it contains the theorical periodic box width for the * nbLevelsAboveRoot choosen */ - int theoricalRepetition() const { - return nbLevelsAboveRoot == -1 ? 3 : 3 * (1<<(nbLevelsAboveRoot+1)) + 1; + long long int theoricalRepetition() const { + return nbLevelsAboveRoot == -1 ? 3 : 3LL * (1LL<<(nbLevelsAboveRoot+1)) + 1LL; } /** To know the number of box repeated in each direction @@ -474,7 +472,7 @@ public: * The maxs value are contains between [0;(theoricalRepetition-1 / 2)] */ void repetitionsIntervals(FTreeCoordinate*const min, FTreeCoordinate*const max) const { - const int halfRepeated = (theoricalRepetition()-1) /2; + const int halfRepeated = int((theoricalRepetition()-1)/2); min->setPosition(-ifDir(DirMinusX,halfRepeated,0),-ifDir(DirMinusY,halfRepeated,0), -ifDir(DirMinusZ,halfRepeated,0)); max->setPosition(ifDir(DirPlusX,halfRepeated,0),ifDir(DirPlusY,halfRepeated,0), @@ -486,7 +484,7 @@ public: * Each value is between [1;theoricalRepetition] */ FTreeCoordinate repetitions() const { - const int halfRepeated = (theoricalRepetition()-1) /2; + const int halfRepeated = int((theoricalRepetition()-1)/2); return FTreeCoordinate(ifDir(DirMinusX,halfRepeated,0) + ifDir(DirPlusX,halfRepeated,0) + 1, ifDir(DirMinusY,halfRepeated,0) + ifDir(DirPlusY,halfRepeated,0) + 1, ifDir(DirMinusZ,halfRepeated,0) + ifDir(DirPlusZ,halfRepeated,0) + 1); @@ -511,11 +509,13 @@ public: */ FPoint extendedBoxCenter() const { const FReal originalBoxWidth = tree->getBoxWidth(); + const FReal originalBoxWidthDiv2 = originalBoxWidth/2.0; const FPoint originalBoxCenter = tree->getBoxCenter(); - const FReal offset = originalBoxWidth * FReal(1<<(offsetRealTree-1)) - originalBoxWidth/FReal(2.0); - return FPoint( originalBoxCenter.getX() + offset, - originalBoxCenter.getY() + offset, - originalBoxCenter.getZ() + offset); + + const FReal offset = extendedBoxWidth()/2; + return FPoint( originalBoxCenter.getX() - originalBoxWidthDiv2 + offset, + originalBoxCenter.getY() - originalBoxWidthDiv2 + offset, + originalBoxCenter.getZ() - originalBoxWidthDiv2 + offset); } /** This function has to be used to init the kernel with correct args @@ -544,7 +544,7 @@ public: * @return correctValue if testDir is used, else wrongValue */ template <class T> - int ifDir(const PeriodicCondition testDir, const T& correctValue, const T& wrongValue) const { + const T& ifDir(const PeriodicCondition testDir, const T& correctValue, const T& wrongValue) const { return (periodicDirections & testDir ? correctValue : wrongValue); } @@ -576,7 +576,7 @@ public: // compute the root typename OctreeClass::Iterator octreeIterator(tree); octreeIterator.gotoLeft(); - kernels->M2M( &rootUp, octreeIterator.getCurrentBox(), 2); + kernels->M2M( &rootUp, octreeIterator.getCurrentBox(), 3); // build fack M2L vector from -3/+3 x/y/z const CellClass* neighbors[343]; @@ -594,10 +594,10 @@ public: } // compute M2L CellClass rootDown; - kernels->M2L( &rootDown , neighbors, counter, 2); + kernels->M2L( &rootDown , neighbors, counter, 3); // put result in level 1 - kernels->L2L( &rootDown, octreeIterator.getCurrentBox(), 2); + kernels->L2L( &rootDown, octreeIterator.getCurrentBox(), 3); FDEBUG( FDebug::Controller << "\tFinished (@Periodic = " << counterTime.tacAndElapsed() << "s)\n" ); return; diff --git a/Src/Core/FFmmAlgorithmSectionTask.hpp b/Src/Core/FFmmAlgorithmSectionTask.hpp index 4878ab861212d736c2232aba3bc74589a0e9f4c0..3adf3f0e9ee7e48ea7be2f5f0e65c21dd092cbde 100755 --- a/Src/Core/FFmmAlgorithmSectionTask.hpp +++ b/Src/Core/FFmmAlgorithmSectionTask.hpp @@ -26,6 +26,7 @@ #include "../Containers/FOctree.hpp" #include "../Containers/FVector.hpp" +#include "FCoreCommon.hpp" /** * @author Berenger Bramas (berenger.bramas@inria.fr) @@ -82,7 +83,7 @@ public: * To execute the fmm algorithm * Call this function to run the complete algorithm */ - void execute(){ + void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){ FTRACE( FTrace::FFunction functionTrace(__FUNCTION__, "Fmm" , __FILE__ , __LINE__) ); #pragma omp parallel @@ -91,22 +92,22 @@ public: { #pragma omp section { - bottomPass(); + if(operationsToProceed & FFmmP2M) bottomPass(); - upwardPass(); + if(operationsToProceed & FFmmM2M) upwardPass(); - transferPass(); + if(operationsToProceed & FFmmM2L) transferPass(); - downardPass(); + if(operationsToProceed & FFmmL2L) downardPass(); } #pragma omp section { - directPass(); + if(operationsToProceed & FFmmP2P) directPass(); } } #pragma omp single { - L2PPass(); + if(operationsToProceed & FFmmL2P) L2PPass(); } } } diff --git a/Src/Core/FFmmAlgorithmTask.hpp b/Src/Core/FFmmAlgorithmTask.hpp index 76e8d322f14017c1e8dfa8f7e625e0aa1a118631..10412c037c10ae296ec66d9dea7f2b1f7705405b 100755 --- a/Src/Core/FFmmAlgorithmTask.hpp +++ b/Src/Core/FFmmAlgorithmTask.hpp @@ -26,6 +26,7 @@ #include "../Containers/FOctree.hpp" #include "../Containers/FVector.hpp" +#include "FCoreCommon.hpp" /** * @author Berenger Bramas (berenger.bramas@inria.fr) @@ -82,18 +83,18 @@ public: * To execute the fmm algorithm * Call this function to run the complete algorithm */ - void execute(){ + void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){ FTRACE( FTrace::FFunction functionTrace(__FUNCTION__, "Fmm" , __FILE__ , __LINE__) ); - bottomPass(); + if(operationsToProceed & FFmmP2M) bottomPass(); - upwardPass(); + if(operationsToProceed & FFmmM2M) upwardPass(); - transferPass(); + if(operationsToProceed & FFmmM2L) transferPass(); - downardPass(); + if(operationsToProceed & FFmmL2L) downardPass(); - directPass(); + if(operationsToProceed & FFmmP2P || operationsToProceed & FFmmL2P) directPass(); } private: diff --git a/Src/Core/FFmmAlgorithmThread.hpp b/Src/Core/FFmmAlgorithmThread.hpp index b47ba8b61dc7801778d6273ec2ef0ba3d66d7848..14dcbf6d192f063afb9988d80b25e6f25051124f 100755 --- a/Src/Core/FFmmAlgorithmThread.hpp +++ b/Src/Core/FFmmAlgorithmThread.hpp @@ -25,6 +25,7 @@ #include "../Containers/FOctree.hpp" +#include "FCoreCommon.hpp" #include <omp.h> @@ -90,7 +91,7 @@ public: * To execute the fmm algorithm * Call this function to run the complete algorithm */ - void execute(){ + void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){ FTRACE( FTrace::FFunction functionTrace(__FUNCTION__, "Fmm" , __FILE__ , __LINE__) ); for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){ @@ -110,15 +111,15 @@ public: iterArray = new typename OctreeClass::Iterator[leafsNumber]; fassert(iterArray, "iterArray bad alloc", __LINE__, __FILE__); - bottomPass(); + if(operationsToProceed & FFmmP2M) bottomPass(); - upwardPass(); + if(operationsToProceed & FFmmM2M) upwardPass(); - transferPass(); + if(operationsToProceed & FFmmM2L) transferPass(); - downardPass(); + if(operationsToProceed & FFmmL2L) downardPass(); - directPass(); + if(operationsToProceed & FFmmP2P || operationsToProceed & FFmmL2P) directPass(); delete [] iterArray; iterArray = 0; diff --git a/Src/Core/FFmmAlgorithmThreadProc.hpp b/Src/Core/FFmmAlgorithmThreadProc.hpp index 2ca2a2ac4d4926e1e659aecf6c8851f7ddb90cb2..d2b0f3a2b1f8cb75be98bccc9b5adeec1500eb30 100755 --- a/Src/Core/FFmmAlgorithmThreadProc.hpp +++ b/Src/Core/FFmmAlgorithmThreadProc.hpp @@ -34,6 +34,7 @@ #include <omp.h> +#include "FCoreCommon.hpp" /** * @author Berenger Bramas (berenger.bramas@inria.fr) @@ -142,7 +143,7 @@ public: * To execute the fmm algorithm * Call this function to run the complete algorithm */ - void execute(){ + void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){ FTRACE( FTrace::FFunction functionTrace( __FUNCTION__, "Fmm" , __FILE__ , __LINE__ ) ); // Count leaf @@ -196,15 +197,15 @@ public: } // run; - bottomPass(); + if(operationsToProceed & FFmmP2M) bottomPass(); - upwardPass(); + if(operationsToProceed & FFmmM2M) upwardPass(); - transferPass(); + if(operationsToProceed & FFmmM2L) transferPass(); - downardPass(); + if(operationsToProceed & FFmmL2L) downardPass(); - directPass(); + if(operationsToProceed & FFmmP2P || operationsToProceed & FFmmL2P) directPass(); // delete array delete [] iterArray; diff --git a/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp b/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp index 7328d192cc6bd6ccc0beb8b8ba01014e0a77581f..dfdd5a2eaf2cb5dcfcd7218953971a884a980a3b 100755 --- a/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp +++ b/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp @@ -35,6 +35,7 @@ #include <omp.h> +#include "FCoreCommon.hpp" /** * @author Berenger Bramas (berenger.bramas@inria.fr) @@ -153,7 +154,7 @@ public: * To execute the fmm algorithm * Call this function to run the complete algorithm */ - void execute(){ + void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){ FTRACE( FTrace::FFunction functionTrace( __FUNCTION__, "Fmm" , __FILE__ , __LINE__ ) ); // Count leaf @@ -207,15 +208,15 @@ public: } // run; - bottomPass(); + if(operationsToProceed & FFmmP2M) bottomPass(); - upwardPass(); + if(operationsToProceed & FFmmM2M) upwardPass(); - transferPass(); + if(operationsToProceed & FFmmM2L) transferPass(); - downardPass(); + if(operationsToProceed & FFmmL2L) downardPass(); - directPass(); + if(operationsToProceed & FFmmP2P || operationsToProceed & FFmmL2P) directPass(); // delete array delete [] iterArray; diff --git a/Src/Core/FFmmAlgorithmThreadTsm.hpp b/Src/Core/FFmmAlgorithmThreadTsm.hpp index d1d68190e1fd57633e7ae23e8720a152fac4b66c..9003496a191967a87324ac2eab390024a07e0e9e 100755 --- a/Src/Core/FFmmAlgorithmThreadTsm.hpp +++ b/Src/Core/FFmmAlgorithmThreadTsm.hpp @@ -24,7 +24,7 @@ #include "../Utils/FGlobal.hpp" #include "../Containers/FOctree.hpp" - +#include "FCoreCommon.hpp" #include <omp.h> @@ -87,7 +87,7 @@ public: * To execute the fmm algorithm * Call this function to run the complete algorithm */ - void execute(){ + void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){ FTRACE( FTrace::FFunction functionTrace(__FUNCTION__, "Fmm" , __FILE__ , __LINE__) ); // Count leaf @@ -100,15 +100,15 @@ public: iterArray = new typename OctreeClass::Iterator[numberOfLeafs]; fassert(iterArray, "iterArray bad alloc", __LINE__, __FILE__); - bottomPass(); + if(operationsToProceed & FFmmP2M) bottomPass(); - upwardPass(); + if(operationsToProceed & FFmmM2M) upwardPass(); - transferPass(); + if(operationsToProceed & FFmmM2L) transferPass(); - downardPass(); + if(operationsToProceed & FFmmL2L) downardPass(); - directPass(); + if(operationsToProceed & FFmmP2P || operationsToProceed & FFmmL2P) directPass(); delete [] iterArray; iterArray = 0; diff --git a/Src/Core/FFmmAlgorithmTsm.hpp b/Src/Core/FFmmAlgorithmTsm.hpp index 8d4ba360debf4234eb5c843bc55f2857202dbf36..c0c77ff60e81d98f4fda00e00569a5d4883aa197 100755 --- a/Src/Core/FFmmAlgorithmTsm.hpp +++ b/Src/Core/FFmmAlgorithmTsm.hpp @@ -23,7 +23,7 @@ #include "../Utils/FTic.hpp" #include "../Containers/FOctree.hpp" - +#include "FCoreCommon.hpp" /** * @author Berenger Bramas (berenger.bramas@inria.fr) @@ -72,19 +72,18 @@ public: * To execute the fmm algorithm * Call this function to run the complete algorithm */ - void execute(){ + void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){ FTRACE( FTrace::FFunction functionTrace(__FUNCTION__, "Fmm" , __FILE__ , __LINE__) ); - bottomPass(); - - upwardPass(); + if(operationsToProceed & FFmmP2M) bottomPass(); - transferPass(); + if(operationsToProceed & FFmmM2M) upwardPass(); - downardPass(); + if(operationsToProceed & FFmmM2L) transferPass(); - directPass(); + if(operationsToProceed & FFmmL2L) downardPass(); + if(operationsToProceed & FFmmP2P || operationsToProceed & FFmmL2P) directPass(); } /** P2M */