Skip to content

Commit 182975e

Browse files
authored
Merge pull request #3209 from boutproject/remove-some-static-locals
Remove `static` local variables from `Mesh::hasBndry*Y`
2 parents a8ce570 + d0600ba commit 182975e

File tree

5 files changed

+23
-30
lines changed

5 files changed

+23
-30
lines changed

include/bout/mesh.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,11 @@ public:
474474

475475
/// Is there a boundary on the lower guard cells in Y
476476
/// on any processor along the X direction?
477-
bool hasBndryLowerY();
477+
virtual bool hasBndryLowerY() const = 0;
478478

479479
/// Is there a boundary on the upper guard cells in Y
480480
/// on any processor along the X direction?
481-
bool hasBndryUpperY();
481+
virtual bool hasBndryUpperY() const = 0;
482482
// Boundary regions
483483

484484
/// Return a vector containing all the boundary regions on this processor

src/mesh/impls/bout/boutmesh.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,20 @@ int BoutMesh::load() {
607607
// Add boundary regions
608608
addBoundaryRegions();
609609

610+
// Set cached values
611+
{
612+
int mybndry = static_cast<int>(!(iterateBndryLowerY().isDone()));
613+
int allbndry = 0;
614+
mpi->MPI_Allreduce(&mybndry, &allbndry, 1, MPI_INT, MPI_BOR, getXcomm(yend));
615+
has_boundary_lower_y = static_cast<bool>(allbndry);
616+
}
617+
{
618+
int mybndry = static_cast<int>(!(iterateBndryUpperY().isDone()));
619+
int allbndry = 0;
620+
mpi->MPI_Allreduce(&mybndry, &allbndry, 1, MPI_INT, MPI_BOR, getXcomm(ystart));
621+
has_boundary_upper_y = static_cast<bool>(allbndry);
622+
}
623+
610624
// Initialize default coordinates
611625
getCoordinates();
612626

src/mesh/impls/bout/boutmesh.hxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ public:
156156
RangeIterator iterateBndryUpperInnerY() const override;
157157
RangeIterator iterateBndryUpperOuterY() const override;
158158

159+
bool hasBndryLowerY() const override { return has_boundary_lower_y; }
160+
bool hasBndryUpperY() const override { return has_boundary_upper_y; }
161+
159162
// Boundary regions
160163
std::vector<BoundaryRegion*> getBoundaries() override;
161164
std::vector<std::shared_ptr<BoundaryRegionPar>>
@@ -400,6 +403,8 @@ private:
400403
static_cast<int>(BoundaryParType::SIZE)>
401404
par_boundary; // Vector of parallel boundary regions
402405

406+
bool has_boundary_lower_y{false};
407+
bool has_boundary_upper_y{false};
403408
//////////////////////////////////////////////////
404409
// Communications
405410

src/mesh/mesh.cxx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -408,34 +408,6 @@ int Mesh::ySize(int jx) const {
408408
return all;
409409
}
410410

411-
bool Mesh::hasBndryLowerY() {
412-
static bool calc = false, answer;
413-
if (calc) {
414-
return answer; // Already calculated
415-
}
416-
417-
int mybndry = static_cast<int>(!(iterateBndryLowerY().isDone()));
418-
int allbndry;
419-
mpi->MPI_Allreduce(&mybndry, &allbndry, 1, MPI_INT, MPI_BOR, getXcomm(yend));
420-
answer = static_cast<bool>(allbndry);
421-
calc = true;
422-
return answer;
423-
}
424-
425-
bool Mesh::hasBndryUpperY() {
426-
static bool calc = false, answer;
427-
if (calc) {
428-
return answer; // Already calculated
429-
}
430-
431-
int mybndry = static_cast<int>(!(iterateBndryUpperY().isDone()));
432-
int allbndry;
433-
mpi->MPI_Allreduce(&mybndry, &allbndry, 1, MPI_INT, MPI_BOR, getXcomm(ystart));
434-
answer = static_cast<bool>(allbndry);
435-
calc = true;
436-
return answer;
437-
}
438-
439411
int Mesh::localSize3D() {
440412
if (localNumCells3D < 0) {
441413
const int xs = firstX() ? xstart - 1 : xstart;

tests/unit/fake_mesh.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ public:
154154
RangeIterator iterateBndryLowerInnerY() const override { return RangeIterator(); }
155155
RangeIterator iterateBndryUpperOuterY() const override { return RangeIterator(); }
156156
RangeIterator iterateBndryUpperInnerY() const override { return RangeIterator(); }
157+
bool hasBndryLowerY() const override { return false; }
158+
bool hasBndryUpperY() const override { return false; }
157159
void addBoundary(BoundaryRegion* region) override { boundaries.push_back(region); }
158160
std::vector<BoundaryRegion*> getBoundaries() override { return boundaries; }
159161
std::vector<std::shared_ptr<BoundaryRegionPar>>

0 commit comments

Comments
 (0)