1 #ifndef BROADCAST_VIEWS_HPP
2 #define BROADCAST_VIEWS_HPP
8 template <
typename ViewType>
9 void resize_view(ViewType& view,
const std::vector<int>& extents) {
10 if constexpr (ViewType::rank == 1) {
11 view = ViewType(view.label(), extents[0]);
12 }
else if constexpr (ViewType::rank == 2) {
13 view = ViewType(view.label(), extents[0], extents[1]);
14 }
else if constexpr (ViewType::rank == 3) {
15 view = ViewType(view.label(), extents[0], extents[1], extents[2]);
16 }
else if constexpr (ViewType::rank == 4) {
17 view = ViewType(view.label(), extents[0], extents[1], extents[2], extents[3]);
18 }
else if constexpr (ViewType::rank == 5) {
19 view = ViewType(view.label(), extents[0], extents[1], extents[2], extents[3], extents[4]);
20 }
else if constexpr (ViewType::rank == 6) {
21 view = ViewType(view.label(), extents[0], extents[1], extents[2], extents[3], extents[4], extents[5]);
26 template <
typename... Views>
27 void broadcast_views(
const MPI_Comm& comm,
const int ROOT_RANK, Views&... views) {
30 MPI_Comm_rank( comm, &my_rank);
31 MPI_Comm_size( comm, &nranks);
34 std::vector<std::vector<int>> extents_list;
36 std::vector<int> extents(Views::rank);
37 if(my_rank==ROOT_RANK){
38 for (
int i = 0; i < Views::rank; i++) {
39 extents[i] = views.extent(i);
42 extents_list.push_back(extents);
46 for (
int v = 0; v < (
sizeof...(Views)); v++) {
47 MPI_Bcast(extents_list[v].data(), extents_list[v].size(), MPI_INT, ROOT_RANK, comm);
51 if(my_rank!=ROOT_RANK){
61 MPI_Bcast(views.data(), views.size(),
get_mpi_type(views), ROOT_RANK, comm);
void broadcast_views(const MPI_Comm &comm, const int ROOT_RANK, Views &...views)
Definition: broadcast_views.hpp:27
MPI_Datatype get_mpi_type()
Definition: my_mpi.hpp:200
void resize_view(ViewType &view, const std::vector< int > &extents)
Definition: broadcast_views.hpp:9