From 1048d15774df037689417c328f503594085f2a37 Mon Sep 17 00:00:00 2001 From: wearysebas Date: Thu, 22 Jan 2026 15:58:33 +0000 Subject: [PATCH 1/2] 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. --- src/mesh/impls/bout/boutmesh.cxx | 18 +++++++++---- tests/unit/mesh/test_boutmesh.cxx | 42 ++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/mesh/impls/bout/boutmesh.cxx b/src/mesh/impls/bout/boutmesh.cxx index ea1b6a41b2..e701ba849f 100644 --- a/src/mesh/impls/bout/boutmesh.cxx +++ b/src/mesh/impls/bout/boutmesh.cxx @@ -268,7 +268,11 @@ void BoutMesh::chooseProcessorSplit(Options& options) { _f("Number of processors ({:d}) not divisible by NPs in x direction ({:d})\n"), NPES, NXPE); } - + if (nx % NXPE != 0) { + throw BoutException( + _("Number of x points ({:d}) not divisible by NPs in x direction ({:d})\n"), nx, + NXPE); + } NYPE = NPES / NXPE; } else { // NXPE not set, but NYPE is @@ -281,7 +285,11 @@ void BoutMesh::chooseProcessorSplit(Options& options) { _f("Number of processors ({:d}) not divisible by NPs in y direction ({:d})\n"), NPES, NYPE); } - + if (ny % NYPE != 0) { + throw BoutException( + _("Number of y points ({:d}) not divisible by NPs in y direction ({:d})\n"), nx, + NXPE); + } NXPE = NPES / NYPE; } @@ -2218,9 +2226,9 @@ void BoutMesh::topology() { } for (int i = 0; i < limiter_count; ++i) { - int const yind = limiter_yinds[i]; - int const xstart = limiter_xstarts[i]; - int const xend = limiter_xends[i]; + const int yind = limiter_yinds[i]; + const int xstart = limiter_xstarts[i]; + const int xend = limiter_xends[i]; output_info.write("Adding a limiter between y={} and {}. X indices {} to {}\n", yind, yind + 1, xstart, xend); add_target(yind, xstart, xend); diff --git a/tests/unit/mesh/test_boutmesh.cxx b/tests/unit/mesh/test_boutmesh.cxx index 8a446a742b..45217bfbe0 100644 --- a/tests/unit/mesh/test_boutmesh.cxx +++ b/tests/unit/mesh/test_boutmesh.cxx @@ -464,7 +464,7 @@ TEST_P(BadBoutMeshDecompositionTest, BadSingleCoreYDecomposition) { EXPECT_THAT(result.reason, HasSubstr(params.expected_message)); } -TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPE) { +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPETooManyXProcs) { Options options{{"NXPE", 3}}; BoutMeshExposer mesh(1, 24, 1, 1, 1, 8); @@ -472,7 +472,7 @@ TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPE) { EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); } -TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPE) { +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPETooManyYProcs) { Options options{{"NYPE", 7}}; BoutMeshExposer mesh(1, 24, 1, 1, 1, 8); @@ -480,10 +480,46 @@ TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPE) { EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); } +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisibleByNYPE) { + WithQuietOutput info{output_info}; + Options options{{"NXPE", 5}}; + + BoutMeshExposer mesh(5, 24, 1, 1, 1, 8); + + EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); +} + +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPENotDivisibleByNYPE) { + WithQuietOutput info{output_info}; + Options options{{"NYPE", 5}}; + + BoutMeshExposer mesh(5, 5, 1, 1, 1, 8); + + EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); +} + +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisibleByNYPE) { + WithQuietOutput info{output_info}; + Options options{{"NXPE", 5}}; + + BoutMeshExposer mesh(5, 24, 1, 1, 1, 8); + + EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); +} + +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPENotDivisibleByNYPE) { + WithQuietOutput info{output_info}; + Options options{{"NYPE", 5}}; + + BoutMeshExposer mesh(5, 5, 1, 1, 1, 8); + + EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); +} + TEST_F(BoutMeshTest, ChooseProcessorSplitNXPE) { Options options{{"NXPE", 4}}; - BoutMeshExposer mesh(1, 24, 1, 1, 1, 8); + BoutMeshExposer mesh(4, 24, 1, 1, 1, 8); EXPECT_NO_THROW(mesh.chooseProcessorSplit(options)); From 35c30cf5fd81b607a680feb04719844294132a99 Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 13 Mar 2026 13:50:07 +0100 Subject: [PATCH 2/2] Fix test names --- tests/unit/mesh/test_boutmesh.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/mesh/test_boutmesh.cxx b/tests/unit/mesh/test_boutmesh.cxx index 45217bfbe0..a23b432f70 100644 --- a/tests/unit/mesh/test_boutmesh.cxx +++ b/tests/unit/mesh/test_boutmesh.cxx @@ -480,7 +480,7 @@ TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPETooManyYProcs) { EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); } -TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisibleByNYPE) { +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisible_0) { WithQuietOutput info{output_info}; Options options{{"NXPE", 5}}; @@ -489,7 +489,7 @@ TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisibleByNYPE) { EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); } -TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPENotDivisibleByNYPE) { +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPENotDivisible_0) { WithQuietOutput info{output_info}; Options options{{"NYPE", 5}}; @@ -498,7 +498,7 @@ TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPENotDivisibleByNYPE) { EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); } -TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisibleByNYPE) { +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisible_1) { WithQuietOutput info{output_info}; Options options{{"NXPE", 5}}; @@ -507,7 +507,7 @@ TEST_F(BoutMeshTest, ChooseProcessorSplitBadNXPENotDivisibleByNYPE) { EXPECT_THROW(mesh.chooseProcessorSplit(options), BoutException); } -TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPENotDivisibleByNYPE) { +TEST_F(BoutMeshTest, ChooseProcessorSplitBadNYPENotDivisible_1) { WithQuietOutput info{output_info}; Options options{{"NYPE", 5}};