testFmmAlgorithmBalanced.cpp 4.75 KB
Newer Older
Quentin Khan's avatar
Quentin Khan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// ===================================================================================
// Copyright ScalFmm 2011 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.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.  
// 
// 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
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info". 
// "http://www.gnu.org/licenses".
// ===================================================================================

17
18
19
// ==== CMAKE ====
// Keep in private GIT
// @SCALFMM_PRIVATE
20
// @FUSE_BLAS
21
22


Quentin Khan's avatar
Quentin Khan committed
23
24
25
#include <string>

#include "Files/FFmaGenericLoader.hpp"
26
#include "Files/FRandomLoader.hpp"
Quentin Khan's avatar
Quentin Khan committed
27
#include "Containers/FOctree.hpp"
28
29
30
31
32
33
34
35
36
37
38

// Cell
//#include "Components/FBasicCell.hpp"
//#include "Kernels/Chebyshev/FChebCell.hpp"
#include "Components/FTestCell.hpp"

// Particle Container
//#include "Components/FBasicParticleContainer.hpp"
#include "Components/FTestParticleContainer.hpp"

// Leaf
Quentin Khan's avatar
Quentin Khan committed
39
40
#include "Components/FSimpleLeaf.hpp"

41
42
43
// Kernel
//#include "Kernels/Chebyshev/FChebSymKernel.hpp"
#include "Components/FTestKernels.hpp"
44
#include "BalanceTree/FChebSymCostKernel.hpp"
45
#include "BalanceTree/FDumbCostKernel.hpp"
46
47

// Algorithm
48
#include "Core/FFmmAlgorithmThread.hpp"
49
#include "BalanceTree/FFmmAlgorithmThreadBalanced.hpp"
50
51

// Other
52
53
54
#include "BalanceTree/FCostZones.hpp"
#include "testFmmAlgorithmBalancedArgs.hpp"
#include "testFmmAlgorithmBalancedUtils.hpp" // last include, to shorten main file
55
56

#define ORDER 7
Quentin Khan's avatar
Quentin Khan committed
57

58
59
using FReal = double;

60
using CellClass         = FCostCell<FTestCell>;
Quentin Khan's avatar
Quentin Khan committed
61
62
63
using ContainerClass    = FTestParticleContainer<FReal>;
using LeafClass         = FSimpleLeaf< FReal, ContainerClass >;
using OctreeClass       = FOctree< FReal, CellClass, ContainerClass, LeafClass >;
64

Quentin Khan's avatar
Quentin Khan committed
65
using MatrixKernelClass = FInterpMatrixKernelR<FReal>;
66
67
68
69
70
// using CostKernelClass   = FChebSymCostKernel<FReal, CellClass, ContainerClass,
//                                              MatrixKernelClass, ORDER,
//                                              OctreeClass>;
using CostKernelClass   = FDumbCostKernel<FReal, CellClass, ContainerClass,
                                             OctreeClass>;
Quentin Khan's avatar
Quentin Khan committed
71

Quentin Khan's avatar
Quentin Khan committed
72
using KernelClass       = FTestKernels< CellClass, ContainerClass>;
73

Quentin Khan's avatar
Quentin Khan committed
74
75
76

const FReal epsilon = 1e-4;

Quentin Khan's avatar
Quentin Khan committed
77

Quentin Khan's avatar
Quentin Khan committed
78
79
int main(int argc, char** argv)
{
80
    // Handle arguments
Quentin Khan's avatar
Quentin Khan committed
81
    loadFMAAndRunFMMArgs args(argc, argv);
82
    omp_set_num_threads(args.zoneCount());
83
84

    /* Creating tree and insterting particles *********************************/
Quentin Khan's avatar
Quentin Khan committed
85
    FFmaGenericLoader<FReal> loader(args.inFileName().c_str());
86
    //FRandomLoader loader(20, 1, FPoint(0.5,0.5,0.5), 1);
Quentin Khan's avatar
Quentin Khan committed
87
88
89
90
91
    OctreeClass tree(args.treeHeight(),
                     args.subTreeHeight(),
                     loader.getBoxWidth(),
                     loader.getCenterOfBox());

Quentin Khan's avatar
Quentin Khan committed
92
    loadTree(tree, loader);
93
94
95
96
    /**************************************************************************/


    /* Compute the cost of each tree cell *************************************/
97
    CostKernelClass costKernel(&tree, epsilon);
BRAMAS Berenger's avatar
BRAMAS Berenger committed
98
    FFmmAlgorithmThread<OctreeClass, CellClass, ContainerClass, CostKernelClass, LeafClass > costAlgo(&tree, &costKernel);
Quentin Khan's avatar
Quentin Khan committed
99

Quentin Khan's avatar
Quentin Khan committed
100
    costAlgo.execute();
Quentin Khan's avatar
Quentin Khan committed
101

Quentin Khan's avatar
Quentin Khan committed
102
    if (args.verboseLevel() > 1) {
103
        //costKernel.printResults(std::cout);
Quentin Khan's avatar
Quentin Khan committed
104
    }
105
106
    /**************************************************************************/

107
    std::cerr << "Running the costzones algorithm" << std::endl;
108
    /* Run the costzone algorithm *********************************************/
109
    FCostZones<OctreeClass, CellClass> costzones(&tree, args.zoneCount());
Quentin Khan's avatar
Quentin Khan committed
110
111
    costzones.run();

112
    /**************************************************************************/
113
    std::cerr << "Done" << std::endl;
114
115
116
117
118
119


    /* Run the balanced algorithm *********************************************/

    std::cout << "Running kernel" << std::endl;
    KernelClass computeKernel;
BRAMAS Berenger's avatar
BRAMAS Berenger committed
120
121
122
123
    FFmmAlgorithmThreadBalanced<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass >
            fmmAlgo(&tree, &computeKernel, costzones.getZoneBounds(), costzones.getLeafZoneBounds());
    //FFmmAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass >
    //     fmmAlgo(&tree, &computeKernel);
Quentin Khan's avatar
Quentin Khan committed
124
    
125
126
127
128
129
130
131
    fmmAlgo.execute();
    /**************************************************************************/


    /* Check the results ******************************************************/
    ValidateFMMAlgo<OctreeClass, CellClass, ContainerClass, LeafClass>(&tree);

132

Quentin Khan's avatar
Quentin Khan committed
133
134
135
136
    return EXIT_SUCCESS;
}