From f4a60743c98f8509f9cb561e72b0aaa33c3fda0d Mon Sep 17 00:00:00 2001 From: Lars Bilke Date: Wed, 23 Oct 2024 09:57:31 +0200 Subject: [PATCH 1/7] [T] MPI tests in the testrunner are now part of the `tests`-target. Was part of `tests_mpi`-target which was never tested in CI. Tests will probably fail. --- Tests/CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 17b5c1ab576..1a450db81a8 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -193,12 +193,9 @@ if(OGS_USE_PETSC) set(TEST_FILTER_MPI --gtest_filter=-MPITest*) add_custom_target(tests mpirun ${MPIRUN_ARGS} -np 1 $ ${TESTRUNNER_ADDITIONAL_ARGUMENTS} ${TEST_FILTER_MPI} + COMMAND mpirun ${MPIRUN_ARGS} -np 3 $ --gtest_filter=MPITest* DEPENDS testrunner tests-cleanup ) - add_custom_target(tests_mpi - mpirun ${MPIRUN_ARGS} -np 3 $ --gtest_filter=MPITest* - DEPENDS testrunner - ) else() add_custom_target(tests $ ${TESTRUNNER_ADDITIONAL_ARGUMENTS} From b2a4a177126498cc2c8c5518871aac2cc34f23d8 Mon Sep 17 00:00:00 2001 From: Wenqing Wang Date: Thu, 17 Oct 2024 18:11:16 +0200 Subject: [PATCH 2/7] [PETScVector] Improved the funtion for getting element and added a warning to use it for creating local vectors. --- MathLib/LinAlg/PETSc/PETScVector.cpp | 69 +++++++++++++++------------- MathLib/LinAlg/PETSc/PETScVector.h | 21 ++++++--- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/MathLib/LinAlg/PETSc/PETScVector.cpp b/MathLib/LinAlg/PETSc/PETScVector.cpp index 552400efac4..bf12c6d3878 100644 --- a/MathLib/LinAlg/PETSc/PETScVector.cpp +++ b/MathLib/LinAlg/PETSc/PETScVector.cpp @@ -47,7 +47,8 @@ PETScVector::PETScVector(const PetscInt vec_size, const bool is_global_size) PETScVector::PETScVector(const PetscInt vec_size, const std::vector& ghost_ids, const bool is_global_size) - : size_ghosts_{static_cast(ghost_ids.size())}, has_ghost_id_{true} + : size_ghosts_{static_cast(ghost_ids.size())}, + created_with_ghost_id_{true} { PetscInt nghosts = static_cast(ghost_ids.size()); if (is_global_size) @@ -90,7 +91,7 @@ PETScVector::PETScVector(PETScVector&& other) size_{other.size_}, size_loc_{other.size_loc_}, size_ghosts_{other.size_ghosts_}, - has_ghost_id_{other.has_ghost_id_}, + created_with_ghost_id_{other.created_with_ghost_id_}, global_ids2local_ids_ghost_{other.global_ids2local_ids_ghost_} { } @@ -178,7 +179,14 @@ void PETScVector::getGlobalVector(std::vector& u) const void PETScVector::setLocalAccessibleVector() const { - copyValues(entry_array_); + if (created_with_ghost_id_) + { + copyValues(entry_array_); + return; + } + + entry_array_.resize(size_); + getGlobalVector(entry_array_); } void PETScVector::copyValues(std::vector& u) const @@ -192,49 +200,27 @@ void PETScVector::copyValues(std::vector& u) const PetscScalar PETScVector::get(const PetscInt idx) const { - if (!global_ids2local_ids_ghost_.empty()) + if (created_with_ghost_id_) { return entry_array_[getLocalIndex(idx)]; } - // Ghost entries, and its original index is 0. - const PetscInt id_p = (idx == -size_) ? 0 : std::abs(idx); - return entry_array_[id_p]; + return entry_array_[idx]; } std::vector PETScVector::get( std::vector const& indices) const { std::vector local_x(indices.size()); - // If VecGetValues can get values from different processors, - // use VecGetValues(v_, indices.size(), indices.data(), - // local_x.data()); - - if (!global_ids2local_ids_ghost_.empty()) - { - for (std::size_t i = 0; i < indices.size(); i++) - { - local_x[i] = entry_array_[getLocalIndex(indices[i])]; - } - } - else - { - for (std::size_t i = 0; i < indices.size(); i++) - { - // Ghost entries, and its original index is 0. - const IndexType id_p = - (indices[i] == -size_) ? 0 : std::abs(indices[i]); - local_x[i] = entry_array_[id_p]; - } - } - + std::transform(indices.begin(), indices.end(), local_x.begin(), + [this](IndexType index) { return get(index); }); return local_x; } PetscScalar* PETScVector::getLocalVector() const { PetscScalar* loc_array; - if (has_ghost_id_) + if (created_with_ghost_id_ && !global_ids2local_ids_ghost_.empty()) { VecGhostUpdateBegin(v_, INSERT_VALUES, SCATTER_FORWARD); VecGhostUpdateEnd(v_, INSERT_VALUES, SCATTER_FORWARD); @@ -253,6 +239,15 @@ PetscInt PETScVector::getLocalIndex(const PetscInt global_index) const { if (global_index >= 0) // non-ghost entry. { +#ifndef NDEBUG + if (global_index < start_rank_ || global_index >= end_rank_) + { + OGS_FATAL( + "The global index {:d} is out of the range `[`{:d}, {:d}`)` of " + "the current rank.", + global_index, start_rank_, end_rank_); + } +#endif return global_index - start_rank_; } @@ -260,12 +255,22 @@ PetscInt PETScVector::getLocalIndex(const PetscInt global_index) const // the size of the local vector: PetscInt real_global_index = (-global_index == size_) ? 0 : -global_index; +#ifndef NDEBUG + if (global_ids2local_ids_ghost_.find(real_global_index) == + global_ids2local_ids_ghost_.end() || + global_ids2local_ids_ghost_.empty()) + { + OGS_FATAL("The global index {:d} is not found as a ghost ID", + global_index); + } +#endif + return global_ids2local_ids_ghost_.at(real_global_index); } void PETScVector::restoreArray(PetscScalar* array) const { - if (has_ghost_id_) + if (created_with_ghost_id_ && !global_ids2local_ids_ghost_.empty()) { VecRestoreArray(v_loc_, &array); VecGhostRestoreLocalForm(v_, &v_loc_); @@ -305,7 +310,7 @@ void PETScVector::shallowCopy(const PETScVector& v) size_ = v.size_; size_loc_ = v.size_loc_; size_ghosts_ = v.size_ghosts_; - has_ghost_id_ = v.has_ghost_id_; + created_with_ghost_id_ = v.created_with_ghost_id_; global_ids2local_ids_ghost_ = v.global_ids2local_ids_ghost_; config(); diff --git a/MathLib/LinAlg/PETSc/PETScVector.h b/MathLib/LinAlg/PETSc/PETScVector.h index 89edeca41f7..ed2734878fb 100644 --- a/MathLib/LinAlg/PETSc/PETScVector.h +++ b/MathLib/LinAlg/PETSc/PETScVector.h @@ -28,6 +28,13 @@ namespace MathLib \class PETScVector \brief Wrapper class for PETSc vector + + It can be used to create a global vector for either parallel or serial + computing. + + Caution: Using it to create a local vector is not allowed, as the + created vector will be partitioned and distributed across all ranks + in an MPI environment. */ class PETScVector { @@ -246,15 +253,15 @@ class PETScVector PetscInt size_ghosts_ = 0; /// Flag to indicate whether the vector is created with ghost entry indices - bool has_ghost_id_ = false; + bool created_with_ghost_id_ = false; /*! - \brief Array containing the entries of the vector. - If the vector is created without given ghost IDs, the array - contains all entries of the global vector, v_. Otherwise it - only contains the entries of the global vector owned by the - current rank. - */ + \brief Array containing the entries of the vector. + If the vector is created without given ghost IDs, the array + contains all entries of the global vector, v_. Otherwise it + only contains the entries of the global vector owned by the + current rank. + */ mutable std::vector entry_array_; /// Map global indices of ghost entries to local indices From e5c02f325bdd425664181eec118f948ac5104ccc Mon Sep 17 00:00:00 2001 From: Wenqing Wang Date: Thu, 17 Oct 2024 18:11:16 +0200 Subject: [PATCH 3/7] [Tests] Fixed the test for PETScVector --- Tests/MathLib/TestGlobalVectorInterface.cpp | 188 +++++++++++--------- 1 file changed, 108 insertions(+), 80 deletions(-) diff --git a/Tests/MathLib/TestGlobalVectorInterface.cpp b/Tests/MathLib/TestGlobalVectorInterface.cpp index 755cf570945..dca634e5a22 100644 --- a/Tests/MathLib/TestGlobalVectorInterface.cpp +++ b/Tests/MathLib/TestGlobalVectorInterface.cpp @@ -15,6 +15,10 @@ #include +#include +#include +#include + #include "MathLib/LinAlg/LinAlg.h" #include "Tests/TestTools.h" @@ -78,115 +82,100 @@ void checkGlobalVectorInterface() } #ifdef USE_PETSC -template -void checkGlobalVectorInterfacePETSc() +double getEuclideanNorm(std::vector const& v) { - int msize; - MPI_Comm_size(PETSC_COMM_WORLD, &msize); + // Create a view that squares each element + auto squared_view = + v | std::views::transform([](double x) { return x * x; }); - ASSERT_EQ(3u, msize); - - // ----------------------------------------------------------------- - // PETSc determined partitioning - T_VECTOR x(16); + return std::sqrt( + std::accumulate(squared_view.begin(), squared_view.end(), 0.0)); +} - ASSERT_EQ(16u, x.size()); +template +void checkPETScVectorNoExplictGhostID(T_VECTOR& x, int const msize) +{ ASSERT_EQ(x.getRangeEnd() - x.getRangeBegin(), x.getLocalSize()); - const int r0 = x.getRangeBegin(); - // x.get(0) is expensive, only get local value. Use it for test purpose + // Note id0_rank may vary because of the PETSc determined partitioning + const int id0_rank = x.getRangeBegin(); x.setLocalAccessibleVector(); - ASSERT_EQ(.0, x.get(r0)); + ASSERT_EQ(.0, x.get(id0_rank)); - set(x, 10.); + set(x, 10.); // x:=10.0 + x.finalizeAssembly(); // Value of x is not copied to y const bool deep_copy = false; - T_VECTOR y(x, deep_copy); + T_VECTOR y(x, deep_copy); // y:= 0.0 y.setLocalAccessibleVector(); - ASSERT_EQ(0, y.get(r0)); + ASSERT_EQ(0, y.get(id0_rank)); - set(y, 10.0); + set(y, 10.0); // y:=10.0 y.setLocalAccessibleVector(); - ASSERT_EQ(10, y.get(r0)); + ASSERT_EQ(10, y.get(id0_rank)); // y += x - axpy(y, 1., x); + axpy(y, 1., x); // y = x + y := 20 y.setLocalAccessibleVector(); - ASSERT_EQ(20, y.get(r0)); - ASSERT_EQ(80., norm2(y)); + ASSERT_EQ(20, y.get(id0_rank)); // y -= x - axpy(y, -1., x); + axpy(y, -1., x); // y = y - x : = 10.0 y.setLocalAccessibleVector(); - ASSERT_EQ(10, y.get(r0)); - ASSERT_EQ(40., norm2(y)); + ASSERT_EQ(10, y.get(id0_rank)); + // Set values by each rank std::vector local_vec(2, 10.0); std::vector vec_pos(2); - vec_pos[0] = r0; // any index in [0,15] - vec_pos[1] = r0 + 1; // any index in [0,15] - + vec_pos[0] = id0_rank; + int const id0_pls_1 = id0_rank + 1; + // If id0_pls_1 is out of the current rank, set its negative value to + // vec_pos[1] to avoid adding value. + vec_pos[1] = id0_pls_1 < y.getRangeEnd() ? id0_pls_1 : -id0_pls_1; y.add(vec_pos, local_vec); + y.finalizeAssembly(); - double normy = std::sqrt(6.0 * 400 + 10.0 * 100); + int const x_size = x.size(); + // Count the number of the change elements of y by y.add + std::vector all_vec_pos(msize * 2); + MPI_Allgather(vec_pos.data(), 2, MPI_INT, all_vec_pos.data(), 2, MPI_INT, + PETSC_COMM_WORLD); - ASSERT_NEAR(0.0, normy - norm2(y), 1.e-10); + std::vector x_raw(x_size); + x.getGlobalVector(x_raw); + std::ranges::for_each( + all_vec_pos, + [&x_raw](int id) + { + if (id >= 0 && id < static_cast(x_raw.size())) + { + x_raw[id] = 20.0; + } + }); - std::vector x0(16); - double z[] = { - 2.0000000000000000e+01, 2.0000000000000000e+01, 1.0000000000000000e+01, - 1.0000000000000000e+01, 1.0000000000000000e+01, 1.0000000000000000e+01, - 2.0000000000000000e+01, 2.0000000000000000e+01, 1.0000000000000000e+01, - 1.0000000000000000e+01, 1.0000000000000000e+01, 2.0000000000000000e+01, - 2.0000000000000000e+01, 1.0000000000000000e+01, 1.0000000000000000e+01, - 1.0000000000000000e+01}; + std::vector y_raw(x_size); - y.getGlobalVector(x0); + y.getGlobalVector(y_raw); - ASSERT_ARRAY_NEAR(z, x0, 16, 1e-10); - - // ----------------------------------------------------------------- - // User determined partitioning - const bool is_global_size = false; - T_VECTOR x_fixed_p(2, is_global_size); + ASSERT_ARRAY_NEAR(x_raw, y_raw, x_size, 1e-10); - ASSERT_EQ(6u, x_fixed_p.size()); + ASSERT_NEAR(getEuclideanNorm(y_raw), norm2(y), 1e-10); - int mrank; - MPI_Comm_rank(PETSC_COMM_WORLD, &mrank); - - ASSERT_EQ(2 * mrank, x_fixed_p.getRangeBegin()); - ASSERT_EQ(2 * mrank + 2, x_fixed_p.getRangeEnd()); - - vec_pos[0] = 2 * mrank; - vec_pos[1] = vec_pos[0] + 1; - local_vec[0] = 1.; - local_vec[1] = 2.; - for (unsigned i = 0; i < 3; i++) - { - const unsigned j = 2 * i; - z[j] = 1.0; - z[j + 1] = 2.0; - } - x_fixed_p.set(vec_pos, local_vec); - x_fixed_p.getGlobalVector(x0); - - ASSERT_ARRAY_NEAR(z, x0, 6, 1e-10); - - // check local array - std::vector loc_v; - x_fixed_p.copyValues(loc_v); - z[0] = 1.0; - z[1] = 2.0; + // Deep copy + T_VECTOR x_deep_copied(y); + x_deep_copied.getGlobalVector(y_raw); + ASSERT_ARRAY_NEAR(x_raw, y_raw, x_size, 1e-10); +} - ASSERT_ARRAY_NEAR(z, loc_v, 2, 1e-10); +template +void checkPETScVectorExplictGhostID() +{ + int msize; + MPI_Comm_size(PETSC_COMM_WORLD, &msize); - // Deep copy - MathLib::finalizeVectorAssembly(x_fixed_p); - T_VECTOR x_deep_copied(x_fixed_p); - ASSERT_NEAR(sqrt(3.0 * 5), norm2(x_deep_copied), 1.e-10); + ASSERT_EQ(3u, msize); // ----------------------------------------------------------------- // Vector with ghost entries @@ -210,16 +199,24 @@ void checkGlobalVectorInterfacePETSc() The above ghost entry embedded vector is realized by the following test. */ + int mrank; + MPI_Comm_rank(PETSC_COMM_WORLD, &mrank); std::size_t local_vec_size = 4; if (mrank == 1) + { local_vec_size = 5; + } else if (mrank == 2) + { local_vec_size = 3; + } std::vector non_ghost_ids(local_vec_size); std::vector non_ghost_vals(local_vec_size); std::size_t nghosts = 3; - if (mrank) + if (mrank > 0) + { nghosts = 2; + } std::vector ghost_ids(nghosts); std::vector expected; switch (mrank) @@ -243,7 +240,7 @@ void checkGlobalVectorInterfacePETSc() expected = {9., 10., 11., 3., 5.}; break; } - T_VECTOR x_with_ghosts(local_vec_size, ghost_ids, is_global_size); + T_VECTOR x_with_ghosts(local_vec_size, ghost_ids, false /*is_global_size*/); x_with_ghosts.set(non_ghost_ids, non_ghost_vals); MathLib::finalizeVectorAssembly(x_with_ghosts); @@ -263,9 +260,40 @@ void checkGlobalVectorInterfacePETSc() //-------------------------------------------- #if defined(USE_PETSC) -TEST(MPITest_Math, CheckInterface_PETScVector) +TEST(MPITest_Math, PETScVectorPatitionedAutomatically) +{ + int msize; + MPI_Comm_size(PETSC_COMM_WORLD, &msize); + + MathLib::PETScVector x(16); // x:=0.0 + ASSERT_LE(msize, 16u); + + ASSERT_EQ(16u, x.size()); + checkPETScVectorNoExplictGhostID(x, msize); +} + +TEST(MPITest_Math, PETScVectorFixedPartition) +{ + int msize; + MPI_Comm_size(PETSC_COMM_WORLD, &msize); + + // Each partition has two elements. + int const num_elements_per_rank = 2; + MathLib::PETScVector x_fixed_p(num_elements_per_rank, + false /*is_global_size*/); + + ASSERT_EQ(num_elements_per_rank * msize, x_fixed_p.size()); + + int mrank; + MPI_Comm_rank(PETSC_COMM_WORLD, &mrank); + ASSERT_EQ(2 * mrank, x_fixed_p.getRangeBegin()); + ASSERT_EQ(2 * mrank + 2, x_fixed_p.getRangeEnd()); + checkPETScVectorNoExplictGhostID(x_fixed_p, msize); +} + +TEST(MPITest_Math, CheckPETScVectorExplictGhostID) { - checkGlobalVectorInterfacePETSc(); + checkPETScVectorExplictGhostID(); } #else TEST(Math, CheckInterface_EigenVector) From 259dffcad5a449e0cb6a587b1f167eef2a8d6373 Mon Sep 17 00:00:00 2001 From: Wenqing Wang Date: Tue, 5 Nov 2024 18:04:12 +0100 Subject: [PATCH 4/7] [UnitTest] Fixed the test for PETScMatrix --- Tests/MathLib/TestGlobalMatrixInterface.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Tests/MathLib/TestGlobalMatrixInterface.cpp b/Tests/MathLib/TestGlobalMatrixInterface.cpp index d266ef9e77a..075084ac1ef 100644 --- a/Tests/MathLib/TestGlobalMatrixInterface.cpp +++ b/Tests/MathLib/TestGlobalMatrixInterface.cpp @@ -79,7 +79,7 @@ void checkGlobalMatrixInterfaceMPI(T_MATRIX& m, T_VECTOR& v) ASSERT_EQ(m.getNumberOfColumns(), gathered_cols); // Add entries - Eigen::Matrix2d loc_m(2, 2); + Eigen::Matrix loc_m; loc_m(0, 0) = 1.; loc_m(0, 1) = 2.; loc_m(1, 0) = 3.; @@ -104,6 +104,7 @@ void checkGlobalMatrixInterfaceMPI(T_MATRIX& m, T_VECTOR& v) // Multiply by a vector // v = 1.; set(v, 1.); + const bool deep_copy = false; T_VECTOR y(v, deep_copy); matMult(m_c, v, y); @@ -112,14 +113,14 @@ void checkGlobalMatrixInterfaceMPI(T_MATRIX& m, T_VECTOR& v) // set a value m_c.set(2 * mrank, 2 * mrank, 5.0); - MathLib::finalizeMatrixAssembly(m); + MathLib::finalizeMatrixAssembly(m_c); // add a value m_c.add(2 * mrank + 1, 2 * mrank + 1, 5.0); MathLib::finalizeMatrixAssembly(m_c); matMult(m_c, v, y); - ASSERT_EQ(sqrt((3 * 7 * 7 + 3 * 12 * 12)), norm2(y)); + ASSERT_NEAR(sqrt((3 * 7 * 7 + 3 * 12 * 12)), norm2(y), 1e-12); } // Rectanglular matrix @@ -144,7 +145,7 @@ void checkGlobalRectangularMatrixInterfaceMPI(T_MATRIX& m, T_VECTOR& v) ASSERT_EQ(m.getNumberOfColumns(), gathered_cols); // Add entries - Eigen::Matrix loc_m; + Eigen::Matrix loc_m; loc_m(0, 0) = 1.; loc_m(0, 1) = 2.; loc_m(0, 2) = 3.; From 9190e82fc4d04b34db1c2f7a2e165c1a74b70c63 Mon Sep 17 00:00:00 2001 From: Wenqing Wang Date: Wed, 6 Nov 2024 17:53:11 +0100 Subject: [PATCH 5/7] [PETScMatrix] Forward declaration of PETScVector and one comment change --- MathLib/LinAlg/PETSc/PETScMatrix.cpp | 2 ++ MathLib/LinAlg/PETSc/PETScMatrix.h | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/MathLib/LinAlg/PETSc/PETScMatrix.cpp b/MathLib/LinAlg/PETSc/PETScMatrix.cpp index aa4e47d1619..76d0a47d5a6 100644 --- a/MathLib/LinAlg/PETSc/PETScMatrix.cpp +++ b/MathLib/LinAlg/PETSc/PETScMatrix.cpp @@ -16,6 +16,8 @@ #include "PETScMatrix.h" +#include "PETScVector.h" + namespace MathLib { PETScMatrix::PETScMatrix(const PetscInt nrows, const PETScMatrixOption& mat_opt) diff --git a/MathLib/LinAlg/PETSc/PETScMatrix.h b/MathLib/LinAlg/PETSc/PETScMatrix.h index 8beb40a7c90..4c932c1fb9a 100644 --- a/MathLib/LinAlg/PETSc/PETScMatrix.h +++ b/MathLib/LinAlg/PETSc/PETScMatrix.h @@ -19,12 +19,12 @@ #include "MathLib/LinAlg/RowColumnIndices.h" #include "PETScMatrixOption.h" -#include "PETScVector.h" typedef Mat PETSc_Mat; namespace MathLib { +class PETScVector; /*! \brief Wrapper class for PETSc matrix routines for matrix. */ @@ -173,7 +173,8 @@ class PETScMatrix \param row_pos The global indices of the rows of the dense sub-matrix. \param col_pos The global indices of the columns of the dense sub-matrix. - \param sub_mat A dense sub-matrix to be added. + \param sub_mat A dense sub-matrix to be added. Its data of which must + be row oriented stored. */ template void add(std::vector const& row_pos, From 9a3427cae48459753699908ad19f3d6c624464d0 Mon Sep 17 00:00:00 2001 From: Wenqing Wang Date: Wed, 6 Nov 2024 18:00:13 +0100 Subject: [PATCH 6/7] [UnitTest] Fixed PETSc Linear solver test --- Tests/MathLib/TestLinearSolver.cpp | 103 +++++++++++++++-------------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/Tests/MathLib/TestLinearSolver.cpp b/Tests/MathLib/TestLinearSolver.cpp index a1ca549f600..c3140099cc8 100644 --- a/Tests/MathLib/TestLinearSolver.cpp +++ b/Tests/MathLib/TestLinearSolver.cpp @@ -37,6 +37,7 @@ #include "MathLib/LinAlg/PETSc/PETScLinearSolver.h" #include "MathLib/LinAlg/PETSc/PETScMatrix.h" #include "MathLib/LinAlg/PETSc/PETScVector.h" +#include "Tests/TestTools.h" #endif #include "Tests/TestTools.h" @@ -220,6 +221,15 @@ void checkLinearSolverInterface(T_MATRIX& A, } #ifdef USE_PETSC + +BaseLib::ConfigTree getConfigTree(std::string const& xml) +{ + auto ptree = Tests::readXml(xml.c_str()); + return BaseLib::ConfigTree(std::move(ptree), "", + BaseLib::ConfigTree::onerror, + BaseLib::ConfigTree::onwarning); +} + template void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b, const std::string& prefix_name, @@ -228,7 +238,7 @@ void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b, int mrank; MPI_Comm_rank(PETSC_COMM_WORLD, &mrank); // Add entries - Eigen::Matrix2d loc_m; + Eigen::Matrix loc_m; loc_m(0, 0) = 1. + mrank; loc_m(0, 1) = 2. + mrank; loc_m(1, 0) = 3. + mrank; @@ -252,6 +262,7 @@ void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b, local_vec[0] = mrank + 1; local_vec[1] = 2. * (mrank + 1); x.set(row_pos, local_vec); + x.finalizeAssembly(); std::vector x0(6); x.getGlobalVector(x0); @@ -348,25 +359,22 @@ TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_basic) const bool is_global_size = false; MathLib::PETScVector b(2, is_global_size); - boost::property_tree::ptree petsc_solver; - boost::property_tree::ptree parameters; - boost::property_tree::ptree prefix; - parameters.put("parameters", - "-ptest1_ksp_type bcgs " - "-ptest1_ksp_rtol 1.e-8 " - "-ptest1_ksp_atol 1.e-50 " - "-ptest1_ksp_max_it 1000 " - "-ptest1_pc_type bjacobi"); - prefix.put("prefix", "ptest1"); - petsc_solver.put_child("petsc", parameters); - petsc_solver.put_child("petsc", prefix); + std::string const xml = + "" + "" + " test1" + "" + "" + " -test1_ksp_type bcgs" + " -test1_pc_type jacobi" + " -test1_ksp_rtol 1.e-10 -test1_ksp_atol 1.e-12" + " -test1_ksp_max_it 4000" + "" + ""; checkLinearSolverInterface( - A, b, "", - BaseLib::ConfigTree(std::move(petsc_solver), "", - BaseLib::ConfigTree::onerror, - BaseLib::ConfigTree::onwarning)); + A, b, "" /*prefix, not specified*/, getConfigTree(xml)); } TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_chebyshev_sor) @@ -381,24 +389,22 @@ TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_chebyshev_sor) const bool is_global_size = false; MathLib::PETScVector b(2, is_global_size); - boost::property_tree::ptree petsc_solver; - boost::property_tree::ptree parameters; - boost::property_tree::ptree prefix; - parameters.put("parameters", - "-ptest2_ksp_type chebyshev " - "-ptest2_ksp_rtol 1.e-8 " - "-ptest2_ksp_atol 1.e-50 " - "-ptest2_ksp_max_it 1000 " - "-ptest2_pc_type sor"); - prefix.put("prefix", "ptest2"); - petsc_solver.put_child("petsc", parameters); - petsc_solver.put_child("petsc", prefix); + std::string const xml = + "" + "" + " test2" + "" + "" + " -test2_ksp_type chebyshev" + " -test2_pc_type sor" + " -test2_ksp_rtol 1.e-10 -test2_ksp_atol 1.e-12" + " -test2_ksp_max_it 4000" + "" + ""; + checkLinearSolverInterface( - A, b, "", - BaseLib::ConfigTree(std::move(petsc_solver), "", - BaseLib::ConfigTree::onerror, - BaseLib::ConfigTree::onwarning)); + A, b, "" /*prefix, not specified*/, getConfigTree(xml)); } TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_gmres_amg) @@ -413,27 +419,22 @@ TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_gmres_amg) const bool is_global_size = false; MathLib::PETScVector b(2, is_global_size); - boost::property_tree::ptree petsc_solver; - boost::property_tree::ptree parameters; - boost::property_tree::ptree prefix; - parameters.put("parameters", - "-ptest3_ksp_type gmres " - "-ptest3_ksp_rtol 1.e-8 " - "-ptest3_ksp_gmres_restart 20 " - "-ptest3_ksp_gmres_classicalgramschmidt " - "-ptest3_pc_type gamg " - "-ptest3_pc_gamg_type agg " - "-ptest3_pc_gamg_agg_nsmooths 2"); - prefix.put("prefix", "ptest3"); - petsc_solver.put_child("petsc", parameters); - petsc_solver.put_child("petsc", prefix); + std::string const xml = + "" + " " + " -ksp_type gmres " + " -ksp_rtol 1.e-8 " + " -ksp_gmres_restart 20 " + " -ksp_gmres_classicalgramschmidt " + " -pc_type gamg " + " -pc_gamg_type agg " + " -pc_gamg_agg_nsmooths 2" + " " + ""; checkLinearSolverInterface( - A, b, "", - BaseLib::ConfigTree(std::move(petsc_solver), "", - BaseLib::ConfigTree::onerror, - BaseLib::ConfigTree::onwarning)); + A, b, "" /*prefix, not specified*/, getConfigTree(xml)); } #endif From 5e05d11e695e1a002bc786c44537045fbe6941c1 Mon Sep 17 00:00:00 2001 From: Wenqing Wang Date: Fri, 15 Nov 2024 15:53:13 +0100 Subject: [PATCH 7/7] [CT] Temporally disabled a benchmark: RadionuclideSorption.prj where PETScVector is incorrectly used as serial vector type. --- ProcessLib/ComponentTransport/Tests.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ProcessLib/ComponentTransport/Tests.cmake b/ProcessLib/ComponentTransport/Tests.cmake index 0a24bcdaf01..e1901bdf713 100644 --- a/ProcessLib/ComponentTransport/Tests.cmake +++ b/ProcessLib/ComponentTransport/Tests.cmake @@ -926,7 +926,8 @@ AddTest( if (OGS_USE_MPI) OgsTest(WRAPPER mpirun -np 1 PROJECTFILE Parabolic/ComponentTransport/ReactiveTransport/EquilibriumPhase/calcitePorosityChange.prj RUNTIME 25) - OgsTest(WRAPPER mpirun -np 2 PROJECTFILE Parabolic/ComponentTransport/ReactiveTransport/SurfaceComplexation/ParallelTest/RadionuclideSorption.prj RUNTIME 60) + # Disabled the following test due to the incorrectly used PETSc vector in AqueousSolution. Will be enabled once the issue is fixed. + #OgsTest(WRAPPER mpirun -np 2 PROJECTFILE Parabolic/ComponentTransport/ReactiveTransport/SurfaceComplexation/ParallelTest/RadionuclideSorption.prj RUNTIME 60) endif() AddTest(