FCoreCommon.hpp 3.55 KB
Newer Older
1
// ===================================================================================
2
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Berenger Bramas, Matthias Messner
3 4 5 6 7 8 9 10 11 12 13 14 15
// 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".
// ===================================================================================
16 17 18
#ifndef FCORECOMMON_HPP
#define FCORECOMMON_HPP

19 20 21
#include "../Utils/FGlobal.hpp"
#include "../Utils/FAssert.hpp"

22 23 24 25 26
#ifdef SCALFMM_USE_EZTRACE
extern "C" {
#include "eztrace.h"
}
#endif
27 28 29 30
/**
 * @brief The FFmmOperations enum
 * To chose which operation has to be performed.
 */
31
enum FFmmOperations {
32 33
    FFmmP2P   = (1 << 0),
    FFmmP2M  = (1 << 1),
34
    FFmmM2M = (1 << 2),
35 36 37 38
    FFmmM2L  = (1 << 3),
    FFmmL2L  = (1 << 4),
    FFmmL2P  = (1 << 5),
//
39 40
    FFmmNearField = FFmmP2P,
    FFmmFarField  = (FFmmP2M|FFmmM2M|FFmmM2L|FFmmL2L|FFmmL2P),
41
//
42 43 44
    FFmmNearAndFarFields = (FFmmNearField|FFmmFarField)
};

45
/**
46 47 48 49
 * \brief Base class of algorithms
 *
 * This class is an abstract algorithm to be able to use the FAlgorithmBuilder
 * and execute from an abstract pointer.
50 51 52
 */
class FAbstractAlgorithm {
protected:
Quentin Khan's avatar
Quentin Khan committed
53 54 55 56

    int upperWorkingLevel; ///< Where to start the work
    int lowerWorkingLevel; ///< Where to end the work (exclusive)
    int nbLevelsInTree;    ///< Height of the tree
57 58

    void setNbLevelsInTree(const int inNbLevelsInTree){
59
        nbLevelsInTree       = inNbLevelsInTree;
60 61 62
        lowerWorkingLevel = nbLevelsInTree;
    }

63 64 65 66 67
    void validateLevels() const {
        FAssertLF(FAbstractAlgorithm::upperWorkingLevel <= FAbstractAlgorithm::lowerWorkingLevel);
        FAssertLF(2 <= FAbstractAlgorithm::upperWorkingLevel);
    }

68 69
    virtual void executeCore(const unsigned operationsToProceed) = 0;

70
public:
71 72 73 74
    FAbstractAlgorithm()
        : upperWorkingLevel(2), lowerWorkingLevel(0), nbLevelsInTree(-1){
    }

75 76 77
    virtual ~FAbstractAlgorithm(){
    }

Quentin Khan's avatar
Quentin Khan committed
78
    /** \brief Execute the whole fmm for given levels. */
79 80 81
    virtual void execute(const int inUpperWorkingLevel, const int inLowerWorkingLevel) final {
        upperWorkingLevel = inUpperWorkingLevel;
        lowerWorkingLevel = inLowerWorkingLevel;
82
        validateLevels();
83 84 85
        executeCore(FFmmNearAndFarFields);
    }

Quentin Khan's avatar
Quentin Khan committed
86
    /** \brief Execute the whole fmm. */
87 88 89
    virtual void execute() final {
        upperWorkingLevel = 2;
        lowerWorkingLevel = nbLevelsInTree;
90
        validateLevels();
91 92 93
        executeCore(FFmmNearAndFarFields);
    }

Quentin Khan's avatar
Quentin Khan committed
94
    /** \brief Execute only some FMM operations for given levels. */
95 96 97
    virtual void execute(const unsigned operationsToProceed, const int inUpperWorkingLevel, const int inLowerWorkingLevel) final {
        upperWorkingLevel = inUpperWorkingLevel;
        lowerWorkingLevel = inLowerWorkingLevel;
98
        validateLevels();
99
        executeCore(operationsToProceed);
100 101
    }

Quentin Khan's avatar
Quentin Khan committed
102
    /** \brief Execute only some steps. */
103 104 105
    virtual void execute(const unsigned operationsToProceed) final {
        upperWorkingLevel = 2;
        lowerWorkingLevel = nbLevelsInTree;
106
        validateLevels();
107 108
        executeCore(operationsToProceed);
    }
109 110 111 112 113
};




114
#endif // FCORECOMMON_HPP