testBlockedUniformCompare.cpp 46.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

// ==== CMAKE =====
// @FUSE_BLAS
// @FUSE_FFT
// ================
// Keep in private GIT


#include "../../Src/Utils/FGlobal.hpp"

#include "../../Src/GroupTree/Core/FGroupTree.hpp"

#include "../../Src/Components/FSimpleLeaf.hpp"
#include "../../Src/Containers/FVector.hpp"

#include "../../Src/Kernels/P2P/FP2PParticleContainer.hpp"

#include "Kernels/Interpolation/FInterpMatrixKernel.hpp"
#include "../../Src/Kernels/Uniform/FUnifKernel.hpp"

#include "../../Src/GroupTree/Uniform/FUnifCellPOD.hpp"

#include "../../Src/Utils/FMath.hpp"
#include "../../Src/Utils/FMemUtils.hpp"
#include "../../Src/Utils/FParameters.hpp"

#include "../../Src/Files/FRandomLoader.hpp"
#include "../../Src/Files/FFmaGenericLoader.hpp"

#include "../../Src/GroupTree/Core/FGroupSeqAlgorithm.hpp"
#include "../../Src/GroupTree/Core/FGroupTaskAlgorithm.hpp"
#ifdef SCALFMM_USE_OMP4
#include "../../Src/GroupTree/Core/FGroupTaskDepAlgorithm.hpp"
34
#include "Core/FFmmAlgorithmOmp4.hpp"
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#endif
#ifdef SCALFMM_USE_STARPU
#include "../../Src/GroupTree/Core/FGroupTaskStarpuAlgorithm.hpp"
#include "../../Src/GroupTree/StarPUUtils/FStarPUKernelCapacities.hpp"
#endif
#include "../../Src/GroupTree/Core/FP2PGroupParticleContainer.hpp"

#include "../../Src/Utils/FParameterNames.hpp"

#include <memory>

#include "Core/FFmmAlgorithm.hpp"
#include "Core/FFmmAlgorithmThread.hpp"
#include "Core/FFmmAlgorithmSectionTask.hpp"
#include "Core/FFmmAlgorithmTask.hpp"
#include "Core/FFmmAlgorithmThreadBalance.hpp"
#include "Components/FSimpleLeaf.hpp"

#include "Kernels/Uniform/FUnifCell.hpp"
#include "Kernels/Interpolation/FInterpMatrixKernel.hpp"
#include "Kernels/Uniform/FUnifKernel.hpp"

#include "Components/FSimpleLeaf.hpp"
#include "Kernels/P2P/FP2PParticleContainerIndexed.hpp"
59
#include "Utils/FBinding.hpp"
60
#include "Utils/FTemplate.hpp"
61

62 63 64 65 66
#ifdef MEMORY_USAGE
#include <sys/time.h>
#include <sys/resource.h>
#endif

67 68 69 70
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
#include <starpu.h>
#endif

71
#define RANDOM_PARTICLES
72

73 74 75 76
const FParameterNames LocalOrder { {"-order"}, "Order of the kernel"};
const FParameterNames LocalOptionOmpTask { {"-omp-task"}, "To use FFmmAlgorithmTask"};
const FParameterNames LocalOptionOmpSection { {"-omp-section"}, "To use FFmmAlgorithmSectionTask"};
const FParameterNames LocalOptionOmpBalance { {"-omp-balance"}, "To use FFmmAlgorithmThreadBalance"};
77 78 79
#ifdef SCALFMM_USE_OMP4
const FParameterNames LocalOptionOmp4 { {"-omp-taskdep"}, "To use FFmmAlgorithmOmp4"};
#endif
80
const FParameterNames LocalOptionClassic { {"-omp", "omp-classic"}, "In order to use classic parallelism"};
81 82
const FParameterNames LocalOptionBlocSize { {"-bs"}, "The size of the block of the blocked tree"};
const FParameterNames LocalOptionNoValidate { {"-no-validation"}, "To avoid comparing with direct computation"};
83
const FParameterNames LocalOptionFMMValidate { {"-fmm-validation"}, "To check with usual FMM"};
84
const FParameterNames LocalOptionProlate { {"-prolate"}, "To generate prolate distribution"};
85
const FParameterNames LocalOptionProlateNonUnif { {"-prolate-nonunif"}, "To generate prolate distribution"};
BRAMAS Berenger's avatar
BRAMAS Berenger committed
86
const FParameterNames LocalOptionNonUnif { {"-nonunif"}, "To generate non uniform"};
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360

#include <cstdlib>
#include <time.h>

/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FSphericalRandomLoader
* Please read the license
*/
template <class FReal>
class FSphericalRandomLoader : public FAbstractLoader<FReal> {
protected:
    const int nbParticles;            //< the number of particles
    const FReal boxWidth;             //< the box width
    const FPoint<FReal> centerOfBox;    //< The center of box
    const bool nu;
    const bool snu;
    const bool su;
    const bool elu;
    const bool ssnu;
    const bool elsu;


    FReal rotationMatrix[3][3];

