Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty grid partitions #606

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions opm/grid/CpGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,11 @@ namespace Dune
OPM_THROW(std::logic_error, "No distributed view available in grid");
current_view_data_=distributed_data_[0].get();
}

void setAllowEmptyPartitions(bool allow)
{
allowEmptyPartitions_ = allow;
}
//@}

#if HAVE_MPI
Expand Down Expand Up @@ -1629,6 +1634,10 @@ namespace Dune
*/
std::map<std::string,std::string> zoltanParams;

/**
* @brief Allow empty partitions
*/
bool allowEmptyPartitions_ = false;
}; // end Class CpGrid


Expand Down
27 changes: 15 additions & 12 deletions opm/grid/cpgrid/CpGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,24 @@ CpGrid::scatterGrid(EdgeWeightMethod method,
procsWithZeroCells = cc.sum(procsWithZeroCells);

if (procsWithZeroCells) {
std::string msg = "At least one process has zero cells. Aborting. \n"
" Try decreasing the imbalance tolerance for zoltan with \n"
" --zoltan-imbalance-tolerance. The current value is "
+ std::to_string(zoltanImbalanceTol);
if (cc.rank()==0)
{
OPM_THROW(std::runtime_error, msg );
}
else
{
OPM_THROW_NOLOG(std::runtime_error, msg);
if (allowEmptyPartitions_) {
Opm::OpmLog::warning("At least one process has zero cells. Continuing as requested.");
} else {
std::string msg = "At least one process has zero cells. Aborting. \n"
" Try decreasing the imbalance tolerance for zoltan with \n"
" --zoltan-imbalance-tolerance. The current value is "
+ std::to_string(zoltanImbalanceTol);
if (cc.rank()==0)
{
OPM_THROW(std::runtime_error, msg );
}
else
{
OPM_THROW_NOLOG(std::runtime_error, msg);
}
}
}


// distributed_data should be empty at this point.
distributed_data_.push_back(std::make_shared<cpgrid::CpGridData>(cc));
distributed_data_[0]->setUniqueBoundaryIds(data_[0]->uniqueBoundaryIds());
Expand Down
40 changes: 39 additions & 1 deletion opm/grid/utility/RegionMapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <unordered_map>
#include <vector>

#if HAVE_MPI
#include <mpi.h>
#endif

namespace Opm
{

Expand All @@ -47,12 +51,29 @@ namespace Opm
*
* \param[in] reg Forward region mapping, restricted to
* active cells only.
* \param[in] comm Global communicator to base region communicator on.
*/
explicit
RegionMapping(const Region& reg)
RegionMapping(const Region& reg
#if HAVE_MPI
, MPI_Comm comm = MPI_COMM_WORLD
#endif
)
: reg_(reg)
{
#if HAVE_MPI
rev_.init(reg_, comm);
#else
rev_.init(reg_);
#endif
}

~RegionMapping()
{
#if HAVE_MPI
if (rev_.comm_ != MPI_COMM_NULL)
MPI_Comm_free(&rev_.comm_);
#endif
}

/**
Expand Down Expand Up @@ -113,6 +134,10 @@ namespace Opm
rev_.c.begin() + rev_.p[i + 1]);
}

#if HAVE_MPI
MPI_Comm comm() const { return rev_.comm_; }
#endif

private:
/**
* Copy of forward region mapping (cell-to-region).
Expand All @@ -131,12 +156,21 @@ namespace Opm
std::vector<Pos> p; /**< Region start pointers */
std::vector<CellId> c; /**< Region cells */

#if HAVE_MPI
MPI_Comm comm_;
#endif

/**
* Compute reverse mapping. Standard linear insertion
* sort algorithm.
*/
#if HAVE_MPI
void
init(const Region& reg, MPI_Comm comm)
#else
void
init(const Region& reg)
#endif
{
binid.clear();
for (const auto& r : reg) {
Expand All @@ -154,6 +188,10 @@ namespace Opm
id.second = n++;
}
}
#if HAVE_MPI
MPI_Comm_split(comm, reg.empty() ? MPI_UNDEFINED : 1,
0, &comm_);
#endif

for (decltype(p.size()) i = 1, sz = p.size(); i < sz; ++i) {
p[0] += p[i];
Expand Down