testFmmAlgorithmProcPeriodic.cpp 10.9 KB
Newer Older
1
// ===================================================================================
2 3 4 5 6 7 8 9
// Logiciel initial: ScalFmm Version 0.5
// Co-auteurs : Olivier Coulaud, Bérenger Bramas.
// Propriétaires : INRIA.
// Copyright © 2011-2012, diffusé sous les termes et conditions d’une licence propriétaire.
// Initial software: ScalFmm Version 0.5
// Co-authors: Olivier Coulaud, Bérenger Bramas.
// Owners: INRIA.
// Copyright © 2011-2012, spread under the terms and conditions of a proprietary license.
10
// ===================================================================================
11

12 13 14
// ==== CMAKE =====
// @FUSE_MPI
// ================
15 16 17

#include <iostream>

18 19
#include <cstdio>
#include <cstdlib>
20

21 22
#include "../../Src/Utils/FParameters.hpp"
#include "../../Src/Utils/FTic.hpp"
23

24 25
#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Containers/FVector.hpp"
26

27
#include "../../Src/Components/FSimpleLeaf.hpp"
28
#include "../../Src/Files/FRandomLoader.hpp"
29

BRAMAS Berenger's avatar
BRAMAS Berenger committed
30
#include "../../Src/Utils/FPoint.hpp"
31

32 33 34
#include "../../Src/Components/FTestParticle.hpp"
#include "../../Src/Components/FTestCell.hpp"
#include "../../Src/Components/FTestKernels.hpp"
35

36
#include "../../Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp"
37
#include "../../Src/Core/FFmmAlgorithmPeriodic.hpp"
38

39
#include "../../Src/Files/FMpiTreeBuilder.hpp"
40

41
#include "../../Src/Components/FAbstractSendable.hpp"
42 43 44 45 46 47 48 49 50 51 52


/** This program show an example of use of
  * the fmm basic algo
  * it also check that each particles is impacted each other particles
  */


// Simply create particles and try the kernels
int main(int argc, char ** argv){
    typedef FTestParticle               ParticleClass;
berenger-bramas's avatar
berenger-bramas committed
53
    typedef FTestCell                   CellClass;
54 55 56 57
    typedef FVector<ParticleClass>      ContainerClass;

    typedef FSimpleLeaf<ParticleClass, ContainerClass >                     LeafClass;
    typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass >  OctreeClass;
58
    typedef FTestKernels<ParticleClass, CellClass, ContainerClass >         KernelClass;
59 60

    typedef FFmmAlgorithmThreadProcPeriodic<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass >     FmmClass;
61
    typedef FFmmAlgorithmPeriodic<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass >     FmmClassSeq;
62 63 64 65 66 67
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
    //////////////////////////////////////////////////////////////

    const int NbLevels          = FParameters::getValue(argc,argv,"-h", 7);
    const int SizeSubLevels     = FParameters::getValue(argc,argv,"-sh", 3);
68
    const long NbParticles      = FParameters::getValue(argc,argv,"-nb", 5);
69
    const int PeriodicDeep      = FParameters::getValue(argc,argv,"-per", 2);
70 71 72 73 74 75 76 77 78
    // choose in +x dir or -/+x dir or all dirs
    int PeriodicDirs          = (FParameters::existParameter(argc,argv,"-x")?DirMinusX:0) |
                                (FParameters::existParameter(argc,argv,"+x")?DirPlusX:0) |
                                (FParameters::existParameter(argc,argv,"-y")?DirMinusY:0) |
                                (FParameters::existParameter(argc,argv,"+y")?DirPlusY:0) |
                                (FParameters::existParameter(argc,argv,"-z")?DirMinusZ:0) |
                                (FParameters::existParameter(argc,argv,"+z")?DirPlusZ:0);
    if( PeriodicDirs == 0 ) PeriodicDirs =  AllDirs;
    if( FParameters::existParameter(argc,argv,"-nodir") ) PeriodicDirs = 0;
79 80 81 82 83 84 85 86

    FMpi app(argc, argv);

    FTic counter;

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

87
    std::cout << "Creating & Inserting " << NbParticles << " particles per boxes ..." << std::endl;
88 89 90
    std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
    counter.tic();

91
    FRandomLoader<ParticleClass> loader(NbParticles,FReal(1.0),FPoint(0,0,0), app.global().processId());
92 93
    OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());

94
    {
95 96 97 98
        FTestParticle*const particles = new FTestParticle[NbParticles];

        for(int idx = 0 ; idx < NbParticles ; ++idx){
            loader.fillParticle(particles[idx]);
99 100
        }

101 102
        FMpiTreeBuilder<ParticleClass>::ArrayToTree(app.global(), particles, NbParticles, loader.getCenterOfBox(),
                                                    loader.getBoxWidth(), tree);
103 104 105 106 107 108 109 110 111 112 113 114 115
        delete[] particles;
    }

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

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    std::cout << "Working on particles ..." << std::endl;
    counter.tic();

    KernelClass kernels;
116 117
    FmmClass algo( app.global(), &tree, PeriodicDeep, PeriodicDirs);
    algo.setKernel(&kernels);
