testFmmAlgorithmBalanced.cpp 4.93 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 23
// ==== CMAKE ====
// Keep in private GIT
// @SCALFMM_PRIVATE
24
// @FUSE_BLAS
25 26


Quentin Khan's avatar
Quentin Khan committed
27 28 29
#include <string>

#include "Files/FFmaGenericLoader.hpp"
30
#include "Files/FRandomLoader.hpp"
Quentin Khan's avatar
Quentin Khan committed
31
#include "Containers/FOctree.hpp"
32 33 34 35 36 37 38 39 40 41 42

// 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
43 44
#include "Components/FSimpleLeaf.hpp"

45 46 47
// Kernel
//#include "Kernels/Chebyshev/FChebSymKernel.hpp"
#include "Components/FTestKernels.hpp"
48
#include "BalanceTree/FChebSymCostKernel.hpp"
49
#include "BalanceTree/FDumbCostKernel.hpp"
50 51

// Algorithm
52
#include "Core/FFmmAlgorithmThread.hpp"
53
#include "BalanceTree/FFmmAlgorithmThreadBalanced.hpp"
54 55

// Other
56 57 58
#include "BalanceTree/FCostZones.hpp"
#include "testFmmAlgorithmBalancedArgs.hpp"
#include "testFmmAlgorithmBalancedUtils.hpp" // last include, to shorten main file
59 60

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

62 63
using FReal = double;

64
using CellClass         = FCostCell<FTestCell>;
65 66 67
using ContainerClass    = FTestParticleContainer<FReal>;
using LeafClass         = FSimpleLeaf< FReal, ContainerClass >;
using OctreeClass       = FOctree< FReal, CellClass, ContainerClass, LeafClass >;
68

69
using MatrixKernelClass = FInterpMatrixKernelR<FReal>;
70 71 72 73 74
// using CostKernelClass   = FChebSymCostKernel<FReal, CellClass, ContainerClass,
//                                              MatrixKernelClass, ORDER,
//                                              OctreeClass>;
using CostKernelClass   = FDumbCostKernel<FReal, CellClass, ContainerClass,
                                             OctreeClass>;
75

76
using KernelClass       = FTestKernels< CellClass, ContainerClass>;
77

Quentin Khan's avatar
Quentin Khan committed
78 79 80

const FReal epsilon = 1e-4;

81

Quentin Khan's avatar
Quentin Khan committed
82 83
int main(int argc, char** argv)
{
84
    // Handle arguments
Quentin Khan's avatar
Quentin Khan committed
85
    loadFMAAndRunFMMArgs args(argc, argv);
86
    omp_set_num_threads(args.zoneCount());
87 88

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

96
    loadTree(tree, loader);
97 98 99 100
    /**************************************************************************/


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

104
    costAlgo.execute();
Quentin Khan's avatar
Quentin Khan committed
105

106
    if (args.verboseLevel() > 1) {
107
        //costKernel.printResults(std::cout);
108
    }
109 110
    /**************************************************************************/

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

116
    /**************************************************************************/
117
    std::cerr << "Done" << std::endl;
118 119 120 121 122 123


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

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


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

136

Quentin Khan's avatar
Quentin Khan committed
137 138 139 140
    return EXIT_SUCCESS;
}