FFmmAlgorithmThread.hpp 19.6 KB
Newer Older
1
// ===================================================================================
2
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Berenger Bramas, Matthias Messner
3 4 5 6
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
7 8
// abiding by the rules of distribution of free software.
//
9 10 11 12
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public and CeCILL-C Licenses for more details.
13
// "http://www.cecill.info".
14
// "http://www.gnu.org/licenses".
15
// ===================================================================================
16 17
#ifndef FFMMALGORITHMTHREAD_HPP
#define FFMMALGORITHMTHREAD_HPP
18

19

BRAMAS Berenger's avatar
BRAMAS Berenger committed
20
#include "../Utils/FAssert.hpp"
BRAMAS Berenger's avatar
BRAMAS Berenger committed
21
#include "../Utils/FLog.hpp"
22

23 24
#include "../Utils/FTic.hpp"
#include "../Utils/FGlobal.hpp"
25
#include "Utils/FAlgorithmTimers.hpp"
26 27 28

#include "../Containers/FOctree.hpp"

29
#include "FCoreCommon.hpp"
30 31 32 33

#include <omp.h>

/**
34 35
* \author Berenger Bramas (berenger.bramas@inria.fr)
* \brief Implements an FMM algorithm threaded using OpenMP.
36
*
37
* Please read the license
38
*
39 40 41 42
* This class runs a threaded FMM algorithm.  It just iterates on a tree and call
* the kernels with good arguments.  The inspector-executor model is used : the
* class iterates on the tree and builds an array and works in parallel on this
* array.
43
*
berenger-bramas's avatar
berenger-bramas committed
44
* When using this algorithm the P2P is thread safe.
45 46
*
* This class does not deallocate pointers given to its constructor.
47
*/
48
template<class OctreeClass, class CellClass, class ContainerClass, class KernelClass, class LeafClass>
49
class FFmmAlgorithmThread : public FAbstractAlgorithm, public FAlgorithmTimers{
50 51
    OctreeClass* const tree;                  ///< The octree to work on.
    KernelClass** kernels;                    ///< The kernels.
52

berenger-bramas's avatar
berenger-bramas committed
53
    typename OctreeClass::Iterator* iterArray;
54
    int leafsNumber;
55 56

    static const int SizeShape = 3*3*3;
57
    int shapeLeaf[SizeShape];
berenger-bramas's avatar
berenger-bramas committed
58

59
    const int MaxThreads;                     ///< The maximum number of threads.
60

61
    const int OctreeHeight;                   ///< The height of the given tree.
62

63 64
    const bool staticSchedule;

65 66
    const int leafLevelSeperationCriteria;

67 68 69 70 71 72 73 74 75 76
    template <class NumType>
    NumType getChunkSize(const NumType inSize) const {
        if(staticSchedule){
            return FMath::Max(NumType(1) , NumType(double(inSize)/double(omp_get_max_threads())) );
        }
        else{
            return FMath::Max(NumType(1) , inSize/NumType(omp_get_max_threads()*omp_get_max_threads()));
        }
    }

77
public:
78 79 80 81 82
    /** Class constructor
     * 
     * The constructor needs the octree and the kernels used for computation.
     * \param inTree the octree to work on.
     * \param inKernels the kernels to call.
83
     * \param inStaticSchedule Whether to use static or dynamic OpenMP scheduling.
84 85 86
     *
     * \except An exception is thrown if one of the arguments is NULL.
     */
87
    FFmmAlgorithmThread(OctreeClass* const inTree, KernelClass* const inKernels,
88
                        const bool inStaticSchedule = true, const int inLeafLevelSeperationCriteria = 1)
89
        : tree(inTree) , kernels(nullptr), iterArray(nullptr), leafsNumber(0),
90
          MaxThreads(omp_get_max_threads()), OctreeHeight(tree->getHeight()),
91
          staticSchedule(inStaticSchedule), leafLevelSeperationCriteria(inLeafLevelSeperationCriteria) {
92

BRAMAS Berenger's avatar
BRAMAS Berenger committed
93
        FAssertLF(tree, "tree cannot be null");
94

berenger-bramas's avatar
berenger-bramas committed
95
        this->kernels = new KernelClass*[MaxThreads];
96
        #pragma omp parallel for schedule(static)
berenger-bramas's avatar
berenger-bramas committed
97
        for(int idxThread = 0 ; idxThread < MaxThreads ; ++idxThread){
98
            #pragma omp critical (InitFFmmAlgorithmThread)
99 100 101
            {
                this->kernels[idxThread] = new KernelClass(*inKernels);
            }
102 103
        }

104 105
        FAbstractAlgorithm::setNbLevelsInTree(tree->getHeight());

BRAMAS Berenger's avatar
BRAMAS Berenger committed
106
        FLOG(FLog::Controller << "FFmmAlgorithmThread (Max Thread " << omp_get_max_threads() << ")\n");
107
        FLOG(FLog::Controller << "\t static schedule " << (staticSchedule?"TRUE":"FALSE") << ")\n");
108 109 110 111
    }

