testBlockedAlgorithm.cpp 8.78 KB
Newer Older
1 2 3 4 5

// Keep in private GIT
// @SCALFMM_PRIVATE


BRAMAS Berenger's avatar
BRAMAS Berenger committed
6 7
#include "../../Src/Utils/FGlobal.hpp"

8
#include "../../Src/GroupTree/Core/FGroupTree.hpp"
9 10 11 12 13 14 15 16 17 18 19

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


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

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

20
#include "../../Src/GroupTree/Core/FGroupSeqAlgorithm.hpp"
21
#ifdef SCALFMM_USE_OMP4
22
#include "../../Src/GroupTree/Core/FGroupTaskDepAlgorithm.hpp"
23
#endif
24
#ifdef SCALFMM_USE_STARPU
25 26
#include "../../Src/GroupTree/Core/FGroupTaskStarpuAlgorithm.hpp"
#include "../../Src/GroupTree/StarPUUtils/FStarPUKernelCapacities.hpp"
27 28

#include "../../Src/GroupTree/StarPUUtils/FStarPUCpuWrapper.hpp"
29
#endif
30 31
#include "../../Src/GroupTree/Core/FP2PGroupParticleContainer.hpp"
#include "../../Src/GroupTree/Core/FGroupTaskAlgorithm.hpp"
32 33 34

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

35
#include "../../Src/Components/FTestParticleContainer.hpp"
36 37
#include "../../Src/Components/FTestCell.hpp"
#include "../../Src/Components/FTestKernels.hpp"
38
#include "../../Src/GroupTree/TestKernel/FGroupTestParticleContainer.hpp"
39
#include "../../Src/GroupTree/TestKernel/FTestCellPOD.hpp"
40

41
#include "../../Src/Files/FFmaGenericLoader.hpp"
42 43
#include "../../Src/Core/FFmmAlgorithm.hpp"

44
int main(int argc, char* argv[]){
45
    setenv("STARPU_NCPU","1",1);
46 47 48 49 50
    const FParameterNames LocalOptionBlocSize {
        {"-bs"},
        "The size of the block of the blocked tree"
    };
    FHelpDescribeAndExit(argc, argv, "Test the blocked tree by counting the particles.",
51 52
                         FParameterDefinitions::OctreeHeight, FParameterDefinitions::NbParticles,
                         FParameterDefinitions::OctreeSubHeight, LocalOptionBlocSize);
53 54 55

    typedef double FReal;

56
    // Initialize the types
57 58 59 60 61 62
    typedef FTestCellPODCore  GroupCellSymbClass;
    typedef FTestCellPODData  GroupCellUpClass;
    typedef FTestCellPODData  GroupCellDownClass;
    typedef FTestCellPOD      GroupCellClass;


63 64
    typedef FGroupTestParticleContainer<FReal>                                GroupContainerClass;
    typedef FGroupTree< FReal, GroupCellClass, GroupCellSymbClass, GroupCellUpClass, GroupCellDownClass,
65
            GroupContainerClass, 0, 1, long long int>  GroupOctreeClass;
66
#ifdef SCALFMM_USE_STARPU
67 68 69
    typedef FStarPUAllCpuCapacities<FTestKernels< GroupCellClass, GroupContainerClass >>  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;
70
#elif defined(SCALFMM_USE_OMP4)
71
    typedef FTestKernels< GroupCellClass, GroupContainerClass >  GroupKernelClass;
72 73
    typedef FGroupTaskDepAlgorithm<GroupOctreeClass, typename GroupOctreeClass::CellGroupClass, GroupCellClass,
            GroupCellSymbClass, GroupCellUpClass, GroupCellDownClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupContainerClass > GroupAlgorithm;
BRAMAS Berenger's avatar
BRAMAS Berenger committed
74
#else
75
    typedef FTestKernels< GroupCellClass, GroupContainerClass >  GroupKernelClass;
76
    //typedef FGroupSeqAlgorithm<GroupOctreeClass, typename GroupOctreeClass::CellGroupClass, GroupCellClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupContainerClass > GroupAlgorithm;
BRAMAS Berenger's avatar
BRAMAS Berenger committed
77 78
    typedef FGroupTaskAlgorithm<GroupOctreeClass, typename GroupOctreeClass::CellGroupClass, GroupCellClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupContainerClass > GroupAlgorithm;
#endif
79 80

    typedef FTestCell                   CellClass;
81 82 83
    typedef FTestParticleContainer<FReal>      ContainerClass;
    typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
    typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
84 85 86 87 88
    typedef FTestKernels< CellClass, ContainerClass >         KernelClass;

    // FFmmAlgorithmTask FFmmAlgorithmThread
    typedef FFmmAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass >     FmmClass;

89 90 91 92
    // Get params
    const int NbLevels      = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeHeight.options, 5);
    const int groupSize      = FParameters::getValue(argc,argv,LocalOptionBlocSize.options, 250);

93 94
//#define LOAD_FILE
#ifndef LOAD_FILE
95
    const FSize NbParticles   = FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, FSize(20));
