FParticlesBalance.hpp 2.56 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
// ===================================================================================

#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
   */
40 41
  FSize getRight(const FSize numberOfLeaves,
                 const int numberOfProc, const int idxOfProc){
42 43 44 45 46 47 48 49 50 51 52 53 54
    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;
  }
55

56 57 58
  /**
   * get left interval based on particles distribution
   */
59 60
  FSize getLeft(const FSize numberOfLeaves,
                const int numberOfProc, const int idxOfProc){
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    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