    /** Default destructor */
    virtual ~FFmmAlgorithmThread(){
berenger-bramas's avatar
berenger-bramas committed
112
        for(int idxThread = 0 ; idxThread < MaxThreads ; ++idxThread){
113 114
            delete this->kernels[idxThread];
        }
berenger-bramas's avatar
berenger-bramas committed
115
        delete [] this->kernels;
116 117
    }

118
protected:
119
    /**
120
      * Runs the complete algorithm.
121
      */
122
    void executeCore(const unsigned operationsToProceed) override {
123 124 125 126 127 128

        for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){
            this->shapeLeaf[idxShape] = 0;
        }

        // Count leaf
129
        leafsNumber = 0;
berenger-bramas's avatar
berenger-bramas committed
130
        typename OctreeClass::Iterator octreeIterator(tree);
131 132
        octreeIterator.gotoBottomLeft();
        do{
133
            ++leafsNumber;
134
            const FTreeCoordinate& coord = octreeIterator.getCurrentCell()->getCoordinate();
135 136 137
            ++this->shapeLeaf[(coord.getX()%3)*9 + (coord.getY()%3)*3 + (coord.getZ()%3)];

        } while(octreeIterator.moveRight());
berenger-bramas's avatar
berenger-bramas committed
138
        iterArray = new typename OctreeClass::Iterator[leafsNumber];
BRAMAS Berenger's avatar
BRAMAS Berenger committed
139
        FAssertLF(iterArray, "iterArray bad alloc");
140

141
        Timers[P2MTimer].tic();
142
        if(operationsToProceed & FFmmP2M) bottomPass();
143
        Timers[P2MTimer].tac();
144

145
        Timers[M2MTimer].tic();
146
        if(operationsToProceed & FFmmM2M) upwardPass();
147
        Timers[M2MTimer].tac();
148

149
        Timers[M2LTimer].tic();
150
        if(operationsToProceed & FFmmM2L) transferPass();
151
        Timers[M2LTimer].tac();
152

153
        Timers[L2LTimer].tic();
154
        if(operationsToProceed & FFmmL2L) downardPass();
155
        Timers[L2LTimer].tac();
156

157 158 159
        Timers[NearTimer].tic();
        if( (operationsToProceed & FFmmP2P) || (operationsToProceed & FFmmL2P) ) directPass((operationsToProceed & FFmmP2P),(operationsToProceed & FFmmL2P));
        Timers[NearTimer].tac();
160 161

        delete [] iterArray;
162
        iterArray = nullptr;
163 164
    }

berenger-bramas's avatar
berenger-bramas committed
165 166 167 168
    /////////////////////////////////////////////////////////////////////////////
    // P2M
    /////////////////////////////////////////////////////////////////////////////

169
    /** Runs the P2M kernel. */
170
    void bottomPass(){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
171
        FLOG( FLog::Controller.write("\tStart Bottom Pass\n").write(FLog::Flush) );
BRAMAS Berenger's avatar
BRAMAS Berenger committed
172
        FLOG(FTic counterTime);
173

berenger-bramas's avatar
berenger-bramas committed
174
        typename OctreeClass::Iterator octreeIterator(tree);
175 176 177 178 179 180 181 182
        int leafs = 0;
        // Iterate on leafs
        octreeIterator.gotoBottomLeft();
        do{
            iterArray[leafs] = octreeIterator;
            ++leafs;
        } while(octreeIterator.moveRight());

183
        const int chunkSize = getChunkSize(leafs);
184

BRAMAS Berenger's avatar
BRAMAS Berenger committed
185
        FLOG(FTic computationCounter);
BRAMAS Berenger's avatar
BRAMAS Berenger committed
186
        #pragma omp parallel
187
        {
berenger-bramas's avatar
berenger-bramas committed
188
            KernelClass * const myThreadkernels = kernels[omp_get_thread_num()];
189
            #pragma omp for nowait schedule(dynamic, chunkSize)
190 191 192 193 194 195
            for(int idxLeafs = 0 ; idxLeafs < leafs ; ++idxLeafs){
                // We need the current cell that represent the leaf
                // and the list of particles
                myThreadkernels->P2M( iterArray[idxLeafs].getCurrentCell() , iterArray[idxLeafs].getCurrentListSrc());
            }
        }
BRAMAS Berenger's avatar
BRAMAS Berenger committed
196
        FLOG(computationCounter.tac() );
197

BRAMAS Berenger's avatar
BRAMAS Berenger committed
198 199
        FLOG( FLog::Controller << "\tFinished (@Bottom Pass (P2M) = "  << counterTime.tacAndElapsed() << "s)\n" );
        FLOG( FLog::Controller << "\t\t Computation : " << computationCounter.elapsed() << " s\n" );
200

201 202
    }