    void initRotationMatrix(){
        const FReal alpha = FMath::FPi<FReal>()/8;
        const FReal omega = FMath::FPi<FReal>()/4;

        FReal yrotation[3][3];
        yrotation[0][0] = FMath::Cos(alpha); yrotation[0][1] = 0.0; yrotation[0][2] = FMath::Sin(alpha);
        yrotation[1][0] = 0.0;               yrotation[1][1] = 1.0; yrotation[1][2] = 0.0;
        yrotation[2][0] = -FMath::Sin(alpha); yrotation[2][1] = 0.0;   yrotation[2][2] = FMath::Cos(alpha);

        FReal zrotation[3][3];
        zrotation[0][0] = FMath::Cos(omega); zrotation[0][1] = -FMath::Sin(omega); zrotation[0][2] = 0.0;
        zrotation[1][0] = FMath::Sin(omega); zrotation[1][1] = FMath::Cos(omega); zrotation[1][2] = 0.0;
        zrotation[2][0] = 0.0; zrotation[2][1] = 0.0;   zrotation[2][2] = 1.0;

        for(int i = 0 ; i < 3 ; ++i){
            for(int j = 0 ; j < 3 ; ++j){
                FReal sum = 0.0;
                for(int k = 0 ; k < 3 ; ++k){
                    sum += zrotation[i][k] * yrotation[k][j];
                }
                rotationMatrix[i][j] = sum;
            }
        }
    }

public:
    /**
    * The constructor need the simulation data
    */
    FSphericalRandomLoader(const int inNbParticles, const bool inNu = false,
                           const bool inSnu = false,
                           const bool inSu = false,
                           const bool inElu = false,
                           const bool inSsnu = false,
                           const bool inElsu = false)
        : nbParticles(inNbParticles), boxWidth(1.0), centerOfBox(0,0,0), nu(inNu),
          snu(inSnu), su(inSu), elu(inElu), ssnu(inSsnu), elsu(inElsu) {
        srand48(static_cast<unsigned int>(0));
        if( !nu && !snu && !su && !elu && !ssnu && !elsu ){
            std::cout << "UNIFORM" << std::endl;
        }
        else if( snu ){
            std::cout << "slightly NON UNIFORM" << std::endl;
        }
        else if( su ){
            std::cout << "SPHERICAL UNIFORM" << std::endl;
        }
        else if( elu ){
            std::cout << "ELLIPSE UNIFORM" << std::endl;
        }
        else if( elsu ){
            std::cout << "ELLIPSE NON UNIFORM" << std::endl;
            initRotationMatrix();
        }
        else if( ssnu ){
            std::cout << "spherical Slightly non UNIFORM" << std::endl;
        }
        else{
            std::cout << "NON UNIFORM" << std::endl;
        }
    }

    /**
    * Default destructor
    */
    virtual ~FSphericalRandomLoader(){
    }

    /**
      * @return true
      */
    bool isOpen() const{
        return true;
    }

    /**
      * To get the number of particles from this loader
      * @param the number of particles the loader can fill
      */
    FSize getNumberOfParticles() const{
        return FSize(this->nbParticles);
    }

    /**
      * The center of the box
      * @return box center
      */
    FPoint<FReal> getCenterOfBox() const{
        return this->centerOfBox;
    }

    /**
      * The box width
      * @return box width
      */
    FReal getBoxWidth() const{
        return this->boxWidth;
    }

    /**
      * Fill a particle
      * @warning to work with the loader, particles has to expose a setPosition method
      * @param the particle to fill
      */
    void fillParticle(FPoint<FReal>* partPtr){
        FPoint<FReal>& inParticle = *partPtr;
        if( !nu && !snu && !su && !elu && !ssnu && !elsu ){
            inParticle.setPosition(
                        (getRandom() * boxWidth) + centerOfBox.getX() - boxWidth/2,
                        (getRandom() * boxWidth) + centerOfBox.getY() - boxWidth/2,
                        (getRandom() * boxWidth) + centerOfBox.getZ() - boxWidth/2);
        }
        else if( snu ){
            const FReal XCenter = centerOfBox.getX();
            const FReal YCenter = centerOfBox.getY();
            const FReal ZCenter = centerOfBox.getZ();

            const FReal rayon = FReal(0.4);
            const FReal thresh = FReal(0.15);
            const FReal threshDiv2 = thresh/2;

            // Generate particles
            const FReal theta = getRandom() * FMath::FPi<FReal>();
            const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2);

            const FReal px = rayon * FMath::Cos(omega) * FMath::Sin(theta) + XCenter + thresh * getRandom() - threshDiv2;
            const FReal py = rayon * FMath::Sin(omega) * FMath::Sin(theta) + YCenter + thresh * getRandom() - threshDiv2;
            const FReal pz = rayon * FMath::Cos(theta) + ZCenter + thresh * getRandom() - threshDiv2;

            inParticle.setPosition(px,py,pz);
        }
        else if( su ){
            //http://www.cs.cmu.edu/~mws/rpos.html
            const FReal r = 0.4;

            const FReal pz = getRandom()*2.0*r - r;
            const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2);

            const FReal theta = FMath::ASin(pz/r);

            const FReal px = r * cos(theta) * cos(omega);
            const FReal py = r * cos(theta) * sin(omega);

