testFlopsChebAlgorithm.cpp 3.37 KB
Newer Older
1
// See LICENCE file at project root
2

3 4 5 6 7

/**
 *@author Matthias Messner
 *
 * **/
8 9 10 11 12 13 14 15 16
// ==== CMAKE =====
// @FUSE_BLAS
// ================

#include <iostream>

#include <cstdio>
#include <cstdlib>

17
#include "Files/FFmaScanfLoader.hpp"
18

19 20
#include "Kernels/Chebyshev/FChebCell.hpp"
#include "Kernels/Interpolation/FInterpMatrixKernel.hpp"
21

22
#include "Kernels/Chebyshev/FChebFlopsSymKernel.hpp"
23

24
#include "Utils/FParameters.hpp"
25

26 27
#include "Containers/FOctree.hpp"
#include "Containers/FVector.hpp"
28

29
#include "Core/FFmmAlgorithm.hpp"
30

31 32
#include "Components/FSimpleLeaf.hpp"
#include "Kernels/P2P/FP2PParticleContainer.hpp"
33

34
#include "Utils/FParameterNames.hpp"
35 36 37 38


int main(int argc, char* argv[])
{
39 40 41 42 43
    FHelpDescribeAndExit(argc, argv,
                         "Counts the number of flops requiered for a Chebyshev FMM.",
                         FParameterDefinitions::InputFile, FParameterDefinitions::OctreeHeight,
                         FParameterDefinitions::OctreeSubHeight);

44
    typedef double FReal;
45 46 47
    const char* const filename       = FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options, "../Data/test20k.fma");
    const unsigned int TreeHeight    = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeHeight.options, 5);
    const unsigned int SubTreeHeight = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeSubHeight.options, 2);
48

49 50
	const unsigned int ORDER = 8;
	const FReal epsilon = FReal(1e-8);
51 52 53

	// init timer
	FTic time;
54 55

	// typedefs
56 57 58 59 60 61
	typedef FP2PParticleContainer<FReal> ContainerClass;
    typedef FSimpleLeaf<FReal,ContainerClass> LeafClass;
    typedef FInterpMatrixKernelR<FReal> MatrixKernelClass;
    typedef FChebCell<FReal,ORDER> CellClass;
    typedef FOctree<FReal,CellClass,ContainerClass,LeafClass> OctreeClass;
    typedef FChebFlopsSymKernel<FReal,CellClass,ContainerClass,MatrixKernelClass,ORDER> KernelClass;
62
	typedef FFmmAlgorithm<OctreeClass,CellClass,ContainerClass,KernelClass,LeafClass> FmmClass;
63 64 65 66


	// What we do //////////////////////////////////////////////////////
	std::cout << ">> Testing the Chebyshev interpolation base FMM algorithm.\n";
67

68
	// open particle file
69
    FFmaScanfLoader<FReal> loader(filename);
70
	//
71
	if(!loader.isOpen()) throw std::runtime_error("Particle file couldn't be opened!");
72

73 74 75 76 77
	// init oct-tree
	OctreeClass tree(TreeHeight, SubTreeHeight, loader.getBoxWidth(), loader.getCenterOfBox());

	// -----------------------------------------------------
	std::cout << "Creating and inserting " << loader.getNumberOfParticles()
78
								<< " particles in a octree of height " << TreeHeight << " ..." << std::endl;
79
	time.tic();
80

81
	{
82
        FPoint<FReal> particlePosition;
83
		FReal physicalValue = 0.0;
84
		for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
85 86 87 88
			loader.fillParticle(&particlePosition,&physicalValue);
			tree.insert(particlePosition, physicalValue);
		}
	}
89

90 91 92
	std::cout << "Done  " << "(" << time.tacAndElapsed() << ")." << std::endl;
	// -----------------------------------------------------

93

94 95
	// -----------------------------------------------------
	std::cout << "\nChebyshev FMM ... " << std::endl;
96
	KernelClass kernels(TreeHeight, loader.getBoxWidth(),loader.getCenterOfBox(), epsilon);
97
	FmmClass algorithm(&tree,&kernels);
98
	time.tic();
99 100 101
	algorithm.execute();
	std::cout << "completed in " << time.tacAndElapsed() << "sec." << std::endl;
	// -----------------------------------------------------
102 103

	return 0;
104 105 106 107
}