OGS
getCommunicator.cpp
Go to the documentation of this file.
1
14#include "getCommunicator.h"
15
16#include <hdf5.h>
17#include <math.h>
18#include <mpi.h>
19
20#include <cassert>
21
22#include "BaseLib/Logging.h"
24
25namespace MeshLib::IO
26{
27int getGroupIndex(int const input_index, int const input_size,
28 int const new_group_size)
29{
30 // A grouping algorithm that determines the number of groups and return the
31 // group idx of the specified input_index
32 assert(input_size >= new_group_size);
33 int const minimum_output_group_size =
34 std::lround(input_size / new_group_size);
35 int const maximum_output_group_size = (input_size % new_group_size)
36 ? minimum_output_group_size + 1
37 : minimum_output_group_size;
38 return std::lround(input_index / maximum_output_group_size);
39};
40
41FileCommunicator getCommunicator(unsigned int const n_files)
42{
43 int num_procs;
44 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
45 int rank_id;
46 MPI_Comm_rank(MPI_COMM_WORLD, &rank_id);
47 int const file_group_id = getGroupIndex(rank_id, num_procs, n_files);
48 MPI_Comm new_communicator;
49 MPI_Comm_split(MPI_COMM_WORLD, file_group_id, rank_id, &new_communicator);
50 return FileCommunicator{std::move(new_communicator),
51 std::move(file_group_id), ""};
52}
53} // namespace MeshLib::IO
Dispatches HDF5 functions specific to execution platform (w/o MPI). There are multiple implementation...
Assigns to each MPI communicator an output file name by attribute color There are multiple implementa...
int getGroupIndex(int const input_index, int const input_size, int const new_group_size)
FileCommunicator getCommunicator(unsigned int const n_files)