            inParticle.setPosition(px,py,pz);
        }
        else if( elu ){
            const FReal a = 0.4;
            const FReal b = 0.15;

            const FReal maxPerimeter = 2.0 * FMath::FPi<FReal>() * a;

            FReal px   = 0;
            // rayon du cercle pour ce x
            FReal subr = 0;

            do {
                px   = (getRandom() * a * 2) - a;
                subr = FMath::Sqrt( (1.0 - ((px*px)/(a*a))) * (b*b) );
            } while( (getRandom()*maxPerimeter) > subr );

            // on genere un angle
            const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2);
            // on recupere py et pz sur le cercle
            const FReal py = FMath::Cos(omega) * subr;
            const FReal pz = FMath::Sin(omega) * subr;

            inParticle.setPosition(px,py,pz);
        }
        else if( elsu ){
            const FReal a = 0.5;
            const FReal b = 0.1;

            const FReal MaxDensity = 10.0;
            const FReal maxPerimeter = 2.0 * FMath::FPi<FReal>() * a ;

            FReal px   = 0;
            // rayon du cercle pour ce x
            FReal subr = 0;
            FReal coef = 1.0;

            do {
                //px   = ( ((getRandom()*8.0+getRandom())/9.0) * a * 2) - a;
                px = (getRandom() * a * 2.0) - a;

                coef = FMath::Abs(px) * MaxDensity/a + 1.0;

                subr = FMath::Sqrt( (1.0 - ((px*px)/(a*a))) * (b*b) );

            } while( (getRandom()*maxPerimeter) > subr * coef );

            // on genere un angle
            const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2);
            // on recupere py et pz sur le cercle
            const FReal py = FMath::Cos(omega) * subr;
            const FReal pz = FMath::Sin(omega) * subr;

           // inParticle.setPosition(px,py,pz);
            inParticle.setPosition(px * rotationMatrix[0][0] + py * rotationMatrix[0][1]+ pz * rotationMatrix[0][2],
                                   px * rotationMatrix[1][0] + py * rotationMatrix[1][1]+ pz * rotationMatrix[1][2],
                                   px * rotationMatrix[2][0] + py * rotationMatrix[2][1]+ pz * rotationMatrix[2][2]);

        }
        else if( ssnu ){
            const FReal XCenter = centerOfBox.getX();
            const FReal YCenter = centerOfBox.getY();
            const FReal ZCenter = centerOfBox.getZ();

            const FReal rayon = FReal(0.4);

            // Generate particles
            /*static const int NbAcc = 2;
            FReal acc = 0;
            for(int idx = 0 ; idx < NbAcc ; ++idx){
                acc += getRandom()/FReal(NbAcc);
            }*/
            FReal acc = ((getRandom()*8)+getRandom())/9;

            const FReal theta = acc * FMath::FPi<FReal>();
            const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2);

            const FReal px = rayon * FMath::Cos(omega) * FMath::Sin(theta) + XCenter ;
            const FReal py = rayon * FMath::Sin(omega) * FMath::Sin(theta) + YCenter ;
            const FReal pz = rayon * FMath::Cos(theta) + ZCenter ;

            inParticle.setPosition(px,py,pz);
        }
        else{
            const FReal XCenter = centerOfBox.getX();
            const FReal YCenter = centerOfBox.getY();
            const FReal ZCenter = centerOfBox.getZ();

            const FReal rayon = FReal(0.4);

            const FReal theta = getRandom() * FMath::FPi<FReal>();
            const FReal omega = getRandom() * FMath::FPi<FReal>() * FReal(2);

            const FReal px = rayon * FMath::Cos(omega) * FMath::Sin(theta) + XCenter ;
            const FReal py = rayon * FMath::Sin(omega) * FMath::Sin(theta) + YCenter ;
            const FReal pz = rayon * FMath::Cos(theta) + ZCenter ;

            inParticle.setPosition(px,py,pz);
        }
    }

    /** Get a random number between 0 & 1 */
    FReal getRandom() const{
        return FReal(drand48());
    }
};
361 362 363 364 365 366 367 368 369 370

struct RunContainer{
    template <const int ORDER>
    static void Run(int argc, char* argv[]){
        std::cout << "Unif kernel ORDER " << ORDER << std::endl;
        // Initialize the types
        typedef double FReal;
        typedef FInterpMatrixKernelR<FReal> MatrixKernelClass;
        const MatrixKernelClass MatrixKernel;
        const int NbLevels      = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeHeight.options, 5);
371 372 373 374 375 376 377 378
        FVector<FSize> threadsList;
        if(FParameters::existParameter(argc,argv,FParameterDefinitions::NbThreads.options)){
            threadsList = FParameters::getListOfValues<FSize>(argc,argv,FParameterDefinitions::NbThreads.options);
            std::cout << "Ask for " << threadsList.getSize() << " threads config" << std::endl;
        }
        else{
            threadsList.push(omp_get_max_threads());
        }
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393

        if(FParameters::existParameter(argc, argv, LocalOptionClassic.options)){
            std::cout << "\n>> Using " << omp_get_max_threads() << " omp threads.\n" << std::endl;
            const unsigned int SubTreeHeight = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeSubHeight.options, 2);

            // init particles position and physical value
            struct TestParticle{
                FPoint<FReal> position;
                FReal forces[3];
                FReal physicalValue;
                FReal potential;
            };

            // open particle file
    #ifdef RANDOM_PARTICLES
394
            const bool prolate = FParameters::existParameter(argc,argv,LocalOptionProlate.options);
395
            const bool prolatenonunif = FParameters::existParameter(argc,argv,LocalOptionProlateNonUnif.options);
BRAMAS Berenger's avatar
BRAMAS Berenger committed
396
            const bool nonunif = FParameters::existParameter(argc,argv,LocalOptionNonUnif.options);
397
            FSphericalRandomLoader<FReal> loader(FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, 2000),
BRAMAS Berenger's avatar
BRAMAS Berenger committed
398
                                                 nonunif, false, false, prolate, false, prolatenonunif);
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
    #else
            const char* const filename = FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options, "../Data/test20k.fma");
            FFmaGenericLoader<FReal> loader(filename);
    #endif
            FAssertLF(loader.isOpen());

            TestParticle* const particles = new TestParticle[loader.getNumberOfParticles()];
            for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
                FPoint<FReal> position;
                FReal physicalValue = 0.0;
    #ifdef RANDOM_PARTICLES
                physicalValue = 0.10;
                loader.fillParticle(&position);
    #else
                loader.fillParticle(&position, &physicalValue);
    #endif
                // get copy
                particles[idxPart].position       = position;
                particles[idxPart].physicalValue  = physicalValue;
                particles[idxPart].potential      = 0.0;
                particles[idxPart].forces[0]      = 0.0;
                particles[idxPart].forces[1]      = 0.0;
                particles[idxPart].forces[2]      = 0.0;
422 423
            }

424
            ////////////////////////////////////////////////////////////////////
425

426
            FTic time;
427

