testMemStats.cpp 6.11 KB
Newer Older
1
// ===================================================================================
2 3 4 5
// Copyright ScalFmm 2016 INRIA, Olivier Coulaud, Bérenger Bramas,
// Matthias Messner olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the
// FMM.
6
//
7
// This software is governed by the CeCILL-C and LGPL licenses and
8
// abiding by the rules of distribution of free software.
9 10 11
// An extension to the license is given to allow static linking of scalfmm
// inside a proprietary application (no matter its license).
// See the main license file for more details.
12
//
13 14 15
// 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
16 17 18
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
19
// ===================================================================================
20 21 22

#include <iostream>

23 24
#include <cstdio>
#include <cstdlib>
25

26 27
#include "../../Src/Utils/FParameters.hpp"
#include "../../Src/Utils/FTic.hpp"
28

29 30
#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Containers/FVector.hpp"
31

32
#include "../../Src/Components/FSimpleLeaf.hpp"
33

34
#include "../../Src/Utils/FPoint.hpp"
35

36 37
#include "../../Src/Components/FTestCell.hpp"
#include "../../Src/Components/FTestKernels.hpp"
38

39 40 41
#include "../../Src/Kernels/Spherical/FSphericalKernel.hpp"
#include "../../Src/Kernels/Spherical/FSphericalCell.hpp"
#include "../../Src/Components/FSimpleLeaf.hpp"
42

43
#include "../../Src/Core/FFmmAlgorithm.hpp"
44

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

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

49 50 51 52 53 54 55
/** 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){
56
    {
57 58 59 60
        FHelpDescribeAndExit(argc, argv, "Show the memory usage (if mem stats is turned on at the compilation)",
                             FParameterDefinitions::OctreeHeight, FParameterDefinitions::OctreeSubHeight,
                             FParameterDefinitions::NbParticles, FParameterDefinitions::SHDevelopment);

61
        typedef double FReal;
62
        typedef FSphericalCell<FReal>                 CellClass;
63

64
        typedef FP2PParticleContainer<FReal>      ContainerClass;
65

66 67
        typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
        typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
68
        //typedef FTestKernels< CellClass, ContainerClass >         KernelClass;
69
        typedef FSphericalKernel<FReal, CellClass, ContainerClass >          KernelClass;
70

71
        typedef FFmmAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass >     FmmClass;
72 73 74
        ///////////////////////What we do/////////////////////////////
        std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
        //////////////////////////////////////////////////////////////
75

76 77
        const int NbLevels      = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeHeight.options, 5);
        const int SizeSubLevels = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeSubHeight.options, 3);
78
        const FSize NbPart       = FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, FSize(2000000));
79
        const int DevP         = FParameters::getValue(argc,argv,FParameterDefinitions::SHDevelopment.options, 5);
80
        const FPoint<FReal> centerOfBox = FPoint<FReal>(0.5,0.5,0.5);
81
        FTic counter;
82

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

85 86
        //////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////
87

berenger-bramas's avatar
berenger-bramas committed
88
        CellClass::Init(DevP);
89
        const FReal boxWidth = 1.0;
90
        OctreeClass tree(NbLevels, SizeSubLevels, boxWidth, centerOfBox);
91

92 93
        //////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////
94

95 96 97
        std::cout << "Creating & Inserting " << NbPart << " particles ..." << std::endl;
        std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
        counter.tic();
98

99
        {
100
            FPoint<FReal> particlePosition;
101
            FReal physicalValue = 0.10;
102
            for(FSize idxPart = 0 ; idxPart < NbPart ; ++idxPart){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
103
                particlePosition.setPosition(FReal(drand48()),FReal(drand48()),FReal(drand48()));
104
                tree.insert(particlePosition, physicalValue);
105
            }
106 107
        }

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

111 112
        //////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////
113

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

117
        // FTestKernels FBasicKernels
118
        //KernelClass kernels;
119
        KernelClass kernels(DevP, NbLevels,boxWidth, centerOfBox);
120 121
        FmmClass algo(&tree,&kernels);
        algo.execute();
122

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

126 127 128
        //////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////
    }
129

130 131 132
    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";
133 134 135 136 137

    return 0;
}


138