berenger-bramas's avatar
berenger-bramas committed
203 204 205 206
    /////////////////////////////////////////////////////////////////////////////
    // Upward
    /////////////////////////////////////////////////////////////////////////////

207
    /** Runs the M2M kernel. */
208
    void upwardPass(){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
209
        FLOG( FLog::Controller.write("\tStart Upward Pass\n").write(FLog::Flush); );
BRAMAS Berenger's avatar
BRAMAS Berenger committed
210 211
        FLOG(FTic counterTime);
        FLOG(FTic computationCounter);
212 213

        // Start from leal level - 1
berenger-bramas's avatar
berenger-bramas committed
214
        typename OctreeClass::Iterator octreeIterator(tree);
215 216
        octreeIterator.gotoBottomLeft();
        octreeIterator.moveUp();
217

218
        for(int idxLevel = OctreeHeight - 2 ; idxLevel > FAbstractAlgorithm::lowerWorkingLevel-1 ; --idxLevel){
219 220 221
            octreeIterator.moveUp();
        }

berenger-bramas's avatar
berenger-bramas committed
222
        typename OctreeClass::Iterator avoidGotoLeftIterator(octreeIterator);
223 224

        // for each levels
225
        for(int idxLevel = FMath::Min(OctreeHeight - 2, FAbstractAlgorithm::lowerWorkingLevel - 1) ; idxLevel >= FAbstractAlgorithm::upperWorkingLevel ; --idxLevel ){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
226
            FLOG(FTic counterTimeLevel);
227
            int numberOfCells = 0;
228 229
            // for each cells
            do{
230 231
                iterArray[numberOfCells] = octreeIterator;
                ++numberOfCells;
232 233 234 235
            } while(octreeIterator.moveRight());
            avoidGotoLeftIterator.moveUp();
            octreeIterator = avoidGotoLeftIterator;// equal octreeIterator.moveUp(); octreeIterator.gotoLeft();

236
            const int chunkSize = getChunkSize(numberOfCells);
237

BRAMAS Berenger's avatar
BRAMAS Berenger committed
238
            FLOG(computationCounter.tic());
239
            #pragma omp parallel
240
            {
berenger-bramas's avatar
berenger-bramas committed
241
                KernelClass * const myThreadkernels = kernels[omp_get_thread_num()];
242
                #pragma omp for nowait  schedule(dynamic, chunkSize)
243
                for(int idxCell = 0 ; idxCell < numberOfCells ; ++idxCell){
244 245
                    // We need the current cell and the child
                    // child is an array (of 8 child) that may be null
246
                    myThreadkernels->M2M( iterArray[idxCell].getCurrentCell() , iterArray[idxCell].getCurrentChild(), idxLevel);
247 248
                }
            }
berenger-bramas's avatar
berenger-bramas committed
249

BRAMAS Berenger's avatar
BRAMAS Berenger committed
250
            FLOG(computationCounter.tac());
BRAMAS Berenger's avatar
BRAMAS Berenger committed
251
            FLOG( FLog::Controller << "\t\t>> Level " << idxLevel << " = "  << counterTimeLevel.tacAndElapsed() << "s\n" );
252 253
        }

berenger-bramas's avatar
berenger-bramas committed
254

BRAMAS Berenger's avatar
BRAMAS Berenger committed
255 256
        FLOG( FLog::Controller << "\tFinished (@Upward Pass (M2M) = "  << counterTime.tacAndElapsed() << "s)\n" );
        FLOG( FLog::Controller << "\t\t Computation : " << computationCounter.cumulated() << " s\n" );
257

258 259
    }

