Page MenuHomec4science

partitioner.hh
No OneTemporary

File Metadata

Created
Sun, May 12, 18:04

partitioner.hh

/**
* @file
* @section LICENSE
*
* Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne),
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#ifndef PARTITIONER_HH
#define PARTITIONER_HH
/* -------------------------------------------------------------------------- */
#include "fftw_mpi_interface.hh"
#include "mpi_interface.hh"
#include "tamaas.hh"
#include "grid.hh"
#include <algorithm>
#include <array>
#include <cstdlib>
/* -------------------------------------------------------------------------- */
namespace tamaas {
template <UInt dim>
struct Partitioner {
static decltype(auto) global_size(std::array<UInt, dim> local) {
local.front() = mpi::allreduce<operation::plus>(local.front());
return local;
}
template <typename T>
static decltype(auto) global_size(const Grid<T, dim>& grid) {
return global_size(grid.sizes());
}
static decltype(auto) local_size(std::array<UInt, dim> global) {
auto tup =
fftw::mpi::local_size_many(dim, cast_size(global).data(), 1);
global.front() = static_cast<UInt>(std::get<1>(tup));
return global;
}
template <typename T>
static decltype(auto) local_size(const Grid<T, dim>& grid) {
return local_size(grid.sizes());
}
static decltype(auto) local_offset(const std::array<UInt, dim>& global) {
auto tup =
fftw::mpi::local_size_many(dim, cast_size(global).data(), 1);
return static_cast<std::size_t>(std::get<2>(tup));
}
template <typename T>
static decltype(auto) local_offset(const Grid<T, dim>& grid) {
auto offset = local_offset(global_size(grid.sizes()));
return offset * grid.getStrides().front();
}
static decltype(auto) cast_size(const std::array<UInt, dim>& s) {
std::array<std::ptrdiff_t, dim> n;
std::copy(s.begin(), s.end(), n.begin());
return n;
}
};
} // namespace tamaas
#endif

Event Timeline