Commit 86db170e authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille

New balance algorithm for building the parallel tree. A Balance repertory has...

New balance algorithm for building the parallel tree. A Balance repertory has been created, with an FAbastractBalanceAlgorithm providing what it's needed to be a BalanceAlgorithm
parent 63680e00
// ===================================================================================
// 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".
// ===================================================================================
#ifndef FABSTRACTBALANCEALGORITHM_H
#define FABSTRACTBALANCEALGORITHM_H
/**
* @author Cyrille Piacibello
* @class FAbstractBalanceAlgorithm
*
* @brief This class provide the methods that are used to balance a
* tree FMpiTreeBuilder::EqualizeAndFillTree
*/
class FAbstractBalanceAlgorithm{
public:
virtual ~FAbstractBalanceAlgorithm(){
}
/**
* @brief Give the right leaves (ie the min) of the interval that
* will be handle by idxOfProc
* @param numberOfLeaves Total number of leaves that exist.
* @param numberOfPartPerLeaf Array of lenght numberOfLeaves containing the number of particles in each leaf
* @param numberOfPart Number of particles in the whole field
* @param idxOfLeaves Array of lenght numberOfLeaves containing the Morton Index of each Leaf
* @param numberOfProc Number of MPI processus that will handle the Octree
* @param idxOfProc Idx of the proc calling.
*/
virtual FSize getRight(const FSize numberOfLeaves, const int*numberOfPartPerLeaf, const FSize numberOfPart, const MortonIndex* idxOfLeaves,
const int numberOfProc, const int idxOfProc) = 0;
/**
* @brief Give the Leaft leaves (ie the max) of the interval that
* will be handle by idxOfProc
* @param numberOfLeaves Total number of leaves that exist.
* @param numberOfPartPerLeaf Array of lenght numberOfLeaves containing the number of particles in each leaf
* @param numberOfPart Number of particles in the whole field
* @param idxOfLeaves Array of lenght numberOfLeaves containing the Morton Index of each Leaf
* @param numberOfProc Number of MPI processus that will handle the Octree
* @param idxOfProc Idx of the proc calling.
*/
virtual FSize getLeft(const FSize numberOfLeaves, const int*numberOfPartPerLeaf, const FSize numberOfPart, const MortonIndex* idxOfLeaves,
const int numberOfProc, const int idxOfProc) = 0;
};
#endif //FABSTRACTBALANCEALGORITHM_H
// ===================================================================================
// 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".
// ===================================================================================
#ifndef FLEAFBALANCE_H
#define FLEAFBALANCE_H
#include "./FAbstractBalanceAlgorithm.hpp"
#include "../Utils/FMath.hpp"
/**
* @author Cyrille Piacibello
* @class FLeafBalance
*
* @brief This class inherits from FAbstractBalanceAlgorithm. It
* provides balancing methods based on leaf numbers only.
*/
class FLeafBalance : public FAbstractBalanceAlgorithm{
public:
/**
* Does not need the number of particles. Just divide the leaves
* over processus
*/
FSize getRight(const FSize numberOfLeaves, const int*numberOfPartPerLeaf, const FSize numberOfPart, const MortonIndex* idxOfLeaves,
const int numberOfProc, const int idxOfProc){
const double step = (double(numberOfLeaves) / double(numberOfProc));
const FSize res = FSize(FMath::Ceil(step * double(idxOfProc+1)));
if(res > numberOfLeaves) return numberOfLeaves;
else return res;
}
/**
* Does not need the number of particles. Just divide the leaves
* over processus
*/
FSize getLeft(const FSize numberOfLeaves, const int*numberOfPartPerLeaf, const FSize numberOfPart, const MortonIndex* idxOfLeaves,
const int numberOfProc, const int idxOfProc){
const double step = (double(numberOfLeaves) / double(numberOfProc));
return FSize(FMath::Ceil(step * double(idxOfProc)));
}
};
#endif // FLEAFBALANCE_H
// ===================================================================================
// 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".
// ===================================================================================
#ifndef FPARTICLESBALANCE_H
#define FPARTICLESBALANCE_H
#include "./FAbstractBalanceAlgorithm.hpp"
#include "../Utils/FMath.hpp"
/**
* @author Cyrille Piacibello
* @class FLeafBalance
*
* @brief This class inherits from FAbstractBalanceAlgorithm. It
* provides balancing methods based on particles distribution.
*/
class FParticlesBalance : public FAbstractBalanceAlgorithm{
public:
/**
* getRight interval based on particles distribution
*/
FSize getRight(const FSize numberOfLeaves, const int*numberOfPartPerLeaf, const FSize numberOfPart, const MortonIndex* idxOfLeaves,
const int numberOfProc, const int idxOfProc){
int acc = 0;
FSize i = 0;
const double step = (double(numberOfPart) / double(numberOfProc));
FSize aimRight = FSize(FMath::Ceil(step * double(idxOfProc+1)));
if(aimRight > numberOfPart) aimRight = numberOfPart;
while(acc < aimRight){
acc+=numberOfPartPerLeaf[i];
++i;
}
if(FMath::Abs(aimRight-acc) < FMath::Abs(aimRight-(acc-numberOfPartPerLeaf[i]))) return i;
else
return i-1;
}
/**
* get left interval based on particles distribution
*/
FSize getLeft(const FSize numberOfLeaves, const int*numberOfPartPerLeaf, const FSize numberOfPart, const MortonIndex* idxOfLeaves,
const int numberOfProc, const int idxOfProc){
int acc = 0;
FSize i = 0;
const double step = (double(numberOfPart) / double(numberOfProc));
const FSize aimLeft = FSize(FMath::Ceil(step * double(idxOfProc)));
while (acc < aimLeft){
acc+=numberOfPartPerLeaf[i];
++i;
}
if(FMath::Abs(aimLeft-acc) < FMath::Abs(aimLeft-(acc-numberOfPartPerLeaf[i]))) return i;
else
return i-1;
}
};
#endif // FPARTICLESBALANCE_H
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment