OGS
partition.cpp
Go to the documentation of this file.
1
14#include "../partition.h"
15
16#include <mpi.h>
17
18#include <numeric>
19
20#include "BaseLib/Algorithm.h"
21#include "BaseLib/Logging.h"
22#include "BaseLib/MPI.h"
24#include "getCommunicator.h"
25
26namespace MeshLib::IO
27{
29{
30 int mpi_rank;
31 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
32 return mpi_rank == 0;
33}
34
35PartitionInfo getPartitionInfo(std::size_t const size,
36 unsigned int const n_files)
37{
39
40 std::vector<std::size_t> const partition_sizes =
41 BaseLib::MPI::allgather(size, mpi);
42
43 // the first partition's offset is zero, offsets for subsequent
44 // partitions are the accumulated sum of all preceding size.
45 std::vector<std::size_t> const partition_offsets =
46 BaseLib::sizesToOffsets(partition_sizes);
47
48 // chunked
49 std::size_t longest_partition =
50 *max_element(partition_sizes.begin(), partition_sizes.end());
51
52 // local_offset, local_length, longest_local_length, global_length
53 return {partition_offsets[mpi.rank], size, longest_partition,
54 partition_offsets.back()};
55}
56} // 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...
static std::vector< T > allgather(T const &value, Mpi const &mpi)
Definition MPI.h:100
std::vector< ranges::range_value_t< R > > sizesToOffsets(R const &sizes)
Definition Algorithm.h:283
FileCommunicator getCommunicator(unsigned int const n_files)
PartitionInfo getPartitionInfo(std::size_t const size, unsigned int const n_files)
Definition partition.cpp:35
bool isFileManager()
Definition partition.cpp:28
Dispatches functions specific to execution platform (w/o MPI)