118 119 120 121 122 123 124 125 126
    algo.execute();

    counter.tac();
    std::cout << "Done  " << "(@Algorithm = " << counter.elapsed() << "s)." << std::endl;

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    {
127 128 129 130 131
        const FTreeCoordinate repetitions = algo.repetitions();
        const int totalRepeatedBox = repetitions.getX() * repetitions.getY() * repetitions.getZ();
        std::cout << "The box is repeated " << repetitions.getX() <<" "<< repetitions.getY()<<" "<<
                     repetitions.getZ() << " there are " << totalRepeatedBox << " boxes in total\n";
        const long long NbParticlesEntireSystem = (NbParticles * app.global().processCount()) * totalRepeatedBox;
132
        std::cout << "The total number of particles is "  << NbParticlesEntireSystem << "\n";
133 134 135
        FTreeCoordinate min, max;
        algo.repetitionsIntervals(&min, &max);
        std::cout << "Min is " << min << " Max is " << max << std::endl;
136

137
        OctreeClass::Iterator octreeIterator(&tree);
138 139
        octreeIterator.gotoBottomLeft();
        do{
140
            ContainerClass::BasicIterator iter(*octreeIterator.getCurrentListTargets());
141 142

            while( iter.hasNotFinished() ){
143 144
                if( NbParticlesEntireSystem - 1 != iter.data().getDataDown()){
                    std::cout << "P2P probleme, should be " << NbParticlesEntireSystem - 1 <<
145 146 147 148 149 150 151 152 153 154 155
                                 " iter.data().getDataDown() "<< iter.data().getDataDown() << std::endl;
                }

                iter.gotoNext();
            }
        } while(octreeIterator.moveRight());
    }

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

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
    {
        OctreeClass treeSeq(NbLevels, SizeSubLevels, FReal(1.0), FPoint(0,0,0));
        for(int idx = 0 ; idx < app.global().processCount() ; ++idx ){
            FRandomLoader<ParticleClass> loaderSeq(NbParticles,FReal(1.0),FPoint(0,0,0), idx);
            loaderSeq.fillTree(treeSeq);
        }

        FmmClassSeq algoSeq( &treeSeq, PeriodicDeep, PeriodicDirs);
        algoSeq.setKernel(&kernels);
        algoSeq.execute();

        { // Ceck if there is number of NbPart summed at level 1
            typename OctreeClass::Iterator octreeIterator(&tree);
            octreeIterator.gotoBottomLeft();

            typename OctreeClass::Iterator octreeIteratorSeq(&treeSeq);
            octreeIteratorSeq.gotoBottomLeft();

            for(int idxLevel = tree.getHeight() - 1 ; idxLevel >= 1 ; --idxLevel ){
                std::cout << "Process level " << idxLevel << std::endl;

                while( octreeIterator.getCurrentGlobalIndex() != octreeIteratorSeq.getCurrentGlobalIndex() ){
                    octreeIteratorSeq.moveRight();
                }

                do{
                    if( octreeIterator.getCurrentGlobalIndex() != octreeIteratorSeq.getCurrentGlobalIndex()){
                        std::cout << "Index problem !!!!!" << std::endl;
                    }

                    if( algo.getWorkingInterval(idxLevel).min <= octreeIteratorSeq.getCurrentGlobalIndex()){
                        if( octreeIterator.getCurrentCell()->getDataUp() != octreeIteratorSeq.getCurrentCell()->getDataUp() ){
                            std::cout << "Up problem at " << octreeIterator.getCurrentGlobalIndex() <<
                                         " Good is " << octreeIteratorSeq.getCurrentCell()->getDataUp() <<
                                         " Bad is " << octreeIterator.getCurrentCell()->getDataUp() << std::endl;
                        }
                        if( octreeIterator.getCurrentCell()->getDataDown() != octreeIteratorSeq.getCurrentCell()->getDataDown() ){
                            std::cout << "Down problem at " << octreeIterator.getCurrentGlobalIndex() <<
                                         " Good is " << octreeIteratorSeq.getCurrentCell()->getDataDown() <<
                                         " Bad is " << octreeIterator.getCurrentCell()->getDataDown() << std::endl;
                        }
                    }
                } while(octreeIterator.moveRight() && octreeIteratorSeq.moveRight());

                octreeIterator.moveUp();
                octreeIterator.gotoLeft();

                octreeIteratorSeq.moveUp();
                octreeIteratorSeq.gotoLeft();
            }
        }
        { // Check that each particle has been summed with all other
            typename OctreeClass::Iterator octreeIterator(&tree);
            octreeIterator.gotoBottomLeft();

            typename OctreeClass::Iterator octreeIteratorSeq(&treeSeq);
            octreeIteratorSeq.gotoBottomLeft();


            while( octreeIterator.getCurrentGlobalIndex() != octreeIteratorSeq.getCurrentGlobalIndex() ){
                octreeIteratorSeq.moveRight();
            }

            do{
                typename ContainerClass::BasicIterator iter(*octreeIterator.getCurrentListTargets());
                typename ContainerClass::BasicIterator iterSeq(*octreeIteratorSeq.getCurrentListTargets());

                while( iter.hasNotFinished() ){
                    // If a particles has been impacted by less than NbPart - 1 (the current particle)
                    // there is a problem
                    if( iter.data().getDataDown() != iterSeq.data().getDataDown() ){
                        std::cout << "Problem L2P + P2P at " << octreeIterator.getCurrentGlobalIndex() <<
                                     " Good is " << iterSeq.data().getDataDown() <<
                                     " Bad is " << iter.data().getDataDown() << std::endl;
                    }

                    iter.gotoNext();
                    iterSeq.gotoNext();
                }
            } while(octreeIterator.moveRight());
        }
    }
    std::cout << "Test is over...\n";

240 241 242 243
    return 0;
}


244