428 429 430
            if(FParameters::existParameter(argc, argv, LocalOptionNoValidate.options) == false){
                // begin direct computation
                std::cout << "\nDirect computation ... " << std::endl;
431
                time.tic();
432 433
                {
                    for(FSize idxTarget = 0 ; idxTarget < loader.getNumberOfParticles() ; ++idxTarget){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
434 435 436 437 438 439
                        FReal fx = 0;
                        FReal fy = 0;
                        FReal fz = 0;
                        FReal potential = 0;

                        #pragma omp parallel for reduction(+:fx,fy,fz,potential)
440 441 442 443 444 445 446 447 448 449 450
                        for(FSize idxOther =  idxTarget + 1 ; idxOther < loader.getNumberOfParticles() ; ++idxOther){
                            FP2P::MutualParticles(particles[idxTarget].position.getX(), particles[idxTarget].position.getY(),
                                                  particles[idxTarget].position.getZ(), particles[idxTarget].physicalValue,
                                                  &particles[idxTarget].forces[0], &particles[idxTarget].forces[1],
                                    &particles[idxTarget].forces[2], &particles[idxTarget].potential,
                                    particles[idxOther].position.getX(), particles[idxOther].position.getY(),
                                    particles[idxOther].position.getZ(), particles[idxOther].physicalValue,
                                    &particles[idxOther].forces[0], &particles[idxOther].forces[1],
                                    &particles[idxOther].forces[2], &particles[idxOther].potential,
                                    &MatrixKernel);
                        }
BRAMAS Berenger's avatar
BRAMAS Berenger committed
451 452 453 454
                        particles[idxTarget].forces[0] += fx;
                        particles[idxTarget].forces[1] += fy;
                        particles[idxTarget].forces[2] += fz;
                        particles[idxTarget].potential += potential;
455 456
                    }
                }
457
                time.tac();
458 459
                std::cout << "Done  " << "(@Direct computation = "
                          << time.elapsed() << "s)." << std::endl;
460

461
            } // end direct computation
462

463 464 465 466 467 468
            // typedefs
            typedef FP2PParticleContainerIndexed<FReal> ContainerClass;
            typedef FSimpleLeaf<FReal, ContainerClass >  LeafClass;
            typedef FUnifCell<FReal,ORDER> CellClass;
            typedef FOctree<FReal, CellClass,ContainerClass,LeafClass> OctreeClass;
            typedef FUnifKernel<FReal,CellClass,ContainerClass,MatrixKernelClass,ORDER> KernelClass;
469

470 471
            // init oct-tree
            OctreeClass tree(NbLevels, SubTreeHeight, loader.getBoxWidth(), loader.getCenterOfBox());
472 473


474 475 476 477 478 479 480 481 482 483
            { // -----------------------------------------------------
                std::cout << "Creating & Inserting " << loader.getNumberOfParticles()
                          << " particles ..." << std::endl;
                std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SubTreeHeight << std::endl;
                time.tic();

                for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
                    // put in tree
                    tree.insert(particles[idxPart].position, idxPart, particles[idxPart].physicalValue);
                }
484

485 486 487 488 489 490
                time.tac();
                std::cout << "Done  " << "(@Creating and Inserting Particles = "
                          << time.elapsed() << "s)." << std::endl;
            } // -----------------------------------------------------