berenger-bramas's avatar
berenger-bramas committed
260
    /////////////////////////////////////////////////////////////////////////////
261
    // Transfer
berenger-bramas's avatar
berenger-bramas committed
262 263
    /////////////////////////////////////////////////////////////////////////////

264
    /** Runs the M2L kernel. */
265
    void transferPass(){
266

BRAMAS Berenger's avatar
BRAMAS Berenger committed
267
        FLOG( FLog::Controller.write("\tStart Downward Pass (M2L)\n").write(FLog::Flush); );
BRAMAS Berenger's avatar
BRAMAS Berenger committed
268 269
        FLOG(FTic counterTime);
        FLOG(FTic computationCounter);
berenger-bramas's avatar
berenger-bramas committed
270

271 272
        typename OctreeClass::Iterator octreeIterator(tree);
        octreeIterator.moveDown();
273

274
        for(int idxLevel = 2 ; idxLevel < FAbstractAlgorithm::upperWorkingLevel ; ++idxLevel){
275 276 277
            octreeIterator.moveDown();
        }

278 279 280
        typename OctreeClass::Iterator avoidGotoLeftIterator(octreeIterator);

        // for each levels
281
        for(int idxLevel = FAbstractAlgorithm::upperWorkingLevel ; idxLevel < FAbstractAlgorithm::lowerWorkingLevel ; ++idxLevel ){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
282
            FLOG(FTic counterTimeLevel);
283
            const int separationCriteria = (idxLevel != FAbstractAlgorithm::lowerWorkingLevel-1 ? 1 : leafLevelSeperationCriteria);
284 285 286 287 288 289 290 291 292
            int numberOfCells = 0;
            // for each cells
            do{
                iterArray[numberOfCells] = octreeIterator;
                ++numberOfCells;
            } while(octreeIterator.moveRight());
            avoidGotoLeftIterator.moveDown();
            octreeIterator = avoidGotoLeftIterator;

293
            const int chunkSize = getChunkSize(numberOfCells);
294

BRAMAS Berenger's avatar
BRAMAS Berenger committed
295
            FLOG(computationCounter.tic());
296
            #pragma omp parallel
297 298
            {
                KernelClass * const myThreadkernels = kernels[omp_get_thread_num()];
299
                const CellClass* neighbors[343];
300

301
                #pragma omp for  schedule(dynamic, chunkSize) nowait
302
                for(int idxCell = 0 ; idxCell < numberOfCells ; ++idxCell){
303
                    const int counter = tree->getInteractionNeighbors(neighbors, iterArray[idxCell].getCurrentGlobalCoordinate(), idxLevel, separationCriteria);
304
                    if(counter) myThreadkernels->M2L( iterArray[idxCell].getCurrentCell() , neighbors, counter, idxLevel);
305
                }
306 307

                myThreadkernels->finishedLevelM2L(idxLevel);
308
            }
BRAMAS Berenger's avatar
BRAMAS Berenger committed
309
            FLOG(computationCounter.tac());
BRAMAS Berenger's avatar
BRAMAS Berenger committed
310
            FLOG( FLog::Controller << "\t\t>> Level " << idxLevel << " = "  << counterTimeLevel.tacAndElapsed() << "s\n" );
311 312
        }

BRAMAS Berenger's avatar
BRAMAS Berenger committed
313 314
        FLOG( FLog::Controller << "\tFinished (@Downward Pass (M2L) = "  << counterTime.tacAndElapsed() << "s)\n" );
        FLOG( FLog::Controller << "\t\t Computation : " << computationCounter.cumulated() << " s\n" );
315
    }
berenger-bramas's avatar
berenger-bramas committed
316

317
    /////////////////////////////////////////////////////////////////////////////
COULAUD Olivier's avatar
COULAUD Olivier committed
318
    // Downward
319 320
    /////////////////////////////////////////////////////////////////////////////

