From 94d3e79a8617f88dc0219cfdeedfa3147833719d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 24 Jun 2019 14:43:36 +0200 Subject: Initialize at openlb-1-3 --- src/communication/blockLoadBalancer.hh | 105 +++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/communication/blockLoadBalancer.hh (limited to 'src/communication/blockLoadBalancer.hh') diff --git a/src/communication/blockLoadBalancer.hh b/src/communication/blockLoadBalancer.hh new file mode 100644 index 0000000..0c61af1 --- /dev/null +++ b/src/communication/blockLoadBalancer.hh @@ -0,0 +1,105 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2007 Mathias Krause + * E-mail contact: info@openlb.net + * The most recent release of OpenLB can be downloaded at + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * 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 License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef BLOCK_LOAD_BALANCER_HH +#define BLOCK_LOAD_BALANCER_HH + +#include +#include +#include "communication/mpiManager.h" +#include "communication/blockLoadBalancer.h" +#include "geometry/cuboidGeometry2D.h" +#include "geometry/cuboidGeometry3D.h" +#include "core/olbDebug.h" + +namespace olb { + +template +BlockLoadBalancer::BlockLoadBalancer(int rank, int size, int globChunkSize, int offset) +{ + init_chunkD(rank, size, globChunkSize, offset); +} + +template +BlockLoadBalancer::BlockLoadBalancer(CuboidGeometry3D& cGeometry) +{ + init_chunkD(singleton::mpi().getRank(), singleton::mpi().getSize(), cGeometry.getNc(), 0); +} + +template +BlockLoadBalancer::BlockLoadBalancer(CuboidGeometry2D& cGeometry) +{ + init_chunkD(singleton::mpi().getRank(), singleton::mpi().getSize(), cGeometry.getNc(), 0); +} + +template +void BlockLoadBalancer::init_chunkD(int rank, int size, int globChunkSize, int offset) +{ + + OLB_PRECONDITION(rank>=0 && size>=1 && offset>=0) + OLB_PRECONDITION(size<=globChunkSize && rank_locChunkSize = (globChunkSize+size-rank-1)/size; + this->_size = _locChunkSize; + if (rank+1 <= globChunkSize-(globChunkSize/size)*size) { + this->_firstGlobNum = globChunkSize/size * rank + rank + offset; + this->_lastGlobNum = this->_firstGlobNum + this->_locChunkSize - 1; + } else { + this->_firstGlobNum = globChunkSize/size * rank + globChunkSize - (globChunkSize/size)*size + offset; + this->_lastGlobNum = this->_firstGlobNum + this->_locChunkSize - 1; + } + for (int i=0; i_locChunkSize; i++) { + this->_loc[this->_firstGlobNum + i] = i; + this->_glob.push_back(this->_firstGlobNum + i); + } + int temp = offset; + for (int iRank=0; iRank_rank[temp] = iRank; + temp++; + } + } +} + +template +int BlockLoadBalancer::locChunkSize() const +{ + return _locChunkSize; +} + +template +int BlockLoadBalancer::firstGlobNum() const +{ + return _firstGlobNum; +} + +template +int BlockLoadBalancer::lastGlobNum() const +{ + return _lastGlobNum; +} + +} // namespace olb +#endif -- cgit v1.2.3