Skip to content

Commit adfe6f1

Browse files
authored
Merge pull request #721 from cb-geo/hotfix/repartition-resume
💻 Add a repartition flag to resume using manual h4 files
2 parents 087bd86 + 2531ed9 commit adfe6f1

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

include/mesh.tcc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,10 @@ template <unsigned Tdim>
954954
void mpm::Mesh<Tdim>::resume_domain_cell_ranks() {
955955
// Get MPI rank
956956
int mpi_rank = 0;
957+
int mpi_size = 0;
957958
#ifdef USE_MPI
958959
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
960+
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
959961
const unsigned rank_max = std::numeric_limits<unsigned>::max();
960962
const unsigned ncells = this->ncells();
961963
// Vector of cell ranks
@@ -980,6 +982,13 @@ void mpm::Mesh<Tdim>::resume_domain_cell_ranks() {
980982
unsigned j = 0;
981983
for (auto citr = cells_.cbegin(); citr != cells_.cend(); ++citr) {
982984
int recv_rank = recv_ranks.at(j);
985+
if (recv_rank >= mpi_size) {
986+
console_->error(
987+
"Resuming analysis: Cell id {} has invalid MPI rank: {} larger than "
988+
"MPI size: {}",
989+
(*citr)->id(), recv_rank, mpi_size);
990+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
991+
}
983992
(*citr)->rank(recv_rank);
984993
++j;
985994
}

include/solvers/mpm_explicit.tcc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ bool mpm::MPMExplicit<Tdim>::solve() {
6262
if (analysis_.find("resume") != analysis_.end())
6363
resume = analysis_["resume"]["resume"].template get<bool>();
6464

65+
// Enable repartitioning if resume is done with particles generated outside
66+
// the MPM code.
67+
bool repartition = false;
68+
if (analysis_.find("resume") != analysis_.end() &&
69+
analysis_["resume"].find("repartition") != analysis_["resume"].end())
70+
repartition = analysis_["resume"]["repartition"].template get<bool>();
71+
6572
// Pressure smoothing
6673
pressure_smoothing_ = io_->analysis_bool("pressure_smoothing");
6774

@@ -85,18 +92,22 @@ bool mpm::MPMExplicit<Tdim>::solve() {
8592
mesh_->iterate_over_particles(std::bind(
8693
&mpm::ParticleBase<Tdim>::compute_mass, std::placeholders::_1));
8794

95+
bool initial_step = (resume == true) ? false : true;
8896
// Check point resume
8997
if (resume) {
9098
this->checkpoint_resume();
91-
mesh_->resume_domain_cell_ranks();
99+
if (repartition) {
100+
this->mpi_domain_decompose(initial_step);
101+
} else {
102+
mesh_->resume_domain_cell_ranks();
92103
#ifdef USE_MPI
93104
#ifdef USE_GRAPH_PARTITIONING
94-
MPI_Barrier(MPI_COMM_WORLD);
105+
MPI_Barrier(MPI_COMM_WORLD);
95106
#endif
96107
#endif
108+
}
97109
} else {
98110
// Domain decompose
99-
bool initial_step = (resume == true) ? false : true;
100111
this->mpi_domain_decompose(initial_step);
101112
}
102113

0 commit comments

Comments
 (0)