321 322
    /** Runs the L2L kernel. */
    void downardPass(){
323

BRAMAS Berenger's avatar
BRAMAS Berenger committed
324
        FLOG( FLog::Controller.write("\tStart Downward Pass (L2L)\n").write(FLog::Flush); );
BRAMAS Berenger's avatar
BRAMAS Berenger committed
325 326
        FLOG(FTic counterTime);
        FLOG(FTic computationCounter);
327 328 329 330

        typename OctreeClass::Iterator octreeIterator(tree);
        octreeIterator.moveDown();

331
        for(int idxLevel = 2 ; idxLevel < FAbstractAlgorithm::upperWorkingLevel ; ++idxLevel){
332 333 334
            octreeIterator.moveDown();
        }

335 336
        typename OctreeClass::Iterator avoidGotoLeftIterator(octreeIterator);

337
        const int heightMinusOne = FAbstractAlgorithm::lowerWorkingLevel - 1;
COULAUD Olivier's avatar
COULAUD Olivier committed
338
        // for each levels excepted leaf level
339
        for(int idxLevel = FAbstractAlgorithm::upperWorkingLevel ; idxLevel < heightMinusOne ; ++idxLevel ){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
340
            FLOG(FTic counterTimeLevel);
341 342 343 344 345 346 347 348 349
            int numberOfCells = 0;
            // for each cells
            do{
                iterArray[numberOfCells] = octreeIterator;
                ++numberOfCells;
            } while(octreeIterator.moveRight());
            avoidGotoLeftIterator.moveDown();
            octreeIterator = avoidGotoLeftIterator;

BRAMAS Berenger's avatar
BRAMAS Berenger committed
350
            FLOG(computationCounter.tic());
351
            const int chunkSize = getChunkSize(numberOfCells);
352
            #pragma omp parallel
353 354
            {
                KernelClass * const myThreadkernels = kernels[omp_get_thread_num()];
355
                #pragma omp for nowait schedule(dynamic, chunkSize)
356 357
                for(int idxCell = 0 ; idxCell < numberOfCells ; ++idxCell){
                    myThreadkernels->L2L( iterArray[idxCell].getCurrentCell() , iterArray[idxCell].getCurrentChild(), idxLevel);
358 359
                }
            }
BRAMAS Berenger's avatar
BRAMAS Berenger committed
360
            FLOG(computationCounter.tac());
BRAMAS Berenger's avatar
BRAMAS Berenger committed
361
            FLOG( FLog::Controller << "\t\t>> Level " << idxLevel << " = "  << counterTimeLevel.tacAndElapsed() << "s\n" );
362 363
        }

BRAMAS Berenger's avatar
BRAMAS Berenger committed
364 365
        FLOG( FLog::Controller << "\tFinished (@Downward Pass (L2L) = "  << counterTime.tacAndElapsed() << "s)\n" );
        FLOG( FLog::Controller << "\t\t Computation : " << computationCounter.cumulated() << " s\n" );
366 367
    }

368 369


berenger-bramas's avatar
berenger-bramas committed
370 371 372 373
    /////////////////////////////////////////////////////////////////////////////
    // Direct
    /////////////////////////////////////////////////////////////////////////////

374 375 376 377 378
    /** Runs the P2P & L2P kernels.
      *
     * \param p2pEnabled Run the P2P kernel.
     * \param l2pEnabled Run the L2P kernel.
     */
379
    void directPass(const bool p2pEnabled, const bool l2pEnabled){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
380
        FLOG( FLog::Controller.write("\tStart Direct Pass\n").write(FLog::Flush); );
BRAMAS Berenger's avatar
BRAMAS Berenger committed
381 382 383
        FLOG(FTic counterTime);
        FLOG(FTic computationCounter);
        FLOG(FTic computationCounterP2P);
384

385
        omp_lock_t lockShape[SizeShape];
386
        for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){
387
            omp_init_lock(&lockShape[idxShape]);
388 389
        }

390 391 392
        struct LeafData{
            MortonIndex index;
            CellClass* cell;
berenger-bramas's avatar
berenger-bramas committed
393 394
            ContainerClass* targets;
            ContainerClass* sources;
395 396 397
        };
        LeafData* const leafsDataArray = new LeafData[this->leafsNumber];

398
        const int LeafIndex = OctreeHeight - 1;
399 400 401 402 403 404 405

        int startPosAtShape[SizeShape];
        startPosAtShape[0] = 0;
        for(int idxShape = 1 ; idxShape < SizeShape ; ++idxShape){
            startPosAtShape[idxShape] = startPosAtShape[idxShape-1] + this->shapeLeaf[idxShape-1];
        }

406
        #pragma omp parallel