96
    FRandomLoader<FReal> loader(NbParticles, 1.0, FPoint<FReal>(0,0,0), 0);
97 98 99
#else
    // Load the particles
    const char* const filename = FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options, "../Data/test20k.fma");
100
    FFmaGenericLoader<FReal> loader(filename);
101
#endif
102
    FAssertLF(loader.isOpen());
103 104

    // Usual octree
105 106
    OctreeClass tree(NbLevels, FParameters::getValue(argc,argv,FParameterDefinitions::OctreeSubHeight.options, 2),
                     loader.getBoxWidth(), loader.getCenterOfBox());
107

BRAMAS Berenger's avatar
BRAMAS Berenger committed
108
    FTestParticleContainer<FReal> allParticles;
109
    for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
110
        FPoint<FReal> particlePosition;
111
#ifndef LOAD_FILE
112
        loader.fillParticle(&particlePosition);
113 114 115 116
#else
        FReal ph;
        loader.fillParticle(&particlePosition, &ph);
#endif
117
        allParticles.push(particlePosition);
118
        tree.insert(particlePosition);
119 120 121
    }

    // Put the data into the tree
122
    //GroupOctreeClass groupedTree(NbLevels, groupSize, &tree);
123
    //GroupOctreeClass groupedTree(NbLevels, loader.getBoxWidth(), loader.getCenterOfBox(), groupSize, &allParticles);
124
    //GroupOctreeClass groupedTree(NbLevels, loader.getBoxWidth(), loader.getCenterOfBox(), groupSize, &allParticles, false, true);
125
    GroupOctreeClass groupedTree(NbLevels, loader.getBoxWidth(), loader.getCenterOfBox(), groupSize, &allParticles, false, true, 0.2);
126 127
    groupedTree.printInfoBlocks();

128
    // Check tree structure at leaf level
129
    groupedTree.forEachCellLeaf<GroupContainerClass>([&](GroupCellClass gcell, GroupContainerClass* gleaf){
130
        const ContainerClass* src = tree.getLeafSrc(gcell.getMortonIndex());
131
        if(src == nullptr){
132
            std::cout << "[PartEmpty] Error cell should not exist " << gcell.getMortonIndex() << "\n";
133 134 135
        }
        else {
            if(src->getNbParticles() != gleaf->getNbParticles()){
136
                std::cout << "[Part] Nb particles is different at index " << gcell.getMortonIndex() << " is " << gleaf->getNbParticles() << " should be " << src->getNbParticles() << "\n";
137 138 139 140
            }
        }
    });

141
    // Run the algorithm
142 143 144 145 146 147 148
    GroupKernelClass groupkernel;
    GroupAlgorithm groupalgo(&groupedTree,&groupkernel);
    groupalgo.execute();

    // Usual algorithm
    KernelClass kernels;            // FTestKernels FBasicKernels
    FmmClass algo(&tree,&kernels);  //FFmmAlgorithm FFmmAlgorithmThread
149 150 151
    algo.execute();

    // Validate the result
152
    groupedTree.forEachCellLeaf<GroupContainerClass>([&](GroupCellClass cell, GroupContainerClass* leaf){
153
        const FSize nbPartsInLeaf = leaf->getNbParticles();
154 155
        if(cell.getDataUp() != nbPartsInLeaf){
            std::cout << "[P2M] Error a Cell has " << cell.getDataUp() << " (it should be " << nbPartsInLeaf << ")\n";
156 157
        }
    });
158
    groupedTree.forEachCellLeaf<GroupContainerClass>([&](GroupCellClass cell, GroupContainerClass* leaf){
159
        const FSize nbPartsInLeaf = leaf->getNbParticles();
160
        const long long int* dataDown = leaf->getDataDown();
161
        for(FSize idxPart = 0 ; idxPart < nbPartsInLeaf ; ++idxPart){
162
            if(dataDown[idxPart] != loader.getNumberOfParticles()-1){
163
                std::cout << "[Full] Error a particle has " << dataDown[idxPart] << " (it should be " << (loader.getNumberOfParticles()-1) << ") at index " << cell.getMortonIndex() << "\n";
164 165 166
            }
        }
    });
167
    // Compare the results
168 169
    groupedTree.forEachCellWithLevel([&](GroupCellClass gcell, const int level){
        const CellClass* cell = tree.getCell(gcell.getMortonIndex(), level);
170
        if(cell == nullptr){
171
            std::cout << "[Empty] Error cell should not exist " << gcell.getMortonIndex() << "\n";
172 173
        }
        else {
174 175
            if(gcell.getDataUp() != cell->getDataUp()){
                std::cout << "[Up] Up is different at index " << gcell.getMortonIndex() << " level " << level << " is " << gcell.getDataUp() << " should be " << cell->getDataUp() << "\n";
176
            }
177 178
            if(gcell.getDataDown() != cell->getDataDown()){
                std::cout << "[Down] Down is different at index " << gcell.getMortonIndex() << " level " << level << " is " << gcell.getDataDown() << " should be " << cell->getDataDown() << "\n";
179 180 181
            }
        }
    });
182 183 184

    return 0;
}