491
            for(FSize idxThread = 0 ; idxThread < threadsList.getSize() ; ++idxThread){
492

493 494
                omp_set_num_threads(int(threadsList[idxThread]));
                std::cout << "\n>> Using " << omp_get_max_threads() << " omp threads.\n" << std::endl;
495

496 497 498 499 500 501 502
                { // -----------------------------------------------------
                    std::cout << "\nLagrange/Uniform grid FMM (ORDER="<< ORDER << ") ... " << std::endl;
                    KernelClass kernels(NbLevels, loader.getBoxWidth(), loader.getCenterOfBox(),&MatrixKernel);
                    if(FParameters::existParameter(argc, argv, LocalOptionOmpBalance.options)){
                        typedef FFmmAlgorithmThreadBalance<OctreeClass,CellClass,ContainerClass,KernelClass,LeafClass> FmmClass;
                        std::cout << "Using FFmmAlgorithmThreadBalance " << std::endl;
                        FmmClass algorithm(&tree, &kernels);
503 504 505 506 507
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        // The taskname() clause is only supported by KSTAR. Make sure
                        // to set it from CMake to enable tracing.
                        starpu_fxt_start_profiling();
#endif
508 509 510
                        time.tic();
                        algorithm.execute();
                        time.tac();
511 512
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        starpu_fxt_stop_profiling();
513
#endif
514 515 516 517 518 519
                        std::cout << "Done  " << "(@Algorithm = " << time.elapsed() << "s)." << std::endl;
                    }
                    else if(FParameters::existParameter(argc, argv, LocalOptionOmpTask.options)){
                        typedef FFmmAlgorithmTask<OctreeClass,CellClass,ContainerClass,KernelClass,LeafClass> FmmClass;
                        std::cout << "Using FFmmAlgorithmTask " << std::endl;
                        FmmClass algorithm(&tree, &kernels);
520 521 522 523 524
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        // The taskname() clause is only supported by KSTAR. Make sure
                        // to set it from CMake to enable tracing.
                        starpu_fxt_start_profiling();
#endif
525 526 527
                        time.tic();
                        algorithm.execute();
                        time.tac();
528 529 530
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        starpu_fxt_stop_profiling();
#endif
531 532 533 534 535 536
                        std::cout << "Done  " << "(@Algorithm = " << time.elapsed() << "s)." << std::endl;
                    }
                    else if(FParameters::existParameter(argc, argv, LocalOptionOmpSection.options)){
                        typedef FFmmAlgorithmSectionTask<OctreeClass,CellClass,ContainerClass,KernelClass,LeafClass> FmmClass;
                        std::cout << "Using FFmmAlgorithmSectionTask " << std::endl;
                        FmmClass algorithm(&tree, &kernels);
537 538 539 540 541
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        // The taskname() clause is only supported by KSTAR. Make sure
                        // to set it from CMake to enable tracing.
                        starpu_fxt_start_profiling();
#endif
542 543 544
                        time.tic();
                        algorithm.execute();
                        time.tac();
545 546 547
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        starpu_fxt_stop_profiling();
#endif
548 549 550 551 552 553 554
                        std::cout << "Done  " << "(@Algorithm = " << time.elapsed() << "s)." << std::endl;
                    }
    #ifdef SCALFMM_USE_OMP4
                    else if(FParameters::existParameter(argc, argv, LocalOptionOmp4.options)){
                        typedef FFmmAlgorithmOmp4<OctreeClass,CellClass,ContainerClass,KernelClass,LeafClass> FmmClass;
                        std::cout << "Using FFmmAlgorithmOmp4 " << std::endl;
                        FmmClass algorithm(&tree, &kernels);
555 556 557 558 559
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        // The taskname() clause is only supported by KSTAR. Make sure
                        // to set it from CMake to enable tracing.
                        starpu_fxt_start_profiling();
#endif
560 561 562
                        time.tic();
                        algorithm.execute();
                        time.tac();
563 564 565
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        starpu_fxt_stop_profiling();
#endif
566 567 568 569 570 571 572
                        std::cout << "Done  " << "(@Algorithm = " << time.elapsed() << "s)." << std::endl;
                    }
    #endif
                    else {
                        typedef FFmmAlgorithmThread<OctreeClass,CellClass,ContainerClass,KernelClass,LeafClass> FmmClass;
                        std::cout << "Using FFmmAlgorithmThread " << std::endl;
                        FmmClass algorithm(&tree, &kernels);
573 574 575 576 577
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        // The taskname() clause is only supported by KSTAR. Make sure
                        // to set it from CMake to enable tracing.
                        starpu_fxt_start_profiling();
#endif
578 579 580
                        time.tic();
                        algorithm.execute();
                        time.tac();
581 582 583
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                        starpu_fxt_stop_profiling();
#endif
584 585 586 587
                        std::cout << "Done  " << "(@Algorithm = " << time.elapsed() << "s)." << std::endl;
                    }
                } // -----------------------------------------------------

588 589 590 591 592 593
    #ifdef MEMORY_USAGE
                // Get the maximum resident set size (RSS) in kilobytes
                struct rusage usage;
                getrusage(RUSAGE_SELF, &usage);
                std::cout << "Done  " << "(@RSS = " << usage.ru_maxrss << "KB)." << std::endl;
    #endif
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
                if(FParameters::existParameter(argc, argv, LocalOptionNoValidate.options) == false){
                    // -----------------------------------------------------
                    FMath::FAccurater<FReal> potentialDiff;
                    FMath::FAccurater<FReal> fx, fy, fz;

                    { // Check that each particle has been summed with all other

                        tree.forEachLeaf([&](LeafClass* leaf){
                            const FReal*const potentials = leaf->getTargets()->getPotentials();
                            const FReal*const forcesX = leaf->getTargets()->getForcesX();
                            const FReal*const forcesY = leaf->getTargets()->getForcesY();
                            const FReal*const forcesZ = leaf->getTargets()->getForcesZ();
                            const FSize nbParticlesInLeaf = leaf->getTargets()->getNbParticles();
                            const FVector<FSize>& indexes = leaf->getTargets()->getIndexes();

                            for(FSize idxPart = 0 ; idxPart < nbParticlesInLeaf ; ++idxPart){
                                const FSize indexPartOrig = indexes[idxPart];

                                potentialDiff.add(particles[indexPartOrig].potential,potentials[idxPart]);
                                fx.add(particles[indexPartOrig].forces[0],forcesX[idxPart]);
                                fy.add(particles[indexPartOrig].forces[1],forcesY[idxPart]);
                                fz.add(particles[indexPartOrig].forces[2],forcesZ[idxPart]);
                            }
                        });
                    }

                    // Print for information
                    std::cout << "Potential " << potentialDiff << std::endl;
                    std::cout << "Fx " << fx << std::endl;
                    std::cout << "Fy " << fy << std::endl;
                    std::cout << "Fz " << fz << std::endl;
                } // -----------------------------------------------------

                tree.forEachCell([&](CellClass* cell){
                    cell->resetToInitialState();
                });
                tree.forEachLeaf([&](LeafClass* leaf){
                    leaf->getTargets()->resetForcesAndPotential();
                });
            }
