From 1dde37bd56437f2a5aac7e607b8ea9f5b4c084a6 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 | 14 ++++++++--- tests/unit/mesh/test_boutmesh.cxx | 42 ++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/mesh/impls/bout/boutmesh.cxx b/src/mesh/impls/bout/boutmesh.cxx index 4be01d4637..999120f48a 100644 --- a/src/mesh/impls/bout/boutmesh.cxx +++ b/src/mesh/impls/bout/boutmesh.cxx @@ -156,7 +156,7 @@ namespace bout { CheckMeshResult checkBoutMeshYDecomposition(int num_y_processors, int ny, int num_y_guards, int jyseps1_1, int jyseps2_1, int jyseps1_2, int jyseps2_2, - int ny_inner) { + int ny_inner) { const int num_local_y_points = ny / num_y_processors; @@ -245,7 +245,11 @@ void BoutMesh::chooseProcessorSplit(Options& options) { _("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 @@ -258,7 +262,11 @@ void BoutMesh::chooseProcessorSplit(Options& options) { _("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; } 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 3e54ba5977bf4b3f9cf37a57c3883c0cfa12c148 Mon Sep 17 00:00:00 2001 From: wearysebas <10083044+wearysebas@users.noreply.github.com> Date: Thu, 29 Jan 2026 14:38:05 +0000 Subject: [PATCH 2/2] Apply clang-format changes --- src/mesh/impls/bout/boutmesh.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/impls/bout/boutmesh.cxx b/src/mesh/impls/bout/boutmesh.cxx index 999120f48a..a0a4a611c4 100644 --- a/src/mesh/impls/bout/boutmesh.cxx +++ b/src/mesh/impls/bout/boutmesh.cxx @@ -156,7 +156,7 @@ namespace bout { CheckMeshResult checkBoutMeshYDecomposition(int num_y_processors, int ny, int num_y_guards, int jyseps1_1, int jyseps2_1, int jyseps1_2, int jyseps2_2, - int ny_inner) { + int ny_inner) { const int num_local_y_points = ny / num_y_processors;