testMemStats.cpp 5 KB
Newer Older
1
// See LICENCE file at project root
2 3 4

#include <iostream>

5 6
#include <cstdio>
#include <cstdlib>
7

8 9
#include "Utils/FParameters.hpp"
#include "Utils/FTic.hpp"
10

11 12
#include "Containers/FOctree.hpp"
#include "Containers/FVector.hpp"
13

14
#include "Components/FSimpleLeaf.hpp"
15

16
#include "Utils/FPoint.hpp"
17

18 19
#include "Components/FTestCell.hpp"
#include "Components/FTestKernels.hpp"
20

21 22 23
#include "Kernels/Spherical/FSphericalKernel.hpp"
#include "Kernels/Spherical/FSphericalCell.hpp"
#include "Components/FSimpleLeaf.hpp"
24

25
#include "Core/FFmmAlgorithm.hpp"
26

27
#include "Kernels/P2P/FP2PParticleContainer.hpp"
28

29
#include "Utils/FParameterNames.hpp"
30

31 32 33 34 35 36 37
/** 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){
38
    {
39 40 41 42
        FHelpDescribeAndExit(argc, argv, "Show the memory usage (if mem stats is turned on at the compilation)",
                             FParameterDefinitions::OctreeHeight, FParameterDefinitions::OctreeSubHeight,
                             FParameterDefinitions::NbParticles, FParameterDefinitions::SHDevelopment);

43
        typedef double FReal;
44
        typedef FSphericalCell<FReal>                 CellClass;
45

46
        typedef FP2PParticleContainer<FReal>      ContainerClass;
47

48 49
        typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
        typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
50
        //typedef FTestKernels< CellClass, ContainerClass >         KernelClass;
51
        typedef FSphericalKernel<FReal, CellClass, ContainerClass >          KernelClass;
52

53
        typedef FFmmAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass >     FmmClass;
54 55 56
        ///////////////////////What we do/////////////////////////////
        std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
        //////////////////////////////////////////////////////////////
57

58 59
        const int NbLevels      = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeHeight.options, 5);
        const int SizeSubLevels = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeSubHeight.options, 3);
60
        const FSize NbPart       = FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, FSize(2000000));
61
        const int DevP         = FParameters::getValue(argc,argv,FParameterDefinitions::SHDevelopment.options, 5);
62
        const FPoint<FReal> centerOfBox = FPoint<FReal>(0.5,0.5,0.5);
63
        FTic counter;
64

BRAMAS Berenger's avatar
BRAMAS Berenger committed
65
        srand48 ( 1 ); // volontary set seed to constant
66

67 68
        //////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////
69

berenger-bramas's avatar
berenger-bramas committed
70
        CellClass::Init(DevP);
71
        const FReal boxWidth = 1.0;
72
        OctreeClass tree(NbLevels, SizeSubLevels, boxWidth, centerOfBox);
73

74 75
        //////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////
76

77 78 79
        std::cout << "Creating & Inserting " << NbPart << " particles ..." << std::endl;
        std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
        counter.tic();
80

81
        {
82
            FPoint<FReal> particlePosition;
83
            FReal physicalValue = 0.10;
84
            for(FSize idxPart = 0 ; idxPart < NbPart ; ++idxPart){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
85
                particlePosition.setPosition(FReal(drand48()),FReal(drand48()),FReal(drand48()));
86
                tree.insert(particlePosition, physicalValue);
87
            }
88 89
        }

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

93 94
        //////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////
95

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

99
        // FTestKernels FBasicKernels
100
        //KernelClass kernels;
101
        KernelClass kernels(DevP, NbLevels,boxWidth, centerOfBox);
102 103
        FmmClass algo(&tree,&kernels);
        algo.execute();
104

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

108 109 110
        //////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////
    }
111

112 113 114
    std::cout << "Memory used at the end " << FMemStats::controler.getCurrentAllocated() << " Bytes (" << FMemStats::controler.getCurrentAllocatedMB() << "MB)\n";
    std::cout << "Max memory used " << FMemStats::controler.getMaxAllocated() << " Bytes (" << FMemStats::controler.getMaxAllocatedMB() << "MB)\n";
    std::cout << "Total memory used " << FMemStats::controler.getTotalAllocated() << " Bytes (" << FMemStats::controler.getTotalAllocatedMB() << "MB)\n";
115 116 117 118 119

    return 0;
}


120