634 635 636 637 638 639 640 641 642 643 644 645 646
        }
        else{
            typedef FUnifCellPODCore         GroupCellSymbClass;
            typedef FUnifCellPODPole<FReal,ORDER>  GroupCellUpClass;
            typedef FUnifCellPODLocal<FReal,ORDER> GroupCellDownClass;
            typedef FUnifCellPOD<FReal,ORDER>      GroupCellClass;

            typedef FP2PGroupParticleContainer<FReal>          GroupContainerClass;
            typedef FGroupTree< FReal, GroupCellClass, GroupCellSymbClass, GroupCellUpClass, GroupCellDownClass, GroupContainerClass, 1, 4, FReal>  GroupOctreeClass;
    #ifdef SCALFMM_USE_STARPU
            typedef FStarPUAllCpuCapacities<FUnifKernel<FReal,GroupCellClass,GroupContainerClass,MatrixKernelClass,ORDER>> GroupKernelClass;
            typedef FStarPUCpuWrapper<typename GroupOctreeClass::CellGroupClass, GroupCellClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupContainerClass> GroupCpuWrapper;
            typedef FGroupTaskStarPUAlgorithm<GroupOctreeClass, typename GroupOctreeClass::CellGroupClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupCpuWrapper > GroupAlgorithm;
647
            std::cout << "Using FGroupTaskStarPUAlgorithm" << std::endl;
648 649 650 651 652
    #elif defined(SCALFMM_USE_OMP4)
            typedef FUnifKernel<FReal,GroupCellClass,GroupContainerClass,MatrixKernelClass,ORDER> GroupKernelClass;
            // Set the number of threads
            typedef FGroupTaskDepAlgorithm<GroupOctreeClass, typename GroupOctreeClass::CellGroupClass, GroupCellClass,
                    GroupCellSymbClass, GroupCellUpClass, GroupCellDownClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupContainerClass > GroupAlgorithm;
653
            std::cout << "Using FGroupTaskDepAlgorithm" << std::endl;
654 655 656 657
    #else
            typedef FUnifKernel<FReal,GroupCellClass,GroupContainerClass,MatrixKernelClass,ORDER> GroupKernelClass;
            //typedef FGroupSeqAlgorithm<GroupOctreeClass, typename GroupOctreeClass::CellGroupClass, GroupCellClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupContainerClass > GroupAlgorithm;
            typedef FGroupTaskAlgorithm<GroupOctreeClass, typename GroupOctreeClass::CellGroupClass, GroupCellClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupContainerClass > GroupAlgorithm;
658
            std::cout << "Using FGroupTaskAlgorithm" << std::endl;
659 660 661 662 663 664
    #endif
            // Get params
            const int groupSize     = FParameters::getValue(argc,argv,LocalOptionBlocSize.options, 250);

            // Load the particles
    #ifdef RANDOM_PARTICLES
665
            const bool prolate = FParameters::existParameter(argc,argv,LocalOptionProlate.options);
666
            const bool prolatenonunif = FParameters::existParameter(argc,argv,LocalOptionProlateNonUnif.options);
BRAMAS Berenger's avatar
BRAMAS Berenger committed
667
            const bool nonunif = FParameters::existParameter(argc,argv,LocalOptionNonUnif.options);
668
            FSphericalRandomLoader<FReal> loader(FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, 2000),
BRAMAS Berenger's avatar
BRAMAS Berenger committed
669
                                                 nonunif, false, false, prolate, false, prolatenonunif);
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
    #else
            const char* const filename = FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options, "../Data/test20k.fma");
            FFmaGenericLoader<FReal> loader(filename);
    #endif
            FAssertLF(loader.isOpen());
            FTic timer;

            FP2PParticleContainer<FReal> allParticles;
            for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
                FPoint<FReal> particlePosition;
                FReal physicalValue;
    #ifdef RANDOM_PARTICLES
                physicalValue = 0.10;
                loader.fillParticle(&particlePosition);
    #else
                loader.fillParticle(&particlePosition, &physicalValue);
    #endif
                allParticles.push(particlePosition, physicalValue);
            }

            // Put the data into the tree
            timer.tic();
            GroupOctreeClass groupedTree(NbLevels, loader.getBoxWidth(), loader.getCenterOfBox(), groupSize, &allParticles);
            groupedTree.printInfoBlocks();
            std::cout << "Tree created in " << timer.tacAndElapsed() << "s\n";



698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
            for(FSize idxThread = 0 ; idxThread < threadsList.getSize() ; ++idxThread){
#ifdef SCALFMM_USE_STARPU
                char buff[128];
                snprintf(buff, 128, "%lld", threadsList[idxThread]);
                setenv("STARPU_NCPUS", buff, 1);
#else
                omp_set_num_threads(int(threadsList[idxThread]));
                std::cout << "\n>> Using " << omp_get_max_threads() << " omp threads.\n" << std::endl;
#endif
                // Run the algorithm
                GroupKernelClass groupkernel(NbLevels, loader.getBoxWidth(), loader.getCenterOfBox(), &MatrixKernel);
                GroupAlgorithm groupalgo(&groupedTree,&groupkernel);

                std::cout << "I am bind to " << (FBinding::GetThreadBinding()) << std::endl;
                FBinding::BindThreadToAnyProcs();
                std::cout << "And now I am bind to " << (FBinding::GetThreadBinding()) << std::endl;

715 716 717
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                // The taskname() clause is only supported by KSTAR. Make sure
                // to set it from CMake to enable tracing.
718 719
                starpu_fxt_start_profiling();
#endif
720 721
                timer.tic();
                groupalgo.execute();
722
                timer.tac();
723
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
724 725 726
                starpu_fxt_stop_profiling();
#endif
                std::cout << "Done  " << "(@Algorithm = " << timer.elapsed() << "s)." << std::endl;
727
           }
728 729 730 731
    #ifdef MEMORY_USAGE
            // Get the maximum resident set size (RSS) in kilobytes
            struct rusage usage;
            getrusage(RUSAGE_SELF, &usage);
732
            std::cout << "Done  " << "(@RSS = " << usage.ru_maxrss << "KB)." << std::endl;
733 734
    #endif

