Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62371590
partitioner.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, May 12, 18:04
Size
2 KB
Mime Type
text/x-c++
Expires
Tue, May 14, 18:04 (2 d)
Engine
blob
Format
Raw Data
Handle
17639131
Attached To
rTAMAAS tamaas
partitioner.hh
View Options
/**
* @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
Log In to Comment