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/Logging.h"
22#include "getCommunicator.h"
23
24namespace MeshLib::IO
25{
27{
28 int mpi_rank;
29 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
30 return mpi_rank == 0;
31}
32
33PartitionInfo getPartitionInfo(std::size_t const size,
34 unsigned int const n_files)
35{
36 MPI_Comm const mpi_comm = getCommunicator(n_files).mpi_communicator;
37 int mpi_size;
38 int mpi_rank;
39 MPI_Comm_size(mpi_comm, &mpi_size);
40 MPI_Comm_rank(mpi_comm, &mpi_rank);
41
42 std::vector<std::size_t> partition_sizes;
43 partition_sizes.resize(mpi_size);
44
45 MPI_Allgather(&size,
46 1,
47 MPI_UNSIGNED_LONG,
48 partition_sizes.data(),
49 1,
50 MPI_UNSIGNED_LONG,
51 mpi_comm);
52
53 // the first partition's offset is zero, offsets for subsequent
54 // partitions are the accumulated sum of all preceding size (excluding
55 // own size)
56 std::vector<std::size_t> partition_offsets(1, 0);
57 std::partial_sum(partition_sizes.begin(),
58 partition_sizes.end(),
59 back_inserter(partition_offsets));
60
61 // chunked
62 std::size_t longest_partition =
63 *max_element(partition_sizes.begin(), partition_sizes.end());
64
65 // local_offset, local_length, longest_local_length, global_length
66 return {partition_offsets[mpi_rank], size, longest_partition,
67 partition_offsets.back()};
68}
69} // 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...
FileCommunicator getCommunicator(unsigned int const n_files)
PartitionInfo getPartitionInfo(std::size_t const size, unsigned int const n_files)
Definition partition.cpp:33
bool isFileManager()
Definition partition.cpp:26
Dispatches functions specific to execution platform (w/o MPI)