735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
            // Validate the result
            if(FParameters::existParameter(argc, argv, LocalOptionNoValidate.options) == false){
                FSize offsetParticles = 0;
                FReal*const allPhysicalValues = allParticles.getPhysicalValues();
                FReal*const allPosX = const_cast<FReal*>( allParticles.getPositions()[0]);
                FReal*const allPosY = const_cast<FReal*>( allParticles.getPositions()[1]);
                FReal*const allPosZ = const_cast<FReal*>( allParticles.getPositions()[2]);

                groupedTree.template forEachCellLeaf<FP2PGroupParticleContainer<FReal> >([&](GroupCellClass cellTarget, FP2PGroupParticleContainer<FReal> * leafTarget){
                    const FReal*const physicalValues = leafTarget->getPhysicalValues();
                    const FReal*const posX = leafTarget->getPositions()[0];
                    const FReal*const posY = leafTarget->getPositions()[1];
                    const FReal*const posZ = leafTarget->getPositions()[2];
                    const FSize nbPartsInLeafTarget = leafTarget->getNbParticles();

                    for(FSize idxPart = 0 ; idxPart < nbPartsInLeafTarget ; ++idxPart){
                        allPhysicalValues[offsetParticles + idxPart] = physicalValues[idxPart];
                        allPosX[offsetParticles + idxPart] = posX[idxPart];
                        allPosY[offsetParticles + idxPart] = posY[idxPart];
                        allPosZ[offsetParticles + idxPart] = posZ[idxPart];
755
                    }
756 757

                    offsetParticles += nbPartsInLeafTarget;
758 759
                });

760 761 762 763 764 765 766 767
                FAssertLF(offsetParticles == loader.getNumberOfParticles());

                FReal*const allDirectPotentials = allParticles.getPotentials();
                FReal*const allDirectforcesX = allParticles.getForcesX();
                FReal*const allDirectforcesY = allParticles.getForcesY();
                FReal*const allDirectforcesZ = allParticles.getForcesZ();

                for(int idxTgt = 0 ; idxTgt < offsetParticles ; ++idxTgt){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
768 769 770 771 772 773
                    FReal fx = 0;
                    FReal fy = 0;
                    FReal fz = 0;
                    FReal potential = 0;

                    #pragma omp parallel for reduction(+:fx,fy,fz,potential)
774 775 776
                    for(int idxMutual = idxTgt + 1 ; idxMutual < offsetParticles ; ++idxMutual){
                        FP2PR::MutualParticles(
                                    allPosX[idxTgt],allPosY[idxTgt],allPosZ[idxTgt], allPhysicalValues[idxTgt],
BRAMAS Berenger's avatar
BRAMAS Berenger committed
777
                                    &fx, &fy, &fz, &potential,
778 779 780 781
                                    allPosX[idxMutual],allPosY[idxMutual],allPosZ[idxMutual], allPhysicalValues[idxMutual],
                                    &allDirectforcesX[idxMutual], &allDirectforcesY[idxMutual], &allDirectforcesZ[idxMutual], &allDirectPotentials[idxMutual]
                                    );
                    }
BRAMAS Berenger's avatar
BRAMAS Berenger committed
782 783 784 785 786

                    allDirectforcesX[idxTgt] += fx;
                    allDirectforcesY[idxTgt] += fy;
                    allDirectforcesZ[idxTgt] += fz;
                    allDirectPotentials[idxTgt] += potential;
787 788
                }

789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
                FMath::FAccurater<FReal> potentialDiff;
                FMath::FAccurater<FReal> fx, fy, fz;
                offsetParticles = 0;
                groupedTree.template forEachCellLeaf<FP2PGroupParticleContainer<FReal> >([&](GroupCellClass cellTarget, FP2PGroupParticleContainer<FReal> * leafTarget){
                    const FReal*const potentials = leafTarget->getPotentials();
                    const FReal*const forcesX = leafTarget->getForcesX();
                    const FReal*const forcesY = leafTarget->getForcesY();
                    const FReal*const forcesZ = leafTarget->getForcesZ();
                    const FSize nbPartsInLeafTarget = leafTarget->getNbParticles();

                    for(int idxTgt = 0 ; idxTgt < nbPartsInLeafTarget ; ++idxTgt){
                        potentialDiff.add(allDirectPotentials[idxTgt + offsetParticles], potentials[idxTgt]);
                        fx.add(allDirectforcesX[idxTgt + offsetParticles], forcesX[idxTgt]);
                        fy.add(allDirectforcesY[idxTgt + offsetParticles], forcesY[idxTgt]);
                        fz.add(allDirectforcesZ[idxTgt + offsetParticles], forcesZ[idxTgt]);
                    }
805

806 807
                    offsetParticles += nbPartsInLeafTarget;
                });
808

809 810 811 812
                std::cout << "Error : Potential " << potentialDiff << "\n";
                std::cout << "Error : fx " << fx << "\n";
                std::cout << "Error : fy " << fy << "\n";
                std::cout << "Error : fz " << fz << "\n";
813
            }
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
            if(FParameters::existParameter(argc, argv, LocalOptionFMMValidate.options) == true){
                {
                    FSize offsetParticles = 0;
                    FReal*const allPhysicalValues = allParticles.getPhysicalValues();
                    FReal*const allPosX = const_cast<FReal*>( allParticles.getPositions()[0]);
                    FReal*const allPosY = const_cast<FReal*>( allParticles.getPositions()[1]);
                    FReal*const allPosZ = const_cast<FReal*>( allParticles.getPositions()[2]);

                    FReal*const allDirectPotentials = allParticles.getPotentials();
                    FReal*const allDirectforcesX = allParticles.getForcesX();
                    FReal*const allDirectforcesY = allParticles.getForcesY();
                    FReal*const allDirectforcesZ = allParticles.getForcesZ();

                    groupedTree.template forEachCellLeaf<FP2PGroupParticleContainer<FReal> >([&](GroupCellClass cellTarget, FP2PGroupParticleContainer<FReal> * leafTarget){
                        const FReal*const physicalValues = leafTarget->getPhysicalValues();
                        const FReal*const posX = leafTarget->getPositions()[0];
                        const FReal*const posY = leafTarget->getPositions()[1];
                        const FReal*const posZ = leafTarget->getPositions()[2];

                        const FReal*const pot = leafTarget->getPotentials();
                        const FReal*const fx = leafTarget->getForcesX();
                        const FReal*const fy = leafTarget->getForcesY();
                        const FReal*const fz = leafTarget->getForcesZ();

                        const FSize nbPartsInLeafTarget = leafTarget->getNbParticles();

                        for(FSize idxPart = 0 ; idxPart < nbPartsInLeafTarget ; ++idxPart){
                            allPhysicalValues[offsetParticles + idxPart] = physicalValues[idxPart];
                            allPosX[offsetParticles + idxPart] = posX[idxPart];
                            allPosY[offsetParticles + idxPart] = posY[idxPart];
                            allPosZ[offsetParticles + idxPart] = posZ[idxPart];
                            allDirectPotentials[offsetParticles + idxPart] = pot[idxPart];
                            allDirectforcesX[offsetParticles + idxPart] = fx[idxPart];
                            allDirectforcesY[offsetParticles + idxPart] = fy[idxPart];
                            allDirectforcesZ[offsetParticles + idxPart] = fz[idxPart];
                        }

                        offsetParticles += nbPartsInLeafTarget;
                    });

                    FAssertLF(offsetParticles == loader.getNumberOfParticles());
                }

                // typedefs
                typedef FP2PParticleContainerIndexed<FReal> ContainerClass;
                typedef FSimpleLeaf<FReal, ContainerClass >  LeafClass;
                typedef FUnifCell<FReal,ORDER> CellClass;
                typedef FOctree<FReal, CellClass,ContainerClass,LeafClass> OctreeClass;
                typedef FUnifKernel<FReal,CellClass,ContainerClass,MatrixKernelClass,ORDER> KernelClass;

                // init oct-tree
                const unsigned int SubTreeHeight = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeSubHeight.options, 2);
                OctreeClass tree(NbLevels, SubTreeHeight, loader.getBoxWidth(), loader.getCenterOfBox());

                FTic time;
                { // -----------------------------------------------------
                    std::cout << "Creating & Inserting " << loader.getNumberOfParticles()
                              << " particles ..." << std::endl;
                    std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SubTreeHeight << std::endl;
                    time.tic();

                    FReal*const allPhysicalValues = allParticles.getPhysicalValues();
                    FReal*const allPosX = const_cast<FReal*>( allParticles.getPositions()[0]);
                    FReal*const allPosY = const_cast<FReal*>( allParticles.getPositions()[1]);
                    FReal*const allPosZ = const_cast<FReal*>( allParticles.getPositions()[2]);

                    for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
                        // put in tree
                        tree.insert(FPoint<FReal>(allPosX[idxPart], allPosY[idxPart], allPosZ[idxPart]), idxPart, allPhysicalValues[idxPart]);
                    }

                    time.tac();
                    std::cout << "Done  " << "(@Creating and Inserting Particles = "
                              << time.elapsed() << "s)." << std::endl;
                } // -----------------------------------------------------

                {
                    KernelClass kernels(NbLevels, loader.getBoxWidth(), loader.getCenterOfBox(),&MatrixKernel);
                    typedef FFmmAlgorithmThread<OctreeClass,CellClass,ContainerClass,KernelClass,LeafClass> FmmClass;
                    std::cout << "Using FFmmAlgorithmThread " << std::endl;
                    FmmClass algorithm(&tree, &kernels);
895 896 897 898 899
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                    // The taskname() clause is only supported by KSTAR. Make sure
                    // to set it from CMake to enable tracing.
                    starpu_fxt_start_profiling();
#endif
900 901 902
                    time.tic();
                    algorithm.execute();
                    time.tac();
903 904 905
#if defined(SCALFMM_USE_STARPU) || defined(OPENMP_SUPPORT_TASK_NAME)
                    starpu_fxt_stop_profiling();
#endif
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
                    std::cout << "Done  " << "(@Algorithm = " << time.elapsed() << "s)." << std::endl;
                }

                {
                    FReal*const allDirectPotentials = allParticles.getPotentials();
                    FReal*const allDirectforcesX = allParticles.getForcesX();
                    FReal*const allDirectforcesY = allParticles.getForcesY();
                    FReal*const allDirectforcesZ = allParticles.getForcesZ();

                    FMath::FAccurater<FReal> potentialDiff;
                    FMath::FAccurater<FReal> fx, fy, fz;
                    FSize offsetParticles = 0;
                    tree.forEachCellLeaf([&](CellClass* cellTarget, LeafClass* leaf){
                        ContainerClass * leafTarget = leaf->getTargets();
                        const FReal*const potentials = leafTarget->getPotentials();
                        const FReal*const forcesX = leafTarget->getForcesX();
                        const FReal*const forcesY = leafTarget->getForcesY();
                        const FReal*const forcesZ = leafTarget->getForcesZ();
                        const FSize nbPartsInLeafTarget = leafTarget->getNbParticles();

                        for(int idxTgt = 0 ; idxTgt < nbPartsInLeafTarget ; ++idxTgt){
                            potentialDiff.add(allDirectPotentials[idxTgt + offsetParticles], potentials[idxTgt]);
                            fx.add(allDirectforcesX[idxTgt + offsetParticles], forcesX[idxTgt]);
                            fy.add(allDirectforcesY[idxTgt + offsetParticles], forcesY[idxTgt]);
                            fz.add(allDirectforcesZ[idxTgt + offsetParticles], forcesZ[idxTgt]);
                        }

                        offsetParticles += nbPartsInLeafTarget;
                    });

                    std::cout << "Error : Potential " << potentialDiff << "\n";
                    std::cout << "Error : fx " << fx << "\n";
                    std::cout << "Error : fy " << fy << "\n";
                    std::cout << "Error : fz " << fz << "\n";
                }
            }
