Skip to content

Commit 1dde37b

Browse files
committed
Add checks to chooseProcessorSplit function in boutmesh.cxx
Setting NXPE or NYPE would not trigger the checks of number of points / number of specified processes. Also added tests to it and modified previous tests to work.
1 parent 7d28d67 commit 1dde37b

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

src/mesh/impls/bout/boutmesh.cxx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace bout {
156156
CheckMeshResult checkBoutMeshYDecomposition(int num_y_processors, int ny,
157157
int num_y_guards, int jyseps1_1,
158158
int jyseps2_1, int jyseps1_2, int jyseps2_2,
159-
int ny_inner) {
159+
int ny_inner) {
160160

161161
const int num_local_y_points = ny / num_y_processors;
162162

@@ -245,7 +245,11 @@ void BoutMesh::chooseProcessorSplit(Options& options) {
245245
_("Number of processors ({:d}) not divisible by NPs in x direction ({:d})\n"),
246246
NPES, NXPE);
247247
}
248-
248+
if (nx % NXPE != 0) {
249+
throw BoutException(
250+
_("Number of x points ({:d}) not divisible by NPs in x direction ({:d})\n"), nx,
251+
NXPE);
252+
}
249253
NYPE = NPES / NXPE;
250254
} else {
251255
// NXPE not set, but NYPE is
@@ -258,7 +262,11 @@ void BoutMesh::chooseProcessorSplit(Options& options) {
258262
_("Number of processors ({:d}) not divisible by NPs in y direction ({:d})\n"),
259263
NPES, NYPE);
260264
}
261-
265+
if (ny % NYPE != 0) {
266+
throw BoutException(
267+
_("Number of y points ({:d}) not divisible by NPs in y direction ({:d})\n"), nx,
268+
NXPE);
269+
}
262270
NXPE = NPES / NYPE;
263271
}
264272

tests/unit/mesh/test_boutmesh.cxx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,26 +464,62 @@ TEST_P(BadBoutMeshDecompositionTest, BadSingleCoreYDecomposition) {
464464
EXPECT_THAT(result.reason, HasSubstr(params.expected_message));
465465
}
466466

467-
TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPE) {
467+
TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPETooManyXProcs) {
468468
Options options{{"NXPE", 3}};
469469

470470
BoutMeshExposer mesh(1, 24, 1, 1, 1, 8);
471471

472472
EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException);
473473
}
474474

475-
TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPE) {
475+
TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPETooManyYProcs) {
476476
Options options{{"NYPE", 7}};
477477

478478
BoutMeshExposer mesh(1, 24, 1, 1, 1, 8);
479479

480480
EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException);
481481
}
482482

483+
TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisibleByNYPE) {
484+
WithQuietOutput info{output_info};
485+
Options options{{"NXPE", 5}};
486+
487+
BoutMeshExposer mesh(5, 24, 1, 1, 1, 8);
488+
489+
EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException);
490+
}
491+
492+
TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPENotDivisibleByNYPE) {
493+
WithQuietOutput info{output_info};
494+
Options options{{"NYPE", 5}};
495+
496+
BoutMeshExposer mesh(5, 5, 1, 1, 1, 8);
497+
498+
EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException);
499+
}
500+
501+
TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisibleByNYPE) {
502+
WithQuietOutput info{output_info};
503+
Options options{{"NXPE", 5}};
504+
505+
BoutMeshExposer mesh(5, 24, 1, 1, 1, 8);
506+
507+
EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException);
508+
}
509+
510+
TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPENotDivisibleByNYPE) {
511+
WithQuietOutput info{output_info};
512+
Options options{{"NYPE", 5}};
513+
514+
BoutMeshExposer mesh(5, 5, 1, 1, 1, 8);
515+
516+
EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException);
517+
}
518+
483519
TEST_F(BoutMeshTest, ChooseProcessorSplitNXPE) {
484520
Options options{{"NXPE", 4}};
485521

486-
BoutMeshExposer mesh(1, 24, 1, 1, 1, 8);
522+
BoutMeshExposer mesh(4, 24, 1, 1, 1, 8);
487523

488524
EXPECT_NO_THROW(mesh.chooseProcessorSplit(options));
489525

0 commit comments

Comments
 (0)