407
        {
408

409 410 411
            const float step = float(this->leafsNumber) / float(omp_get_num_threads());
            const int start = int(FMath::Ceil(step * float(omp_get_thread_num())));
            const int tempEnd = int(FMath::Ceil(step * float(omp_get_thread_num()+1)));
412
            const int end = (tempEnd > this->leafsNumber ? this->leafsNumber : tempEnd);
413

berenger-bramas's avatar
berenger-bramas committed
414
            typename OctreeClass::Iterator octreeIterator(tree);
415
            octreeIterator.gotoBottomLeft();
416 417 418 419 420

            for(int idxPreLeaf = 0 ; idxPreLeaf < start ; ++idxPreLeaf){
                octreeIterator.moveRight();
            }

421
            // for each leafs
422
            for(int idxMyLeafs = start ; idxMyLeafs < end ; ++idxMyLeafs){
423
                //iterArray[leafs] = octreeIterator;
424
                //++leafs;
425
                const FTreeCoordinate& coord = octreeIterator.getCurrentGlobalCoordinate();
426
                const int shapePosition = (coord.getX()%3)*9 + (coord.getY()%3)*3 + (coord.getZ()%3);
427

428 429 430
                omp_set_lock(&lockShape[shapePosition]);
                const int positionToWork = startPosAtShape[shapePosition]++;
                omp_unset_lock(&lockShape[shapePosition]);
431

COULAUD Olivier's avatar
COULAUD Olivier committed
432 433
                leafsDataArray[positionToWork].index   = octreeIterator.getCurrentGlobalIndex();
                leafsDataArray[positionToWork].cell    = octreeIterator.getCurrentCell();
434 435
                leafsDataArray[positionToWork].targets = octreeIterator.getCurrentListTargets();
                leafsDataArray[positionToWork].sources = octreeIterator.getCurrentListSrc();
436

437 438
                octreeIterator.moveRight();
            }
439

440
            #pragma omp barrier
441

BRAMAS Berenger's avatar
BRAMAS Berenger committed
442
            FLOG(if(!omp_get_thread_num()) computationCounter.tic());
443

berenger-bramas's avatar
berenger-bramas committed
444
            KernelClass& myThreadkernels = (*kernels[omp_get_thread_num()]);
445
            // There is a maximum of 26 neighbors
berenger-bramas's avatar
berenger-bramas committed
446
            ContainerClass* neighbors[27];
447
            int previous = 0;
448 449

            for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){
450
                const int endAtThisShape = this->shapeLeaf[idxShape] + previous;
451
                const int chunkSize = getChunkSize(endAtThisShape);
452
                #pragma omp for schedule(dynamic, chunkSize)
453 454
                for(int idxLeafs = previous ; idxLeafs < endAtThisShape ; ++idxLeafs){
                    LeafData& currentIter = leafsDataArray[idxLeafs];
455 456 457 458 459 460 461 462 463 464 465
                    if(l2pEnabled){
                        myThreadkernels.L2P(currentIter.cell, currentIter.targets);
                    }
                    if(p2pEnabled){
                        // need the current particles and neighbors particles
                        FLOG(if(!omp_get_thread_num()) computationCounterP2P.tic());
                        const int counter = tree->getLeafsNeighbors(neighbors, currentIter.cell->getCoordinate(), LeafIndex);
                        myThreadkernels.P2P(currentIter.cell->getCoordinate(), currentIter.targets,
                                            currentIter.sources, neighbors, counter);
                        FLOG(if(!omp_get_thread_num()) computationCounterP2P.tac());
                    }
466
                }
467 468

                previous = endAtThisShape;
469 470
            }
        }
471

BRAMAS Berenger's avatar
BRAMAS Berenger committed
472
        FLOG(computationCounter.tac());
473

474
        delete [] leafsDataArray;
475 476 477 478
        for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){
            omp_destroy_lock(&lockShape[idxShape]);
        }

479

BRAMAS Berenger's avatar
BRAMAS Berenger committed
480
        FLOG( FLog::Controller << "\tFinished (@Direct Pass (L2P + P2P) = "  << counterTime.tacAndElapsed() << "s)\n" );
COULAUD Olivier's avatar
COULAUD Olivier committed
481 482
        FLOG( FLog::Controller << "\t\t Computation L2P + P2P : " << computationCounter.cumulated()    << " s\n" );
        FLOG( FLog::Controller << "\t\t Computation P2P :       " << computationCounterP2P.cumulated() << " s\n" );
483

484 485 486 487 488 489
    }

};


#endif //FFMMALGORITHMTHREAD_HPP