FFmmAlgorithmThread.hpp 19.3 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 65 66 67 68 69 70 71 72 73 74
    const bool staticSchedule;

    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()));
        }
    }

75
public:
76 77 78 79 80
    /** 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.
81
     * \param inStaticSchedule Whether to use static or dynamic OpenMP scheduling.
82 83 84
     *
     * \except An exception is thrown if one of the arguments is NULL.
     */
85 86
    FFmmAlgorithmThread(OctreeClass* const inTree, KernelClass* const inKernels,
                        const bool inStaticSchedule = true)
87
        : tree(inTree) , kernels(nullptr), iterArray(nullptr), leafsNumber(0),
88 89
          MaxThreads(omp_get_max_threads()), OctreeHeight(tree->getHeight()),
          staticSchedule(inStaticSchedule) {
90

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

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

102 103
        FAbstractAlgorithm::setNbLevelsInTree(tree->getHeight());

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

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

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

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

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

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

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

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

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

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

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

        delete [] iterArray;
160
        iterArray = nullptr;
161 162
    }

berenger-bramas's avatar
berenger-bramas committed
163 164 165 166
    /////////////////////////////////////////////////////////////////////////////
    // P2M
    /////////////////////////////////////////////////////////////////////////////

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

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

181
        const int chunkSize = getChunkSize(leafs);
182

BRAMAS Berenger's avatar
BRAMAS Berenger committed
183
        FLOG(FTic computationCounter);
BRAMAS Berenger's avatar
BRAMAS Berenger committed
184
        #pragma omp parallel
185
        {
berenger-bramas's avatar
berenger-bramas committed
186
            KernelClass * const myThreadkernels = kernels[omp_get_thread_num()];
187
            #pragma omp for nowait schedule(dynamic, chunkSize)
188 189 190 191 192 193
            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
194
        FLOG(computationCounter.tac() );
195

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

199 200
    }

berenger-bramas's avatar
berenger-bramas committed
201 202 203 204
    /////////////////////////////////////////////////////////////////////////////
    // Upward
    /////////////////////////////////////////////////////////////////////////////

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

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

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

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

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

234
            const int chunkSize = getChunkSize(numberOfCells);
235

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

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

berenger-bramas's avatar
berenger-bramas committed
252

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

256 257
    }

berenger-bramas's avatar
berenger-bramas committed
258
    /////////////////////////////////////////////////////////////////////////////
259
    // Transfer
berenger-bramas's avatar
berenger-bramas committed
260 261
    /////////////////////////////////////////////////////////////////////////////

262
    /** Runs the M2L kernel. */
263
    void transferPass(){
264

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

269 270
        typename OctreeClass::Iterator octreeIterator(tree);
        octreeIterator.moveDown();
271

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

276 277 278
        typename OctreeClass::Iterator avoidGotoLeftIterator(octreeIterator);

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

290
            const int chunkSize = getChunkSize(numberOfCells);
291

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

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

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

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

314
    /////////////////////////////////////////////////////////////////////////////
COULAUD Olivier's avatar
COULAUD Olivier committed
315
    // Downward
316 317
    /////////////////////////////////////////////////////////////////////////////

318 319
    /** Runs the L2L kernel. */
    void downardPass(){
320

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

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

328
        for(int idxLevel = 2 ; idxLevel < FAbstractAlgorithm::upperWorkingLevel ; ++idxLevel){
329 330 331
            octreeIterator.moveDown();
        }

332 333
        typename OctreeClass::Iterator avoidGotoLeftIterator(octreeIterator);

334
        const int heightMinusOne = FAbstractAlgorithm::lowerWorkingLevel - 1;
COULAUD Olivier's avatar
COULAUD Olivier committed
335
        // for each levels excepted leaf level
336
        for(int idxLevel = FAbstractAlgorithm::upperWorkingLevel ; idxLevel < heightMinusOne ; ++idxLevel ){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
337
            FLOG(FTic counterTimeLevel);
338 339 340 341 342 343 344 345 346
            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
347
            FLOG(computationCounter.tic());
348
            const int chunkSize = getChunkSize(numberOfCells);
349
            #pragma omp parallel
350 351
            {
                KernelClass * const myThreadkernels = kernels[omp_get_thread_num()];
352
                #pragma omp for nowait schedule(dynamic, chunkSize)
353 354
                for(int idxCell = 0 ; idxCell < numberOfCells ; ++idxCell){
                    myThreadkernels->L2L( iterArray[idxCell].getCurrentCell() , iterArray[idxCell].getCurrentChild(), idxLevel);
355 356
                }
            }
BRAMAS Berenger's avatar
BRAMAS Berenger committed
357
            FLOG(computationCounter.tac());
BRAMAS Berenger's avatar
BRAMAS Berenger committed
358
            FLOG( FLog::Controller << "\t\t>> Level " << idxLevel << " = "  << counterTimeLevel.tacAndElapsed() << "s\n" );
359 360
        }

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

365 366


berenger-bramas's avatar
berenger-bramas committed
367 368 369 370
    /////////////////////////////////////////////////////////////////////////////
    // Direct
    /////////////////////////////////////////////////////////////////////////////

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

382
        omp_lock_t lockShape[SizeShape];
383
        for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){
384
            omp_init_lock(&lockShape[idxShape]);
385 386
        }

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

395
        const int LeafIndex = OctreeHeight - 1;
396 397 398 399 400 401 402

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

403
        #pragma omp parallel
404
        {
405

406 407 408
            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)));
409
            const int end = (tempEnd > this->leafsNumber ? this->leafsNumber : tempEnd);
410

berenger-bramas's avatar
berenger-bramas committed
411
            typename OctreeClass::Iterator octreeIterator(tree);
412
            octreeIterator.gotoBottomLeft();
413 414 415 416 417

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

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

425 426 427
                omp_set_lock(&lockShape[shapePosition]);
                const int positionToWork = startPosAtShape[shapePosition]++;
                omp_unset_lock(&lockShape[shapePosition]);
428

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

434 435
                octreeIterator.moveRight();
            }
436

437
            #pragma omp barrier
438

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

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

            for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){
447
                const int endAtThisShape = this->shapeLeaf[idxShape] + previous;
448
                const int chunkSize = getChunkSize(endAtThisShape);
449
                #pragma omp for schedule(dynamic, chunkSize)
450 451
                for(int idxLeafs = previous ; idxLeafs < endAtThisShape ; ++idxLeafs){
                    LeafData& currentIter = leafsDataArray[idxLeafs];
452 453 454 455 456 457 458 459 460 461 462
                    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());
                    }
463
                }
464 465

                previous = endAtThisShape;
466 467
            }
        }
468

BRAMAS Berenger's avatar
BRAMAS Berenger committed
469
        FLOG(computationCounter.tac());
470

471
        delete [] leafsDataArray;
472 473 474 475
        for(int idxShape = 0 ; idxShape < SizeShape ; ++idxShape){
            omp_destroy_lock(&lockShape[idxShape]);
        }

476

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

481 482 483 484 485 486
    }

};


#endif //FFMMALGORITHMTHREAD_HPP