mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #5210 from akva2/move_parallel_split_to_cpp
MPIPartitionFromFile: move implementation to generic translation unit
This commit is contained in:
@@ -38,86 +38,12 @@
|
|||||||
#include <opm/models/blackoil/blackoilproperties.hh>
|
#include <opm/models/blackoil/blackoilproperties.hh>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <filesystem>
|
|
||||||
#include <fstream>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iterator>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#if HAVE_MPI
|
|
||||||
|
|
||||||
namespace Opm { namespace details {
|
|
||||||
class MPIPartitionFromFile
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit MPIPartitionFromFile(const std::filesystem::path& partitionFile)
|
|
||||||
: partitionFile_(partitionFile)
|
|
||||||
{}
|
|
||||||
|
|
||||||
std::vector<int> operator()(const Dune::CpGrid& grid) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::filesystem::path partitionFile_{};
|
|
||||||
};
|
|
||||||
|
|
||||||
inline std::vector<int>
|
|
||||||
MPIPartitionFromFile::operator()(const Dune::CpGrid& grid) const
|
|
||||||
{
|
|
||||||
std::ifstream pfile { this->partitionFile_ };
|
|
||||||
|
|
||||||
auto partition = std::vector<int> {
|
|
||||||
std::istream_iterator<int> { pfile },
|
|
||||||
std::istream_iterator<int> {}
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto nc =
|
|
||||||
static_cast<std::vector<int>::size_type>(grid.size(0));
|
|
||||||
|
|
||||||
if (partition.size() == nc) {
|
|
||||||
// Input is one process ID for each active cell
|
|
||||||
return partition;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (partition.size() == 3 * nc) {
|
|
||||||
// Partition file is of the form
|
|
||||||
//
|
|
||||||
// Process_ID Cartesian_Idx NLDD_Domain
|
|
||||||
//
|
|
||||||
// with one row for each active cell. Select first column.
|
|
||||||
auto g2l = std::unordered_map<int, int>{};
|
|
||||||
auto locCell = 0;
|
|
||||||
for (const auto& globCell : grid.globalCell()) {
|
|
||||||
g2l.insert_or_assign(globCell, locCell++);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto filtered_partition = std::vector<int>(nc);
|
|
||||||
for (auto c = 0*nc; c < nc; ++c) {
|
|
||||||
auto pos = g2l.find(partition[3*c + 1]);
|
|
||||||
if (pos != g2l.end()) {
|
|
||||||
filtered_partition[pos->second] = partition[3*c + 0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return filtered_partition;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw std::invalid_argument {
|
|
||||||
fmt::format("Partition file '{}' with {} values does "
|
|
||||||
"not match CpGrid instance with {} cells",
|
|
||||||
this->partitionFile_.generic_string(),
|
|
||||||
partition.size(), nc)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}} // namespace Opm::details
|
|
||||||
|
|
||||||
#endif // HAVE_MPI
|
|
||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
template <class TypeTag>
|
template <class TypeTag>
|
||||||
class EclCpGridVanguard;
|
class EclCpGridVanguard;
|
||||||
|
|||||||
@@ -52,20 +52,74 @@
|
|||||||
#include <ebos/femcpgridcompat.hh>
|
#include <ebos/femcpgridcompat.hh>
|
||||||
#endif //HAVE_DUNE_FEM
|
#endif //HAVE_DUNE_FEM
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iterator>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
|
|
||||||
|
#if HAVE_MPI
|
||||||
|
namespace details {
|
||||||
|
|
||||||
|
std::vector<int>
|
||||||
|
MPIPartitionFromFile::operator()(const Dune::CpGrid& grid) const
|
||||||
|
{
|
||||||
|
std::ifstream pfile { this->partitionFile_ };
|
||||||
|
|
||||||
|
auto partition = std::vector<int> {
|
||||||
|
std::istream_iterator<int> { pfile },
|
||||||
|
std::istream_iterator<int> {}
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto nc =
|
||||||
|
static_cast<std::vector<int>::size_type>(grid.size(0));
|
||||||
|
|
||||||
|
if (partition.size() == nc) {
|
||||||
|
// Input is one process ID for each active cell
|
||||||
|
return partition;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (partition.size() == 3 * nc) {
|
||||||
|
// Partition file is of the form
|
||||||
|
//
|
||||||
|
// Process_ID Cartesian_Idx NLDD_Domain
|
||||||
|
//
|
||||||
|
// with one row for each active cell. Select first column.
|
||||||
|
auto g2l = std::unordered_map<int, int>{};
|
||||||
|
auto locCell = 0;
|
||||||
|
for (const auto& globCell : grid.globalCell()) {
|
||||||
|
g2l.insert_or_assign(globCell, locCell++);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto filtered_partition = std::vector<int>(nc);
|
||||||
|
for (auto c = 0*nc; c < nc; ++c) {
|
||||||
|
auto pos = g2l.find(partition[3*c + 1]);
|
||||||
|
if (pos != g2l.end()) {
|
||||||
|
filtered_partition[pos->second] = partition[3*c + 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered_partition;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::invalid_argument {
|
||||||
|
fmt::format("Partition file '{}' with {} values does "
|
||||||
|
"not match CpGrid instance with {} cells",
|
||||||
|
this->partitionFile_.generic_string(),
|
||||||
|
partition.size(), nc)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::optional<std::function<std::vector<int> (const Dune::CpGrid&)>> externalLoadBalancer;
|
std::optional<std::function<std::vector<int> (const Dune::CpGrid&)>> externalLoadBalancer;
|
||||||
|
|
||||||
template<class ElementMapper, class GridView, class Scalar>
|
template<class ElementMapper, class GridView, class Scalar>
|
||||||
|
|||||||
@@ -36,6 +36,10 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#if HAVE_MPI
|
||||||
|
#include <filesystem>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
class EclipseState;
|
class EclipseState;
|
||||||
class Schedule;
|
class Schedule;
|
||||||
@@ -45,6 +49,25 @@ namespace Opm {
|
|||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
|
|
||||||
|
#if HAVE_MPI
|
||||||
|
namespace details {
|
||||||
|
class MPIPartitionFromFile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit MPIPartitionFromFile(const std::filesystem::path& partitionFile)
|
||||||
|
: partitionFile_(partitionFile)
|
||||||
|
{}
|
||||||
|
|
||||||
|
std::vector<int> operator()(const Dune::CpGrid& grid) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::filesystem::path partitionFile_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Opm::details
|
||||||
|
#endif // HAVE_MPI
|
||||||
|
|
||||||
|
|
||||||
/// \brief optional functor returning external load balancing information
|
/// \brief optional functor returning external load balancing information
|
||||||
///
|
///
|
||||||
/// If it is set then this will be used during loadbalance.
|
/// If it is set then this will be used during loadbalance.
|
||||||
|
|||||||
Reference in New Issue
Block a user