diff --git a/Data/utestFmb.data b/Data/utestFmb.data new file mode 100644 index 0000000000000000000000000000000000000000..eb7af49452b06209c6399807e442e160f7c052b0 Binary files /dev/null and b/Data/utestFmb.data differ diff --git a/Src/Components/FAbstractKernels.hpp b/Src/Components/FAbstractKernels.hpp index d20d1cddb6ee9e5462a9d46eeca63b617cc4d84c..c9fcc19cd21c45c58baa1e6ca1ee0687c23300b4 100644 --- a/Src/Components/FAbstractKernels.hpp +++ b/Src/Components/FAbstractKernels.hpp @@ -101,27 +101,8 @@ public: */ virtual void P2P(const MortonIndex inCurrentLeafIndex, ContainerClass* const FRestrict targets, const ContainerClass* const FRestrict sources, - ContainerClass* const directNeighborsParticles[26], const MortonIndex inNeighborsIndex[26], const int size) = 0; + ContainerClass* const directNeighborsParticles[26], const int size) = 0; - - ////////////////////////////////////////////////////////////////////////////// - // Periodic methods - ////////////////////////////////////////////////////////////////////////////// - - /** - * P2P - * Particles to particles - * @param inCurrentLeafIndex the leaf index - * @param targets current boxe targets particles - * @param sources current boxe sources particles - * @param directNeighborsParticles the particles from direct neighbors (this is an array of list) - * @param neighborsRelativePositions the relative position of neighbors - * @param size the number of direct neighbors (the size of the array directNeighborsParticles) - */ - virtual void P2P(const MortonIndex inCurrentLeafIndex, - ContainerClass* const FRestrict targets, const ContainerClass* const FRestrict sources, - ContainerClass* const directNeighborsParticles[26], const FTreeCoordinate neighborsRelativeOffset[26], - const int size) = 0; }; diff --git a/Src/Components/FBasicKernels.hpp b/Src/Components/FBasicKernels.hpp index 3832507d2f658a281f8489feb59431a8d0a3b431..c9aca4e9900fa56654d1b4ebee56eb94d0252605 100644 --- a/Src/Components/FBasicKernels.hpp +++ b/Src/Components/FBasicKernels.hpp @@ -67,18 +67,10 @@ public: /** Do nothing */ virtual void P2P(const MortonIndex , ContainerClass* const FRestrict , const ContainerClass* const FRestrict , - ContainerClass* const [26], const MortonIndex [26], const int ){ + ContainerClass* const [26], const int ){ } - // ------------------- Periodic -------------------- - - - /** After Downward */ - void P2P(const MortonIndex , - ContainerClass* const FRestrict , const ContainerClass* const FRestrict , - ContainerClass* const [26], const FTreeCoordinate [26], const int ) { - } }; diff --git a/Src/Components/FTestKernels.hpp b/Src/Components/FTestKernels.hpp index 5b03d3565d08a26da25406617e686f5b2cd59d3a..c8f8d500a064fcd4ee6b439d382606d0aca7fe9e 100644 --- a/Src/Components/FTestKernels.hpp +++ b/Src/Components/FTestKernels.hpp @@ -114,7 +114,7 @@ public: /** After Downward */ void P2P(const MortonIndex , ContainerClass* const FRestrict targets, const ContainerClass* const FRestrict sources, - ContainerClass* const directNeighborsParticles[26], const MortonIndex [26], const int size) { + ContainerClass* const directNeighborsParticles[26], const int size) { // Each particles targeted is impacted by the particles sources long long int inc = sources->getSize(); diff --git a/Src/Components/FTestPeriodicKernels.hpp b/Src/Components/FTestPeriodicKernels.hpp deleted file mode 100644 index 3cf189b0fc135e83088b8d1046bf747ff9efd463..0000000000000000000000000000000000000000 --- a/Src/Components/FTestPeriodicKernels.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// =================================================================================== -// Logiciel initial: ScalFmm Version 0.5 -// Co-auteurs : Olivier Coulaud, Bérenger Bramas. -// Propriétaires : INRIA. -// Copyright © 2011-2012, diffusé sous les termes et conditions d’une licence propriétaire. -// Initial software: ScalFmm Version 0.5 -// Co-authors: Olivier Coulaud, Bérenger Bramas. -// Owners: INRIA. -// Copyright © 2011-2012, spread under the terms and conditions of a proprietary license. -// =================================================================================== -#ifndef FTESTPERIODICKERNELS_HPP -#define FTESTPERIODICKERNELS_HPP - -#include "FTestKernels.hpp" - -/** This kernel is the periodic version of the test kernel - */ - -template< class ParticleClass, class CellClass, class ContainerClass> -class FTestPeriodicKernels : public FTestKernels<ParticleClass,CellClass,ContainerClass> { -public: - - - /** After Downward */ - void P2P(const MortonIndex , - ContainerClass* const FRestrict targets, const ContainerClass* const FRestrict sources, - ContainerClass* const directNeighborsParticles[26], const FTreeCoordinate [26], const int size) { - - // Each particles targeted is impacted by the particles sources - long long int inc = sources->getSize(); - if(targets == sources){ - inc -= 1; - } - for(int idx = 0 ; idx < size ; ++idx){ - inc += directNeighborsParticles[idx]->getSize(); - } - - typename ContainerClass::BasicIterator iter(*targets); - while( iter.hasNotFinished() ){ - iter.data().setDataDown(iter.data().getDataDown() + inc); - iter.gotoNext(); - } - - } -}; - -#endif // FTESTPERIODICKERNELS_HPP diff --git a/Src/Containers/FOctree.hpp b/Src/Containers/FOctree.hpp index 3e66059dacfa4a88e0ee1be9d384b8a680869723..2ffbed48137c73b093d9e433cb742b1a64069219 100644 --- a/Src/Containers/FOctree.hpp +++ b/Src/Containers/FOctree.hpp @@ -687,7 +687,7 @@ public: FTreeCoordinate center; center.setPositionFromMorton(inIndex, inLevel); - const int limite = FMath::pow(2,inLevel); + const int limite = FMath::pow2(inLevel); int idxNeighbors = 0; @@ -773,7 +773,7 @@ public: const FTreeCoordinate parentCell(workingCell.getX()>>1,workingCell.getY()>>1,workingCell.getZ()>>1); // Limite at parent level number of box (split by 2 by level) - const int limite = FMath::pow(2,inLevel-1); + const int limite = FMath::pow2(inLevel-1); int idxNeighbors = 0; // We test all cells around @@ -838,7 +838,7 @@ public: const FTreeCoordinate parentCell(workingCell.getX()>>1,workingCell.getY()>>1,workingCell.getZ()>>1); // Limite at parent level number of box (split by 2 by level) - const int limite = FMath::pow(2,inLevel-1); + const int limite = FMath::pow2(inLevel-1); // This is not on a border we can use normal interaction list method if( !(parentCell.getX() == 0 || parentCell.getY() == 0 || parentCell.getZ() == 0 || @@ -933,22 +933,9 @@ public: * @param inLevel the level of the element * @return the number of neighbors */ - int getLeafsNeighbors(ContainerClass* inNeighbors[26], const MortonIndex inIndex, const int inLevel){ - MortonIndex inNeighborsIndex[26]; - return getLeafsNeighborsWithIndex(inNeighbors, inNeighborsIndex, inIndex, inLevel); - } - - /** This function fill an array with the neighbors of a cell - * @param inNeighbors the array to store the elements - * @param inIndex the index of the element we want the neighbors - * @param inLevel the level of the element - * @return the number of neighbors - */ - int getLeafsNeighborsWithIndex(ContainerClass* inNeighbors[26], MortonIndex inNeighborsIndex[26], const MortonIndex inIndex, const int inLevel){ - FTreeCoordinate center; - center.setPositionFromMorton(inIndex, inLevel); - - const int limite = FMath::pow(2,inLevel); + int getLeafsNeighbors(ContainerClass* inNeighbors[26], const FTreeCoordinate& center, const int inLevel){ + memset( inNeighbors, 0 , 26 * sizeof(ContainerClass*)); + const int limite = FMath::pow2(inLevel); int idxNeighbors = 0; @@ -970,8 +957,8 @@ public: ContainerClass* const leaf = getLeafSrc(mortonOther); // add to list if not null if(leaf){ - inNeighborsIndex[idxNeighbors] = mortonOther; - inNeighbors[idxNeighbors++] = leaf; + inNeighbors[(((idxX + 1) * 3) + (idxY +1)) * 3 + idxZ + 1] = leaf; + ++idxNeighbors; } } } @@ -987,11 +974,9 @@ public: * @param inLevel the level of the element * @return the number of neighbors */ - int getLeafsNeighborsWithIndex(ContainerClass* inNeighbors[26], FTreeCoordinate inNeighborsPosition[26], const MortonIndex inIndex, const int inLevel){ - FTreeCoordinate center; - center.setPositionFromMorton(inIndex, inLevel); - - const int limite = FMath::pow(2,inLevel); + int getPeriodicLeafsNeighbors(ContainerClass* inNeighbors[26], const FTreeCoordinate& center, const int inLevel){ + memset(inNeighbors , 0 , 26 * sizeof(ContainerClass*)); + const int limite = FMath::pow2(inLevel); int idxNeighbors = 0; @@ -1039,8 +1024,8 @@ public: ContainerClass* const leaf = getLeafSrc(mortonOther); // add to list if not null if(leaf){ - inNeighborsPosition[idxNeighbors] = offset; - inNeighbors[idxNeighbors++] = leaf; + inNeighbors[(((idxX + 1) * 3) + (idxY +1)) * 3 + idxZ + 1] = leaf; + ++idxNeighbors; } } } diff --git a/Src/Core/FFmmAlgorithm.hpp b/Src/Core/FFmmAlgorithm.hpp index d83d0c9a967d52162b73f66ea2433310792b3c68..6176814ec7fb71b0cc9941255b0ecdc173249937 100644 --- a/Src/Core/FFmmAlgorithm.hpp +++ b/Src/Core/FFmmAlgorithm.hpp @@ -234,16 +234,15 @@ private: octreeIterator.gotoBottomLeft(); // There is a maximum of 26 neighbors ContainerClass* neighbors[26]; - MortonIndex neighborsIndex[26]; // for each leafs do{ FDEBUG(computationCounterL2P.tic()); kernels->L2P(octreeIterator.getCurrentCell(), octreeIterator.getCurrentListTargets()); FDEBUG(computationCounterL2P.tac()); // need the current particles and neighbors particles - const int counter = tree->getLeafsNeighborsWithIndex(neighbors, neighborsIndex, octreeIterator.getCurrentGlobalIndex(),heightMinusOne); + const int counter = tree->getLeafsNeighbors(neighbors, octreeIterator.getCurrentGlobalCoordinate(),heightMinusOne); FDEBUG(computationCounterP2P.tic()); - kernels->P2P(octreeIterator.getCurrentGlobalIndex(),octreeIterator.getCurrentListTargets(), octreeIterator.getCurrentListSrc() , neighbors, neighborsIndex, counter); + kernels->P2P(octreeIterator.getCurrentGlobalIndex(),octreeIterator.getCurrentListTargets(), octreeIterator.getCurrentListSrc() , neighbors, counter); FDEBUG(computationCounterP2P.tac()); } while(octreeIterator.moveRight()); diff --git a/Src/Core/FFmmAlgorithmPeriodic.hpp b/Src/Core/FFmmAlgorithmPeriodic.hpp index 1fa3a6b914ddbea86465c517815b0ca43a5a48c4..1a005e55ab71c7e5d3f258a06ffb1f5c1d92e9a3 100644 --- a/Src/Core/FFmmAlgorithmPeriodic.hpp +++ b/Src/Core/FFmmAlgorithmPeriodic.hpp @@ -232,16 +232,15 @@ private: octreeIterator.gotoBottomLeft(); // There is a maximum of 26 neighbors ContainerClass* neighbors[26]; - FTreeCoordinate neighborsPosition[26]; // for each leafs do{ FDEBUG(computationCounterL2P.tic()); kernels->L2P(octreeIterator.getCurrentCell(), octreeIterator.getCurrentListTargets()); FDEBUG(computationCounterL2P.tac()); // need the current particles and neighbors particles - const int counter = tree->getLeafsNeighborsWithIndex(neighbors, neighborsPosition, octreeIterator.getCurrentGlobalIndex(),heightMinusOne); + const int counter = tree->getPeriodicLeafsNeighbors(neighbors, octreeIterator.getCurrentGlobalCoordinate(),heightMinusOne); FDEBUG(computationCounterP2P.tic()); - kernels->P2P(octreeIterator.getCurrentGlobalIndex(),octreeIterator.getCurrentListTargets(), octreeIterator.getCurrentListSrc() , neighbors, neighborsPosition, counter); + kernels->P2P(octreeIterator.getCurrentGlobalIndex(),octreeIterator.getCurrentListTargets(), octreeIterator.getCurrentListSrc() , neighbors, counter); FDEBUG(computationCounterP2P.tac()); } while(octreeIterator.moveRight()); diff --git a/Src/Core/FFmmAlgorithmTask.hpp b/Src/Core/FFmmAlgorithmTask.hpp index 7f299af1d1f2a3d1bb4a48be9f341c7cfdcfbfba..7a6bac76dc6209b8e4335c83e51e42a132316b0a 100644 --- a/Src/Core/FFmmAlgorithmTask.hpp +++ b/Src/Core/FFmmAlgorithmTask.hpp @@ -282,7 +282,6 @@ private: KernelClass*const myThreadkernels = kernels[omp_get_thread_num()]; // There is a maximum of 26 neighbors ContainerClass* neighbors[26]; - MortonIndex neighborsIndex[26]; #pragma omp single nowait { @@ -306,8 +305,8 @@ private: #pragma omp task { // need the current particles and neighbors particles - const int counter = tree->getLeafsNeighborsWithIndex(neighbors, neighborsIndex, octreeIterator.getCurrentGlobalIndex(),heightMinusOne); - myThreadkernels->P2P(octreeIterator.getCurrentGlobalIndex(),octreeIterator.getCurrentListTargets(), octreeIterator.getCurrentListSrc() , neighbors, neighborsIndex, counter); + const int counter = tree->getLeafsNeighbors(neighbors, octreeIterator.getCurrentGlobalCoordinate(),heightMinusOne); + myThreadkernels->P2P(octreeIterator.getCurrentGlobalIndex(),octreeIterator.getCurrentListTargets(), octreeIterator.getCurrentListSrc() , neighbors, counter); } } else{ @@ -324,8 +323,8 @@ private: typename OctreeClass::Iterator toWork = shapes[idxShape][iterLeaf]; #pragma omp task { - const int counter = tree->getLeafsNeighborsWithIndex(neighbors, neighborsIndex, toWork.getCurrentGlobalIndex(),heightMinusOne); - myThreadkernels->P2P(toWork.getCurrentGlobalIndex(),toWork.getCurrentListTargets(), toWork.getCurrentListSrc() , neighbors, neighborsIndex, counter); + const int counter = tree->getLeafsNeighbors(neighbors, toWork.getCurrentGlobalCoordinate(),heightMinusOne); + myThreadkernels->P2P(toWork.getCurrentGlobalIndex(),toWork.getCurrentListTargets(), toWork.getCurrentListSrc() , neighbors, counter); } } diff --git a/Src/Core/FFmmAlgorithmThread.hpp b/Src/Core/FFmmAlgorithmThread.hpp index 7556bdabd4bc5a5f7f9e51ebc85f48841fc2381c..be47737e5a58f356445e3f98c9629c41c2425078 100644 --- a/Src/Core/FFmmAlgorithmThread.hpp +++ b/Src/Core/FFmmAlgorithmThread.hpp @@ -331,7 +331,7 @@ private: startPosAtShape[idxShape] = startPosAtShape[idxShape-1] + this->shapeLeaf[idxShape-1]; } -#pragma omp parallel + #pragma omp parallel { const float step = float(this->leafsNumber) / float(omp_get_num_threads()); @@ -365,27 +365,26 @@ private: octreeIterator.moveRight(); } -#pragma omp barrier + #pragma omp barrier FDEBUG(if(!omp_get_thread_num()) computationCounter.tic()); KernelClass& myThreadkernels = (*kernels[omp_get_thread_num()]); // There is a maximum of 26 neighbors ContainerClass* neighbors[26]; - MortonIndex neighborsIndex[26]; int previous = 0; for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){ const int endAtThisShape = this->shapeLeaf[idxShape] + previous; -#pragma omp for schedule(dynamic) + #pragma omp for schedule(dynamic) for(int idxLeafs = previous ; idxLeafs < endAtThisShape ; ++idxLeafs){ LeafData& currentIter = leafsDataArray[idxLeafs]; myThreadkernels.L2P(currentIter.cell, currentIter.targets); // need the current particles and neighbors particles FDEBUG(if(!omp_get_thread_num()) computationCounterP2P.tic()); - const int counter = tree->getLeafsNeighborsWithIndex(neighbors, neighborsIndex, currentIter.index, LeafIndex); - myThreadkernels.P2P(currentIter.index, currentIter.targets, currentIter.sources , neighbors, neighborsIndex, counter); + const int counter = tree->getLeafsNeighbors(neighbors, currentIter.cell->getCoordinate(), LeafIndex); + myThreadkernels.P2P(currentIter.index, currentIter.targets, currentIter.sources , neighbors, counter); FDEBUG(if(!omp_get_thread_num()) computationCounterP2P.tac()); } diff --git a/Src/Core/FFmmAlgorithmThreadProc.hpp b/Src/Core/FFmmAlgorithmThreadProc.hpp index cb2ba0ec75a1f0c5929676a17592fdb37cdc77fb..43abacf61d5b36e0151515ff93fa935950b49d7e 100644 --- a/Src/Core/FFmmAlgorithmThreadProc.hpp +++ b/Src/Core/FFmmAlgorithmThreadProc.hpp @@ -728,12 +728,15 @@ private: int counter = 0; // does we receive this index from someone? for(int idxNeig = 0 ;idxNeig < counterNeighbors ; ++idxNeig){ - const void* const cellFromOtherProc = tempTree.getCell(neighborsIndex[idxNeig], idxLevel); - if(cellFromOtherProc){ - neighborsData[counter].deserializeUp(cellFromOtherProc); - neighborsData[counter].setMortonIndex(neighborsIndex[idxNeig]); - neighbors[ neighborsPosition[counter] ] = &neighborsData[counter]; - ++counter; + if(neighborsIndex[idxNeig] < getWorkingInterval(idxLevel , idProcess).min + || getWorkingInterval(idxLevel , idProcess).max < neighborsIndex[idxNeig]){ + const void* const cellFromOtherProc = tempTree.getCell(neighborsIndex[idxNeig], idxLevel); + if(cellFromOtherProc){ + neighborsData[counter].deserializeUp(cellFromOtherProc); + neighborsData[counter].setMortonIndex(neighborsIndex[idxNeig]); + neighbors[ neighborsPosition[counter] ] = &neighborsData[counter]; + ++counter; + } } } // need to compute @@ -1111,26 +1114,25 @@ private: FDEBUG(FTic computationCounter); -#pragma omp parallel + #pragma omp parallel { KernelClass& myThreadkernels = (*kernels[omp_get_thread_num()]); // There is a maximum of 26 neighbors ContainerClass* neighbors[26]; - MortonIndex neighborsIndex[26]; int previous = 0; for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){ const int endAtThisShape = shapeLeaf[idxShape] + previous; -#pragma omp for schedule(dynamic) + #pragma omp for schedule(dynamic) for(int idxLeafs = previous ; idxLeafs < endAtThisShape ; ++idxLeafs){ if(!leafsNeedOtherShaped.get(idxLeafs)){ LeafData& currentIter = leafsDataArray[idxLeafs]; myThreadkernels.L2P(currentIter.cell, currentIter.targets); // need the current particles and neighbors particles - const int counter = tree->getLeafsNeighborsWithIndex(neighbors, neighborsIndex, currentIter.index, LeafIndex); - myThreadkernels.P2P( currentIter.index,currentIter.targets, currentIter.sources , neighbors, neighborsIndex, counter); + const int counter = tree->getLeafsNeighbors(neighbors, currentIter.cell->getCoordinate(), LeafIndex); + myThreadkernels.P2P( currentIter.index,currentIter.targets, currentIter.sources , neighbors, counter); } } @@ -1184,7 +1186,6 @@ private: KernelClass& myThreadkernels = (*kernels[omp_get_thread_num()]); // There is a maximum of 26 neighbors ContainerClass* neighbors[26]; - MortonIndex neighborsIndex[26]; int previous = 0; // Box limite const int limite = 1 << (this->OctreeHeight - 1); @@ -1192,7 +1193,7 @@ private: for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){ const int endAtThisShape = shapeLeaf[idxShape] + previous; -#pragma omp for schedule(dynamic) + #pragma omp for schedule(dynamic) for(int idxLeafs = previous ; idxLeafs < endAtThisShape ; ++idxLeafs){ // Maybe need also data from other? if(leafsNeedOtherShaped.get(idxLeafs)){ @@ -1200,7 +1201,7 @@ private: myThreadkernels.L2P(currentIter.cell, currentIter.targets); // need the current particles and neighbors particles - int counter = tree->getLeafsNeighborsWithIndex(neighbors, neighborsIndex, currentIter.index, LeafIndex); + int counter = tree->getLeafsNeighbors(neighbors, currentIter.cell->getCoordinate(), LeafIndex); // Take possible data MortonIndex indexesNeighbors[26]; @@ -1211,13 +1212,12 @@ private: ContainerClass*const hypotheticNeighbor = otherP2Ptree.getLeafSrc(indexesNeighbors[idxNeigh]); if(hypotheticNeighbor){ neighbors[counter] = hypotheticNeighbor; - neighborsIndex[counter] = indexesNeighbors[idxNeigh]; ++counter; } } } - myThreadkernels.P2P( currentIter.index,currentIter.targets, currentIter.sources , neighbors, neighborsIndex, counter); + myThreadkernels.P2P( currentIter.index,currentIter.targets, currentIter.sources , neighbors, counter); } } @@ -1277,7 +1277,7 @@ private: const FTreeCoordinate parentCell(workingCell.getX()>>1,workingCell.getY()>>1,workingCell.getZ()>>1); // Limite at parent level number of box (split by 2 by level) - const int limite = FMath::pow(2,inLevel-1); + const int limite = FMath::pow2(inLevel-1); int idxNeighbors = 0; // We test all cells around diff --git a/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp b/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp index 00d50da828894f5e458b1b71ae52b5861a10c767..6a78f0159e585428ea21965ab5d709033c7a5a88 100644 --- a/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp +++ b/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp @@ -801,12 +801,15 @@ private: int counter = 0; // does we receive this index from someone? for(int idxNeig = 0 ;idxNeig < counterNeighbors ; ++idxNeig){ - const void* const cellFromOtherProc = tempTree.getCell(neighborsIndex[idxNeig], idxLevel); - if(cellFromOtherProc){ - neighborsData[counter].deserializeUp(cellFromOtherProc); - neighborsData[counter].setMortonIndex(neighborsIndex[idxNeig]); - neighbors[ neighborsPosition[counter] ] = &neighborsData[counter]; - ++counter; + if(neighborsIndex[idxNeig] < getWorkingInterval(idxLevel , idProcess).min + || getWorkingInterval(idxLevel , idProcess).max < neighborsIndex[idxNeig]){ + const void* const cellFromOtherProc = tempTree.getCell(neighborsIndex[idxNeig], idxLevel); + if(cellFromOtherProc){ + neighborsData[counter].deserializeUp(cellFromOtherProc); + neighborsData[counter].setMortonIndex(neighborsIndex[idxNeig]); + neighbors[ neighborsPosition[counter] ] = &neighborsData[counter]; + ++counter; + } } } @@ -1036,9 +1039,9 @@ private: memset(alreadySent, 0, sizeof(int) * nbProcess); bool needOther = false; - const int neighCount = getNeighborsIndexes(iterArray[idxLeaf].getCurrentGlobalIndex(), limite, indexesNeighbors); + getNeighborsIndexes(iterArray[idxLeaf].getCurrentGlobalCoordinate(), limite, indexesNeighbors); - for(int idxNeigh = 0 ; idxNeigh < neighCount ; ++idxNeigh){ + for(int idxNeigh = 0 ; idxNeigh < 26 ; ++idxNeigh){ if(indexesNeighbors[idxNeigh] < intervals[idProcess].min || intervals[idProcess].max < indexesNeighbors[idxNeigh]){ needOther = true; @@ -1188,26 +1191,25 @@ private: FDEBUG(FTic computationCounter); -#pragma omp parallel + #pragma omp parallel { KernelClass& myThreadkernels = (*kernels[omp_get_thread_num()]); // There is a maximum of 26 neighbors ContainerClass* neighbors[26]; - FTreeCoordinate neighborsPosition[26]; int previous = 0; for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){ const int endAtThisShape = shapeLeaf[idxShape] + previous; -#pragma omp for schedule(dynamic) + #pragma omp for schedule(dynamic) for(int idxLeafs = previous ; idxLeafs < endAtThisShape ; ++idxLeafs){ if(!leafsNeedOtherShaped.get(idxLeafs)){ LeafData& currentIter = leafsDataArray[idxLeafs]; myThreadkernels.L2P(currentIter.cell, currentIter.targets); // need the current particles and neighbors particles - const int counter = tree->getLeafsNeighborsWithIndex(neighbors, neighborsPosition, currentIter.index, LeafIndex); - myThreadkernels.P2P( currentIter.index,currentIter.targets, currentIter.sources , neighbors, neighborsPosition, counter); + const int counter = tree->getPeriodicLeafsNeighbors(neighbors, currentIter.cell->getCoordinate(), LeafIndex); + myThreadkernels.P2P( currentIter.index,currentIter.targets, currentIter.sources , neighbors, counter); } } @@ -1256,12 +1258,13 @@ private: FTRACE( FTrace::FRegion regionOtherTrace("Compute P2P Other", __FUNCTION__ , __FILE__ , __LINE__) ); FDEBUG( computation2Counter.tic() ); -#pragma omp parallel + #pragma omp parallel { KernelClass& myThreadkernels = (*kernels[omp_get_thread_num()]); // There is a maximum of 26 neighbors ContainerClass* neighbors[26]; - //MortonIndex neighborsIndex[26]; + MortonIndex indexesNeighbors[26]; + int previous = 0; // Box limite const int limite = 1 << (this->OctreeHeight - 1); @@ -1269,7 +1272,7 @@ private: for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){ const int endAtThisShape = shapeLeaf[idxShape] + previous; -#pragma omp for schedule(dynamic) + #pragma omp for schedule(dynamic) for(int idxLeafs = previous ; idxLeafs < endAtThisShape ; ++idxLeafs){ // Maybe need also data from other? if(leafsNeedOtherShaped.get(idxLeafs)){ @@ -1277,33 +1280,30 @@ private: myThreadkernels.L2P(currentIter.cell, currentIter.targets); // need the current particles and neighbors particles - // int counter = tree->getLeafsNeighborsWithIndex(neighbors, neighborsIndex, currentIter.index, LeafIndex); + // int counter = tree->getLeafsNeighbors(neighbors, neighborsIndex, currentIter.index, LeafIndex); int counter = 0; + memset(neighbors, 0, 26 * sizeof(ContainerClass*)); // Take possible data - MortonIndex indexesNeighbors[26]; - FTreeCoordinate neighborsPosition[26]; - const int neighCount = getNeighborsIndexes(currentIter.index, limite, indexesNeighbors, neighborsPosition); + getNeighborsIndexes(currentIter.cell->getCoordinate(), limite, indexesNeighbors); - for(int idxNeigh = 0 ; idxNeigh < neighCount ; ++idxNeigh){ + for(int idxNeigh = 0 ; idxNeigh < 26 ; ++idxNeigh){ if(indexesNeighbors[idxNeigh] < intervals[idProcess].min || intervals[idProcess].max < indexesNeighbors[idxNeigh]){ ContainerClass*const hypotheticNeighbor = otherP2Ptree.getLeafSrc(indexesNeighbors[idxNeigh]); if(hypotheticNeighbor){ - neighbors[counter] = hypotheticNeighbor; - neighborsPosition[counter] = neighborsPosition[idxNeigh]; + neighbors[idxNeigh] = hypotheticNeighbor; ++counter; } } else{ ContainerClass*const hypotheticNeighbor = tree->getLeafSrc(indexesNeighbors[idxNeigh]); if(hypotheticNeighbor){ - neighbors[counter] = hypotheticNeighbor; - neighborsPosition[counter] = neighborsPosition[idxNeigh]; + neighbors[idxNeigh] = hypotheticNeighbor; ++counter; } } } - myThreadkernels.P2P( currentIter.index,currentIter.targets, currentIter.sources , neighbors, neighborsPosition, counter); + myThreadkernels.P2P( currentIter.index,currentIter.targets, currentIter.sources , neighbors, counter); } } @@ -1331,15 +1331,8 @@ private: } - int getNeighborsIndexes(const MortonIndex centerIndex, const int limite, MortonIndex indexes[26]) const{ - FTreeCoordinate relativePositions[26]; - return getNeighborsIndexes(centerIndex, limite, indexes, relativePositions); - } - - int getNeighborsIndexes(const MortonIndex centerIndex, const int limite, MortonIndex indexes[26], FTreeCoordinate inRelativePositions[26]) const{ - FTreeCoordinate center; - center.setPositionFromMorton(centerIndex, OctreeHeight - 1); + void getNeighborsIndexes(const FTreeCoordinate& center, const int limite, MortonIndex indexes[26]) const{ int idxNeig = 0; // We test all cells around for(int idxX = -1 ; idxX <= 1 ; ++idxX){ @@ -1358,16 +1351,12 @@ private: if( other.getZ() < 0 ) other.setZ( other.getZ() + limite ); else if( limite <= other.getZ() ) other.setZ( other.getZ() - limite ); - inRelativePositions[idxNeig].setPosition( idxX, - idxY, - idxZ); - indexes[idxNeig++] = other.getMortonIndex(this->OctreeHeight - 1); - + indexes[idxNeig] = other.getMortonIndex(this->OctreeHeight - 1); } + ++idxNeig; } } } - return idxNeig; } @@ -1378,7 +1367,7 @@ private: const FTreeCoordinate parentCell(workingCell.getX()>>1,workingCell.getY()>>1,workingCell.getZ()>>1); // Limite at parent level number of box (split by 2 by level) - const int limite = FMath::pow(2,inLevel-1); + const int limite = FMath::pow2(inLevel-1); int idxNeighbors = 0; // We test all cells around diff --git a/Src/Core/FFmmAlgorithmThreadTsm.hpp b/Src/Core/FFmmAlgorithmThreadTsm.hpp index 300188c6244c391380c21376aa4cd0dbf2306a87..44d8c75fa021a82063a849f7b9f06edb7026c610 100644 --- a/Src/Core/FFmmAlgorithmThreadTsm.hpp +++ b/Src/Core/FFmmAlgorithmThreadTsm.hpp @@ -349,7 +349,7 @@ public: for(int idxLeafs = 0 ; idxLeafs < numberOfLeafs ; ++idxLeafs){ myThreadkernels->L2P(iterArray[idxLeafs].getCurrentCell(), iterArray[idxLeafs].getCurrentListTargets()); // need the current particles and neighbors particles - const int counter = tree->getLeafsNeighbors(neighbors, iterArray[idxLeafs].getCurrentGlobalIndex(),heightMinusOne); + const int counter = tree->getLeafsNeighbors(neighbors, iterArray[idxLeafs].getCurrentGlobalCoordinate(),heightMinusOne); myThreadkernels->P2P( iterArray[idxLeafs].getCurrentListTargets(), iterArray[idxLeafs].getCurrentListSrc() , neighbors, counter); } } diff --git a/Src/Core/FFmmAlgorithmTsm.hpp b/Src/Core/FFmmAlgorithmTsm.hpp index c83a0d7dac395f2158738cea167f259450f36e77..6198e120b125a7e5de4a9625e64723a68ac164ae 100644 --- a/Src/Core/FFmmAlgorithmTsm.hpp +++ b/Src/Core/FFmmAlgorithmTsm.hpp @@ -280,7 +280,7 @@ public: FDEBUG(computationCounter.tic()); kernels->L2P(octreeIterator.getCurrentCell(), octreeIterator.getCurrentListTargets()); // need the current particles and neighbors particles - const int counter = tree->getLeafsNeighbors(neighbors, octreeIterator.getCurrentGlobalIndex(),heightMinusOne); + const int counter = tree->getLeafsNeighbors(neighbors, octreeIterator.getCurrentGlobalCoordinate(), heightMinusOne); kernels->P2P( octreeIterator.getCurrentListTargets(), octreeIterator.getCurrentListSrc() , neighbors, counter); FDEBUG(computationCounter.tac()); FDEBUG(totalComputation += computationCounter.elapsed()); diff --git a/Src/Kernels/FAbstractSphericalKernel.hpp b/Src/Kernels/FAbstractSphericalKernel.hpp index c2b9d82273a0341a92dba9e028b5624cdc3070ec..6827ff78cac5d41a25a652103a18d60fda34b133 100644 --- a/Src/Kernels/FAbstractSphericalKernel.hpp +++ b/Src/Kernels/FAbstractSphericalKernel.hpp @@ -249,7 +249,7 @@ public: */ void P2P(const MortonIndex inCurrentIndex, ContainerClass* const FRestrict targets, const ContainerClass* const FRestrict /*sources*/, - ContainerClass* const directNeighbors[26], const MortonIndex inNeighborsIndex[26], const int size){ + ContainerClass* const directNeighbors[26], const int size){ { // Compute interaction in this leaf typename ContainerClass::BasicIterator iterTarget(*targets); while( iterTarget.hasNotFinished() ){ @@ -271,7 +271,7 @@ public: { // Compute interactions with other leaves // For all the neigbors leaves for(int idxDirectNeighbors = 0 ; idxDirectNeighbors < size ; ++idxDirectNeighbors){ - if(inCurrentIndex < inNeighborsIndex[idxDirectNeighbors] ){ + if(inCurrentIndex < 0 /*inNeighborsIndex[idxDirectNeighbors] TODO */ ){ // For all particles in current leaf typename ContainerClass::BasicIterator iterTarget(*targets); while( iterTarget.hasNotFinished() ){ @@ -297,8 +297,8 @@ public: /** After Downward */ - void P2P(const MortonIndex inCurrentIndex, - ContainerClass* const FRestrict targets, const ContainerClass* const FRestrict /*sources*/, + /*void P2P(const MortonIndex inCurrentIndex, + ContainerClass* const FRestrict targets, const ContainerClass* const FRestrict ,//sources ContainerClass* const directNeighbors[26], const FTreeCoordinate neighborsRelativeOffset[26], const int size) { { // Compute interaction in this leaf @@ -358,7 +358,7 @@ public: } } } - } + }*/ /////////////////////////////////////////////////////////////////////////////// // Computation diff --git a/Src/Utils/FMath.hpp b/Src/Utils/FMath.hpp index 0032b18d791824e42d9b8773ce5340609fd66e26..d852e779ae909403e854f247109ad72335f3a1a0 100644 --- a/Src/Utils/FMath.hpp +++ b/Src/Utils/FMath.hpp @@ -80,6 +80,11 @@ struct FMath{ return result; } + /** To get pow of 2 */ + static int pow2(const int power){ + return (1 << power); + } + /** To know if a value is between two others */ template <class NumType> static bool Between(const NumType inValue, const NumType inMin, const NumType inMax){ diff --git a/Tests/testFmmAlgorithmPeriodic.cpp b/Tests/testFmmAlgorithmPeriodic.cpp index c43c71aab2fa3687ab65885221ed2a4b93a604dd..7034a85b86dc40831510983ce89009f6203fc55c 100644 --- a/Tests/testFmmAlgorithmPeriodic.cpp +++ b/Tests/testFmmAlgorithmPeriodic.cpp @@ -27,7 +27,7 @@ #include "../Src/Components/FTestParticle.hpp" #include "../Src/Components/FTestCell.hpp" -#include "../Src/Components/FTestPeriodicKernels.hpp" +#include "../Src/Components/FTestKernels.hpp" #include "../Src/Core/FFmmAlgorithmPeriodic.hpp" @@ -45,7 +45,7 @@ int main(int argc, char ** argv){ typedef FSimpleLeaf<ParticleClass, ContainerClass > LeafClass; typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass > OctreeClass; - typedef FTestPeriodicKernels<ParticleClass, CellClass, ContainerClass > KernelClass; + typedef FTestKernels<ParticleClass, CellClass, ContainerClass > KernelClass; typedef FFmmAlgorithmPeriodic<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass; ///////////////////////What we do///////////////////////////// diff --git a/Tests/testFmmAlgorithmProcPeriodic.cpp b/Tests/testFmmAlgorithmProcPeriodic.cpp index 880f88afa7ffff51a8fc0f94b7e23a765c9c9ff5..a25701e53564cda3647b84377bb464906d769eed 100644 --- a/Tests/testFmmAlgorithmProcPeriodic.cpp +++ b/Tests/testFmmAlgorithmProcPeriodic.cpp @@ -27,7 +27,7 @@ #include "../Src/Components/FTestParticle.hpp" #include "../Src/Components/FTestCell.hpp" -#include "../Src/Components/FTestPeriodicKernels.hpp" +#include "../Src/Components/FTestKernels.hpp" #include "../Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp" @@ -69,7 +69,7 @@ int main(int argc, char ** argv){ typedef FSimpleLeaf<ParticleClass, ContainerClass > LeafClass; typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass > OctreeClass; - typedef FTestPeriodicKernels<ParticleClass, CellClass, ContainerClass > KernelClass; + typedef FTestKernels<ParticleClass, CellClass, ContainerClass > KernelClass; typedef FFmmAlgorithmThreadProcPeriodic<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass; ///////////////////////What we do///////////////////////////// diff --git a/Tests/testFmmDemonstration.cpp b/Tests/testFmmDemonstration.cpp index 40f5cd117c48c32b4adee37717b51be83195cc1b..8e760f5a58a509acaff886b86be0117abd4a546e 100644 --- a/Tests/testFmmDemonstration.cpp +++ b/Tests/testFmmDemonstration.cpp @@ -107,7 +107,7 @@ public: void P2P(const MortonIndex , ContainerClass* const FRestrict , const ContainerClass* const FRestrict , - ContainerClass* const [26], const MortonIndex [26], const int ){ + ContainerClass* const [26], const int ){ } }; diff --git a/Tests/testStatsTree.cpp b/Tests/testStatsTree.cpp index 13b49a004ae2dc2d2d12a46d56e9ff562732ad87..20833179210ac108642c26bf26b5215b2d411c09 100644 --- a/Tests/testStatsTree.cpp +++ b/Tests/testStatsTree.cpp @@ -153,7 +153,7 @@ int main(int argc, char ** argv){ do{ ContainerClass* neighbors[26]; // need the current particles and neighbors particles - averageNeighbors += FReal(tree.getLeafsNeighbors(neighbors, octreeIterator.getCurrentGlobalIndex(),NbLevels-1)); + averageNeighbors += FReal(tree.getLeafsNeighbors(neighbors, octreeIterator.getCurrentGlobalCoordinate(),NbLevels-1)); ++nbLeafs; } while(octreeIterator.moveRight()); std::cout << "[STAT] Average neighbors for each leafs = " << (averageNeighbors/FReal(nbLeafs)) << std::endl; diff --git a/UTests/utestFmbDirectPeriodic.cpp b/UTests/utestFmbDirectPeriodic.cpp index 2d6302dbdbc789235bebd04b1fdd1077ac1ed60a..54c8704209a6217ea2e625387ed9056ab7b86020 100644 --- a/UTests/utestFmbDirectPeriodic.cpp +++ b/UTests/utestFmbDirectPeriodic.cpp @@ -21,7 +21,7 @@ #include "FUTester.hpp" #include "../Src/Components/FTestCell.hpp" -#include "../Src/Components/FTestPeriodicKernels.hpp" +#include "../Src/Components/FTestKernels.hpp" #include "../Src/Components/FTestParticle.hpp" /* @@ -220,7 +220,7 @@ class TestFmbDirectPeriodic : public FUTester<TestFmbDirectPeriodic> { typedef FTestCell TestCellClass; typedef FVector<TestParticleClass> TestContainerClass; - typedef FTestPeriodicKernels<TestParticleClass, TestCellClass, TestContainerClass > TestKernelClass; + typedef FTestKernels<TestParticleClass, TestCellClass, TestContainerClass > TestKernelClass; typedef FSimpleLeaf<TestParticleClass, TestContainerClass > TestLeafClass; typedef FOctree<TestParticleClass, TestCellClass, TestContainerClass , TestLeafClass > TestOctreeClass;