OGS
mpi/partition.cpp
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2
// SPDX-License-Identifier: BSD-3-Clause
3
4
#include "
../partition.h
"
5
6
#include <mpi.h>
7
8
#include <numeric>
9
10
#include "
BaseLib/Algorithm.h
"
11
#include "
BaseLib/Logging.h
"
12
#include "
BaseLib/MPI.h
"
13
#include "
MeshLib/IO/XDMF/fileIO.h
"
14
#include "
getCommunicator.h
"
15
16
namespace
MeshLib::IO
17
{
18
bool
isFileManager
()
19
{
20
int
mpi_rank;
21
MPI_Comm_rank(
BaseLib::MPI::OGS_COMM_WORLD
, &mpi_rank);
22
return
mpi_rank == 0;
23
}
24
25
PartitionInfo
getPartitionInfo
(std::size_t
const
size,
26
unsigned
int
const
n_files)
27
{
28
BaseLib::MPI::Mpi
const
mpi{
getCommunicator
(n_files).
mpi_communicator
};
29
30
std::vector<std::size_t>
const
partition_sizes =
31
BaseLib::MPI::allgather
(size, mpi);
32
33
// the first partition's offset is zero, offsets for subsequent
34
// partitions are the accumulated sum of all preceding size.
35
std::vector<std::size_t>
const
partition_offsets =
36
BaseLib::sizesToOffsets
(partition_sizes);
37
38
// chunked
39
std::size_t longest_partition =
40
*max_element(partition_sizes.begin(), partition_sizes.end());
41
42
// local_offset, local_length, longest_local_length, global_length
43
return
{partition_offsets[mpi.
rank
], size, longest_partition,
44
partition_offsets.back()};
45
}
46
}
// namespace MeshLib::IO
Algorithm.h
Logging.h
MPI.h
fileIO.h
getCommunicator.h
BaseLib::MPI::OGS_COMM_WORLD
MPI_Comm OGS_COMM_WORLD
Definition
MPI.cpp:9
BaseLib::MPI::allgather
static std::vector< T > allgather(T const &value, Mpi const &mpi)
Definition
MPI.h:98
BaseLib::sizesToOffsets
std::vector< ranges::range_value_t< R > > sizesToOffsets(R const &sizes)
Definition
Algorithm.h:276
MeshLib::IO
Definition
MeshIO.cpp:262
MeshLib::IO::getCommunicator
FileCommunicator getCommunicator(unsigned int const n_files)
Definition
getCommunicator.cpp:32
MeshLib::IO::getPartitionInfo
PartitionInfo getPartitionInfo(std::size_t const size, unsigned int const n_files)
Definition
mpi/partition.cpp:25
MeshLib::IO::isFileManager
bool isFileManager()
Definition
mpi/partition.cpp:18
partition.h
BaseLib::MPI::Mpi
Definition
MPI.h:44
BaseLib::MPI::Mpi::rank
int rank
Definition
MPI.h:60
MeshLib::IO::FileCommunicator::mpi_communicator
MPI_Comm mpi_communicator
Definition
getCommunicator.h:14
MeshLib::IO::PartitionInfo
Definition
partition.h:11
MeshLib
IO
XDMF
mpi
partition.cpp
Generated by
1.14.0