942
        }
943

944 945
    }
};
946 947


948 949 950 951
int main(int argc, char* argv[]){
    FHelpDescribeAndExit(argc, argv, "Test the blocked tree by counting the particles.",
                         FParameterDefinitions::OctreeHeight, FParameterDefinitions::OctreeSubHeight,
                     #ifdef RANDOM_PARTICLES
BRAMAS Berenger's avatar
BRAMAS Berenger committed
952
                         FParameterDefinitions::NbParticles, LocalOptionProlate,LocalOptionProlateNonUnif,LocalOptionNonUnif,
953 954 955 956 957 958
                     #else
                         FParameterDefinitions::InputFile,
                     #endif
                         FParameterDefinitions::NbThreads,
                         LocalOptionBlocSize, LocalOptionNoValidate, LocalOptionClassic,
                         LocalOptionOmpTask, LocalOptionOmpSection, LocalOptionOmpBalance,
959
                         LocalOrder, LocalOptionFMMValidate
960 961 962 963
#ifdef SCALFMM_USE_OMP4
                         , LocalOptionOmp4
#endif
                         );
964 965

    const int order = FParameters::getValue(argc,argv,LocalOrder.options, 5);
966
    FRunIf::Run<int, 3, 8, 1, RunContainer>(order, argc, argv);
967 968 969

    return 0;
}
970 971 972 973 974