From 0b4103f18cda1dfd90703836f5b76f036e083fa8 Mon Sep 17 00:00:00 2001 From: julianlitz Date: Wed, 18 Feb 2026 21:50:32 +0100 Subject: [PATCH 1/5] Add copy --- include/LinearAlgebra/Matrix/coo_matrix.h | 12 ++--- include/LinearAlgebra/Matrix/csr_matrix.h | 12 ++--- .../LinearAlgebra/Vector/vector_operations.h | 13 +++++ src/GMGPolar/solver.cpp | 2 +- src/Residual/ResidualGive/residualGive.cpp | 2 +- src/Smoother/SmootherGive/smootherGive.cpp | 2 +- tests/DirectSolver/directSolver.cpp | 48 +++++++++---------- tests/DirectSolver/directSolverNoMumps.cpp | 48 +++++++++---------- .../extrapolated_smoother.cpp | 40 ++++++++-------- .../Vector/vector_operations.cpp | 24 +++++++++- tests/Smoother/smoother.cpp | 40 ++++++++-------- 11 files changed, 139 insertions(+), 104 deletions(-) diff --git a/include/LinearAlgebra/Matrix/coo_matrix.h b/include/LinearAlgebra/Matrix/coo_matrix.h index 9cfdc17f..d8bfda02 100644 --- a/include/LinearAlgebra/Matrix/coo_matrix.h +++ b/include/LinearAlgebra/Matrix/coo_matrix.h @@ -142,9 +142,9 @@ SparseMatrixCOO::SparseMatrixCOO(const SparseMatrixCOO& other) , values_("COO values", nnz_) , is_symmetric_(other.is_symmetric_) { - Kokkos::deep_copy(row_indices_, other.row_indices_); - Kokkos::deep_copy(column_indices_, other.column_indices_); - Kokkos::deep_copy(values_, other.values_); + copy_vector(row_indices_, other.row_indices_); + copy_vector(column_indices_, other.column_indices_); + copy_vector(values_, other.values_); } // copy assignment @@ -166,9 +166,9 @@ SparseMatrixCOO& SparseMatrixCOO::operator=(const SparseMatrixCOO& other) columns_ = other.columns_; nnz_ = other.nnz_; is_symmetric_ = other.is_symmetric_; - Kokkos::deep_copy(row_indices_, other.row_indices_); - Kokkos::deep_copy(column_indices_, other.column_indices_); - Kokkos::deep_copy(values_, other.values_); + copy_vector(row_indices_, other.row_indices_); + copy_vector(column_indices_, other.column_indices_); + copy_vector(values_, other.values_); return *this; } diff --git a/include/LinearAlgebra/Matrix/csr_matrix.h b/include/LinearAlgebra/Matrix/csr_matrix.h index d9af82f1..76c08e96 100644 --- a/include/LinearAlgebra/Matrix/csr_matrix.h +++ b/include/LinearAlgebra/Matrix/csr_matrix.h @@ -116,9 +116,9 @@ SparseMatrixCSR::SparseMatrixCSR(const SparseMatrixCSR& other) , column_indices_("CSR column indices", nnz_) , row_start_indices_("CSR row start indices", rows_ + 1) { - Kokkos::deep_copy(values_, other.values_); - Kokkos::deep_copy(column_indices_, other.column_indices_); - Kokkos::deep_copy(row_start_indices_, other.row_start_indices_); + copy_vector(values_, other.values_); + copy_vector(column_indices_, other.column_indices_); + copy_vector(row_start_indices_, other.row_start_indices_); } // copy assignment @@ -139,9 +139,9 @@ SparseMatrixCSR& SparseMatrixCSR::operator=(const SparseMatrixCSR& other) rows_ = other.rows_; columns_ = other.columns_; nnz_ = other.nnz_; - Kokkos::deep_copy(values_, other.values_); - Kokkos::deep_copy(column_indices_, other.column_indices_); - Kokkos::deep_copy(row_start_indices_, other.row_start_indices_); + copy_vector(values_, other.values_); + copy_vector(column_indices_, other.column_indices_); + copy_vector(row_start_indices_, other.row_start_indices_); return *this; } diff --git a/include/LinearAlgebra/Vector/vector_operations.h b/include/LinearAlgebra/Vector/vector_operations.h index 2546a6e0..7635dc77 100644 --- a/include/LinearAlgebra/Vector/vector_operations.h +++ b/include/LinearAlgebra/Vector/vector_operations.h @@ -35,6 +35,19 @@ void assign(Vector lhs, const T& value) } } +template +void copy_vector(Vector dst, ConstVector src) +{ + if (dst.size() != src.size()) { + throw std::invalid_argument("Vectors must be of the same size."); + } + std::size_t n = dst.size(); +#pragma omp parallel for if (n > 10'000) + for (std::size_t i = 0; i < n; ++i) { + dst(i) = src(i); + } +} + template void add(Vector result, ConstVector x) { diff --git a/src/GMGPolar/solver.cpp b/src/GMGPolar/solver.cpp index ebc6d342..a67e6563 100644 --- a/src/GMGPolar/solver.cpp +++ b/src/GMGPolar/solver.cpp @@ -17,7 +17,7 @@ void IGMGPolar::initializeSolution() Level& coarsest_level = levels_[coarsest_depth]; // Solve directly on the coarsest level - Kokkos::deep_copy(coarsest_level.solution(), coarsest_level.rhs()); + copy_vector(coarsest_level.solution(), coarsest_level.rhs()); coarsest_level.directSolveInPlace(coarsest_level.solution()); // Direct solve on coarsest grid // Prolongate the solution from the coarsest level up to the finest, while applying Multigrid Cycles on each level diff --git a/src/Residual/ResidualGive/residualGive.cpp b/src/Residual/ResidualGive/residualGive.cpp index eb308998..54284957 100644 --- a/src/Residual/ResidualGive/residualGive.cpp +++ b/src/Residual/ResidualGive/residualGive.cpp @@ -16,7 +16,7 @@ void ResidualGive::computeResidual(Vector result, ConstVector rh { assert(result.size() == x.size()); - Kokkos::deep_copy(result, rhs); + copy_vector(result, rhs); /* Single-threaded execution */ if (num_omp_threads_ == 1) { diff --git a/src/Smoother/SmootherGive/smootherGive.cpp b/src/Smoother/SmootherGive/smootherGive.cpp index db458ad0..a6775676 100644 --- a/src/Smoother/SmootherGive/smootherGive.cpp +++ b/src/Smoother/SmootherGive/smootherGive.cpp @@ -49,7 +49,7 @@ void SmootherGive::smoothing(Vector x, ConstVector rhs, Vector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -238,7 +238,7 @@ TEST(DirectSolverTest_CircularGeometry, ParallelDirectSolverDirBC_Interior_Circu ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -282,7 +282,7 @@ TEST(DirectSolverTest_CircularGeometry, SequentialDirectSolverAcrossOrigin_Circu ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -326,7 +326,7 @@ TEST(DirectSolverTest_CircularGeometry, ParallelDirectSolverAcrossOrigin_Circula ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -375,7 +375,7 @@ TEST(DirectSolverTest_ShafranovGeometry, DirectSolverDirBC_Interior_ShafranovGeo ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -420,7 +420,7 @@ TEST(DirectSolverTest_ShafranovGeometry, DirectSolverAcrossOrigin_ShafranovGeome ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -470,7 +470,7 @@ TEST(DirectSolverTest_CzarnyGeometry, DirectSolverDirBC_Interior_CzarnyGeometry) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -516,7 +516,7 @@ TEST(DirectSolverTest_CzarnyGeometry, DirectSolverAcrossOrigin_CzarnyGeometry) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -564,7 +564,7 @@ TEST(DirectSolverTest_CulhamGeometry, DirectSolverDirBC_Interior_CulhamGeometry) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -608,7 +608,7 @@ TEST(DirectSolverTest_CulhamGeometry, DirectSolverAcrossOrigin_CulhamGeometry) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -664,7 +664,7 @@ TEST(DirectSolverTest_CircularGeometry, DirectSolverAcrossOriginHigherPrecision_ ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -708,7 +708,7 @@ TEST(DirectSolverTest_CircularGeometry, DirectSolverAcrossOriginHigherPrecision2 ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -753,7 +753,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, SequentialDirectSolverDirBC_Interior ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -797,7 +797,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, ParallelDirectSolverDirBC_Interior_C ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -841,7 +841,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, SequentialDirectSolverAcrossOrigin_C ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -885,7 +885,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, ParallelDirectSolverAcrossOrigin_Cir ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -934,7 +934,7 @@ TEST(DirectSolverTakeTest_ShafranovGeometry, DirectSolverDirBC_Interior_Shafrano ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -979,7 +979,7 @@ TEST(DirectSolverTakeTest_ShafranovGeometry, DirectSolverAcrossOrigin_ShafranovG ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1029,7 +1029,7 @@ TEST(DirectSolverTakeTest_CzarnyGeometry, DirectSolverDirBC_Interior_CzarnyGeome ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1075,7 +1075,7 @@ TEST(DirectSolverTakeTest_CzarnyGeometry, DirectSolverAcrossOrigin_CzarnyGeometr ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1123,7 +1123,7 @@ TEST(DirectSolverTakeTest_CulhamGeometry, DirectSolverDirBC_Interior_CulhamGeome ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1167,7 +1167,7 @@ TEST(DirectSolverTakeTest_CulhamGeometry, DirectSolverAcrossOrigin_CulhamGeometr ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1221,7 +1221,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, DirectSolverAcrossOriginHigherPrecis ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1265,7 +1265,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, DirectSolverAcrossOriginHigherPrecis ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("sol", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); diff --git a/tests/DirectSolver/directSolverNoMumps.cpp b/tests/DirectSolver/directSolverNoMumps.cpp index 8d296245..6ab457f7 100644 --- a/tests/DirectSolver/directSolverNoMumps.cpp +++ b/tests/DirectSolver/directSolverNoMumps.cpp @@ -194,7 +194,7 @@ TEST(DirectSolverTestNoMumps_CircularGeometry, SequentialDirectSolverDirBC_Inter ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -238,7 +238,7 @@ TEST(DirectSolverTestNoMumps_CircularGeometry, ParallelDirectSolverDirBC_Interio ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -282,7 +282,7 @@ TEST(DirectSolverTestNoMumps_CircularGeometry, SequentialDirectSolverAcrossOrigi ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -326,7 +326,7 @@ TEST(DirectSolverTestNoMumps_CircularGeometry, ParallelDirectSolverAcrossOrigin_ ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -376,7 +376,7 @@ TEST(DirectSolverTestNoMumps_ShafranovGeometry, DirectSolverDirBC_Interior_Shafr ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -422,7 +422,7 @@ TEST(DirectSolverTestNoMumps_ShafranovGeometry, DirectSolverAcrossOrigin_Shafran ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -473,7 +473,7 @@ TEST(DirectSolverTestNoMumps_CzarnyGeometry, DirectSolverDirBC_Interior_CzarnyGe ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -520,7 +520,7 @@ TEST(DirectSolverTestNoMumps_CzarnyGeometry, DirectSolverAcrossOrigin_CzarnyGeom ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -568,7 +568,7 @@ TEST(DirectSolverTestNoMumps_CulhamGeometry, DirectSolverDirBC_Interior_CulhamGe ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -612,7 +612,7 @@ TEST(DirectSolverTestNoMumps_CulhamGeometry, DirectSolverAcrossOrigin_CulhamGeom ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -668,7 +668,7 @@ TEST(DirectSolverTestNoMumps_CircularGeometry, DirectSolverAcrossOriginHigherPre ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -712,7 +712,7 @@ TEST(DirectSolverTestNoMumps_CircularGeometry, DirectSolverAcrossOriginHigherPre ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -757,7 +757,7 @@ TEST(DirectSolverTakeCustomLUTest_CircularGeometry, SequentialDirectSolverDirBC_ ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -801,7 +801,7 @@ TEST(DirectSolverTakeCustomLUTest_CircularGeometry, ParallelDirectSolverDirBC_In ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -845,7 +845,7 @@ TEST(DirectSolverTakeCustomLUTest_CircularGeometry, SequentialDirectSolverAcross ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -889,7 +889,7 @@ TEST(DirectSolverTakeCustomLUTest_CircularGeometry, ParallelDirectSolverAcrossOr ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -939,7 +939,7 @@ TEST(DirectSolverTakeCustomLUTest_ShafranovGeometry, DirectSolverDirBC_Interior_ ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -985,7 +985,7 @@ TEST(DirectSolverTakeCustomLUTest_ShafranovGeometry, DirectSolverAcrossOrigin_Sh ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1036,7 +1036,7 @@ TEST(DirectSolverTakeCustomLUTest_CzarnyGeometry, DirectSolverDirBC_Interior_Cza ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1083,7 +1083,7 @@ TEST(DirectSolverTakeCustomLUTest_CzarnyGeometry, DirectSolverAcrossOrigin_Czarn ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1131,7 +1131,7 @@ TEST(DirectSolverTakeCustomLUTest_CulhamGeometry, DirectSolverDirBC_Interior_Cul ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1175,7 +1175,7 @@ TEST(DirectSolverTakeCustomLUTest_CulhamGeometry, DirectSolverAcrossOrigin_Culha ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1229,7 +1229,7 @@ TEST(DirectSolverTakeCustomLUTest_CircularGeometry, DirectSolverAcrossOriginHigh ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); @@ -1273,7 +1273,7 @@ TEST(DirectSolverTakeCustomLUTest_CircularGeometry, DirectSolverAcrossOriginHigh ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector solution("solution", rhs.size()); - Kokkos::deep_copy(solution, rhs); + copy_vector(solution, rhs); solver_op.solveInPlace(solution); Vector residuum("residuum", level.grid().numberOfNodes()); diff --git a/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp b/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp index d35a809d..bb810e80 100644 --- a/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp +++ b/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp @@ -70,11 +70,11 @@ TEST(ExtrapolatedSmootherTest, extrapolatedSmoother_DirBC_Interior) Vector temp = generate_random_sample_data(level.grid(), 8); Vector solution_Give("solution_Give", start.size()); - Kokkos::deep_copy(solution_Give, start); + copy_vector(solution_Give, start); smootherGive_operator.extrapolatedSmoothing(solution_Give, rhs, temp); Vector solution_Take("solution_Take", start.size()); - Kokkos::deep_copy(solution_Take, start); + copy_vector(solution_Take, start); smootherTake_operator.extrapolatedSmoothing(solution_Take, rhs, temp); @@ -130,11 +130,11 @@ TEST(ExtrapolatedSmootherTest, extrapolatedSmoother_AcossOrigin) Vector temp = generate_random_sample_data(level.grid(), 8); Vector solution_Give("solution_Give", start.size()); - Kokkos::deep_copy(solution_Give, start); + copy_vector(solution_Give, start); smootherGive_operator.extrapolatedSmoothing(solution_Give, rhs, temp); Vector solution_Take("solution_Take", start.size()); - Kokkos::deep_copy(solution_Take, start); + copy_vector(solution_Take, start); smootherTake_operator.extrapolatedSmoothing(solution_Take, rhs, temp); ASSERT_EQ(solution_Give.size(), solution_Take.size()); @@ -190,7 +190,7 @@ TEST(ExtrapolatedSmootherTest, SequentialExtrapolatedSmootherDirBC_Interior) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -273,7 +273,7 @@ TEST(ExtrapolatedSmootherTest, ParallelExtrapolatedSmootherDirBC_Interior) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -356,7 +356,7 @@ TEST(ExtrapolatedSmootherTest, SequentialExtrapolatedSmootherAcrossOrigin) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -441,7 +441,7 @@ TEST(ExtrapolatedSmootherTest, ParallelExtrapolatedSmootherAcrossOrigin) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -525,7 +525,7 @@ TEST(ExtrapolatedSmootherTest, SequentialExtrapolatedSmootherDirBC_Interior_Smal ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -609,7 +609,7 @@ TEST(ExtrapolatedSmootherTest, ParallelExtrapolatedSmootherDirBC_Interior_Smalle ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -693,7 +693,7 @@ TEST(ExtrapolatedSmootherTest, SequentialExtrapolatedSmootherAcrossOrigin_Smalle ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -775,7 +775,7 @@ TEST(ExtrapolatedSmootherTest, ParallelExtrapolatedSmootherAcrossOrigin_Smallest ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -860,7 +860,7 @@ TEST(ExtrapolatedSmootherTest, SequentialExtrapolatedSmootherTakeDirBC_Interior) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -945,7 +945,7 @@ TEST(ExtrapolatedSmootherTest, ParallelExtrapolatedSmootherTakeDirBC_Interior) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1028,7 +1028,7 @@ TEST(ExtrapolatedSmootherTest, SequentialExtrapolatedSmootherTakeAcrossOrigin) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1111,7 +1111,7 @@ TEST(ExtrapolatedSmootherTest, ParallelExtrapolatedSmootherTakeAcrossOrigin) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1193,7 +1193,7 @@ TEST(ExtrapolatedSmootherTest, SequentialExtrapolatedSmootherTakeDirBC_Interior_ ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1275,7 +1275,7 @@ TEST(ExtrapolatedSmootherTest, ParallelExtrapolatedSmootherTakeDirBC_Interior_Sm ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1357,7 +1357,7 @@ TEST(ExtrapolatedSmootherTest, SequentialExtrapolatedSmootherTakeAcrossOrigin_Sm ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1439,7 +1439,7 @@ TEST(ExtrapolatedSmootherTest, ParallelExtrapolatedSmootherTakeAcrossOrigin_Smal ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); diff --git a/tests/LinearAlgebra/Vector/vector_operations.cpp b/tests/LinearAlgebra/Vector/vector_operations.cpp index d411a48f..0f49a5b3 100644 --- a/tests/LinearAlgebra/Vector/vector_operations.cpp +++ b/tests/LinearAlgebra/Vector/vector_operations.cpp @@ -49,10 +49,32 @@ TEST(VectorOperations, assign_vector_scalar) v(2) = 3; assign(v, 5.0); Vector expected_result("expected_result", 3); - Kokkos::deep_copy(expected_result, 5); + expected_result(0) = 5; + expected_result(1) = 5; + expected_result(2) = 5; + EXPECT_TRUE(equals(ConstVector(v), ConstVector(expected_result))); } +/* void copy_vector(Vector& dst, ConstVector& src); */ + +TEST(VectorOperations, copy_vector) +{ + Vector src("src", 3); + src(0) = 1; + src(1) = 2; + src(2) = 3; + + Vector dst("dst", 3); + copy_vector(dst, ConstVector(src)); + Vector expected_result("expected_result", 3); + expected_result(0) = 1; + expected_result(1) = 2; + expected_result(2) = 3; + + EXPECT_TRUE(equals(ConstVector(dst), ConstVector(expected_result))); +} + /* void add(Vector result, ConstVector x); */ TEST(VectorOperations, add_vector_vector) diff --git a/tests/Smoother/smoother.cpp b/tests/Smoother/smoother.cpp index 087d9bae..d3b1b579 100644 --- a/tests/Smoother/smoother.cpp +++ b/tests/Smoother/smoother.cpp @@ -69,11 +69,11 @@ TEST(SmootherTest, smoother_DirBC_Interior) Vector temp = generate_random_sample_data(level.grid(), 8); Vector solution_Give("solution_Give", start.size()); - Kokkos::deep_copy(solution_Give, start); + copy_vector(solution_Give, start); smootherGive_operator.smoothing(solution_Give, rhs, temp); Vector solution_Take("solution_Take", start.size()); - Kokkos::deep_copy(solution_Take, start); + copy_vector(solution_Take, start); smootherTake_operator.smoothing(solution_Take, rhs, temp); ASSERT_EQ(solution_Give.size(), solution_Take.size()); @@ -128,11 +128,11 @@ TEST(SmootherTest, smoother_AcrossOrigin) Vector temp = generate_random_sample_data(level.grid(), 8); Vector solution_Give("solution_Give", start.size()); - Kokkos::deep_copy(solution_Give, start); + copy_vector(solution_Give, start); smootherGive_operator.smoothing(solution_Give, rhs, temp); Vector solution_Take("solution_Take", start.size()); - Kokkos::deep_copy(solution_Take, start); + copy_vector(solution_Take, start); smootherTake_operator.smoothing(solution_Take, rhs, temp); ASSERT_EQ(solution_Give.size(), solution_Take.size()); @@ -188,7 +188,7 @@ TEST(SmootherTest, SequentialSmootherDirBC_Interior) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -266,7 +266,7 @@ TEST(SmootherTest, ParallelSmootherDirBC_Interior) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -344,7 +344,7 @@ TEST(SmootherTest, SequentialSmootherAcrossOrigin) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -422,7 +422,7 @@ TEST(SmootherTest, ParallelSmootherAcrossOrigin) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -499,7 +499,7 @@ TEST(SmootherTest, SequentialSmootherDirBC_Interior_SmallestGrid) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -576,7 +576,7 @@ TEST(SmootherTest, ParallelSmootherDirBC_Interior_SmallestGrid) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -653,7 +653,7 @@ TEST(SmootherTest, SequentialSmootherAcrossOrigin_SmallestGrid) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -730,7 +730,7 @@ TEST(SmootherTest, ParallelSmootherAcrossOrigin_SmallestGrid) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -810,7 +810,7 @@ TEST(SmootherTest, SequentialSmootherTakeDirBC_Interior) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -888,7 +888,7 @@ TEST(SmootherTest, ParallelSmootherTakeDirBC_Interior) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -966,7 +966,7 @@ TEST(SmootherTest, SequentialSmootherTakeAcrossOrigin) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1044,7 +1044,7 @@ TEST(SmootherTest, ParallelSmootherTakeAcrossOrigin) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1121,7 +1121,7 @@ TEST(SmootherTest, SequentialSmootherTakeDirBC_Interior_SmallestGrid) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1198,7 +1198,7 @@ TEST(SmootherTest, ParallelSmootherTakeDirBC_Interior_SmallestGrid) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1275,7 +1275,7 @@ TEST(SmootherTest, SequentialSmootherTakeAcrossOrigin_SmallestGrid) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); @@ -1352,7 +1352,7 @@ TEST(SmootherTest, ParallelSmootherTakeAcrossOrigin_SmallestGrid) ConstVector rhs = generate_random_sample_data(level.grid(), 42); Vector discrete_solution("discrete_solution", rhs.size()); - Kokkos::deep_copy(discrete_solution, rhs); + copy_vector(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); Vector temp("temp", level.grid().numberOfNodes()); From 3352b053ca25160bf26bbd0749461c4eabbf85f4 Mon Sep 17 00:00:00 2001 From: julianlitz Date: Wed, 18 Feb 2026 22:40:34 +0100 Subject: [PATCH 2/5] const --- include/LinearAlgebra/Matrix/coo_matrix.h | 12 ++++++------ include/LinearAlgebra/Matrix/csr_matrix.h | 14 +++++++------- src/GMGPolar/solver.cpp | 2 +- .../ExtrapolatedSmoother/extrapolated_smoother.cpp | 12 ++++++------ tests/Smoother/smoother.cpp | 12 ++++++------ 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/LinearAlgebra/Matrix/coo_matrix.h b/include/LinearAlgebra/Matrix/coo_matrix.h index d8bfda02..8c119c30 100644 --- a/include/LinearAlgebra/Matrix/coo_matrix.h +++ b/include/LinearAlgebra/Matrix/coo_matrix.h @@ -142,9 +142,9 @@ SparseMatrixCOO::SparseMatrixCOO(const SparseMatrixCOO& other) , values_("COO values", nnz_) , is_symmetric_(other.is_symmetric_) { - copy_vector(row_indices_, other.row_indices_); - copy_vector(column_indices_, other.column_indices_); - copy_vector(values_, other.values_); + copy_vector(row_indices_, ConstVector(other.row_indices_)); + copy_vector(column_indices_, ConstVector(other.column_indices_)); + copy_vector(values_, ConstVector(other.values_)); } // copy assignment @@ -166,9 +166,9 @@ SparseMatrixCOO& SparseMatrixCOO::operator=(const SparseMatrixCOO& other) columns_ = other.columns_; nnz_ = other.nnz_; is_symmetric_ = other.is_symmetric_; - copy_vector(row_indices_, other.row_indices_); - copy_vector(column_indices_, other.column_indices_); - copy_vector(values_, other.values_); + copy_vector(row_indices_, ConstVector(other.row_indices_)); + copy_vector(column_indices_, ConstVector(other.column_indices_)); + copy_vector(values_, ConstVector(other.values_)); return *this; } diff --git a/include/LinearAlgebra/Matrix/csr_matrix.h b/include/LinearAlgebra/Matrix/csr_matrix.h index 76c08e96..0c5a4eb2 100644 --- a/include/LinearAlgebra/Matrix/csr_matrix.h +++ b/include/LinearAlgebra/Matrix/csr_matrix.h @@ -71,7 +71,7 @@ class SparseMatrixCSR AllocatableVector column_indices_; AllocatableVector row_start_indices_; - bool is_sorted_entries(const std::vector>& entries) + bool is_sorted_entries(const std::vector& entries) { for (size_t i = 1; i < entries.size(); ++i) { const auto& prev = entries[i - 1]; @@ -116,9 +116,9 @@ SparseMatrixCSR::SparseMatrixCSR(const SparseMatrixCSR& other) , column_indices_("CSR column indices", nnz_) , row_start_indices_("CSR row start indices", rows_ + 1) { - copy_vector(values_, other.values_); - copy_vector(column_indices_, other.column_indices_); - copy_vector(row_start_indices_, other.row_start_indices_); + copy_vector(values_, ConstVector(other.values_)); + copy_vector(column_indices_, ConstVector(other.column_indices_)); + copy_vector(row_start_indices_, ConstVector(other.row_start_indices_)); } // copy assignment @@ -139,9 +139,9 @@ SparseMatrixCSR& SparseMatrixCSR::operator=(const SparseMatrixCSR& other) rows_ = other.rows_; columns_ = other.columns_; nnz_ = other.nnz_; - copy_vector(values_, other.values_); - copy_vector(column_indices_, other.column_indices_); - copy_vector(row_start_indices_, other.row_start_indices_); + copy_vector(values_, ConstVector(other.values_)); + copy_vector(column_indices_, ConstVector(other.column_indices_)); + copy_vector(row_start_indices_, ConstVector(other.row_start_indices_)); return *this; } diff --git a/src/GMGPolar/solver.cpp b/src/GMGPolar/solver.cpp index a67e6563..dd85f693 100644 --- a/src/GMGPolar/solver.cpp +++ b/src/GMGPolar/solver.cpp @@ -17,7 +17,7 @@ void IGMGPolar::initializeSolution() Level& coarsest_level = levels_[coarsest_depth]; // Solve directly on the coarsest level - copy_vector(coarsest_level.solution(), coarsest_level.rhs()); + copy_vector(coarsest_level.solution(), ConstVector(coarsest_level.rhs())); coarsest_level.directSolveInPlace(coarsest_level.solution()); // Direct solve on coarsest grid // Prolongate the solution from the coarsest level up to the finest, while applying Multigrid Cycles on each level diff --git a/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp b/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp index bb810e80..614e4f44 100644 --- a/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp +++ b/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp @@ -65,9 +65,9 @@ TEST(ExtrapolatedSmootherTest, extrapolatedSmoother_DirBC_Interior) ExtrapolatedSmootherTake smootherTake_operator(level.grid(), level.levelCache(), domain_geometry, *coefficients, DirBC_Interior, maxOpenMPThreads); - Vector rhs = generate_random_sample_data(level.grid(), 69); - Vector start = generate_random_sample_data(level.grid(), 24); - Vector temp = generate_random_sample_data(level.grid(), 8); + Vector rhs = generate_random_sample_data(level.grid(), 69); + ConstVector start = generate_random_sample_data(level.grid(), 24); + Vector temp = generate_random_sample_data(level.grid(), 8); Vector solution_Give("solution_Give", start.size()); copy_vector(solution_Give, start); @@ -125,9 +125,9 @@ TEST(ExtrapolatedSmootherTest, extrapolatedSmoother_AcossOrigin) ExtrapolatedSmootherTake smootherTake_operator(level.grid(), level.levelCache(), domain_geometry, *coefficients, DirBC_Interior, maxOpenMPThreads); - Vector rhs = generate_random_sample_data(level.grid(), 69); - Vector start = generate_random_sample_data(level.grid(), 24); - Vector temp = generate_random_sample_data(level.grid(), 8); + Vector rhs = generate_random_sample_data(level.grid(), 69); + ConstVector start = generate_random_sample_data(level.grid(), 24); + Vector temp = generate_random_sample_data(level.grid(), 8); Vector solution_Give("solution_Give", start.size()); copy_vector(solution_Give, start); diff --git a/tests/Smoother/smoother.cpp b/tests/Smoother/smoother.cpp index d3b1b579..ae680d4c 100644 --- a/tests/Smoother/smoother.cpp +++ b/tests/Smoother/smoother.cpp @@ -64,9 +64,9 @@ TEST(SmootherTest, smoother_DirBC_Interior) SmootherTake smootherTake_operator(level.grid(), level.levelCache(), domain_geometry, *coefficients, DirBC_Interior, maxOpenMPThreads); - Vector rhs = generate_random_sample_data(level.grid(), 69); - Vector start = generate_random_sample_data(level.grid(), 24); - Vector temp = generate_random_sample_data(level.grid(), 8); + Vector rhs = generate_random_sample_data(level.grid(), 69); + ConstVector start = generate_random_sample_data(level.grid(), 24); + Vector temp = generate_random_sample_data(level.grid(), 8); Vector solution_Give("solution_Give", start.size()); copy_vector(solution_Give, start); @@ -123,9 +123,9 @@ TEST(SmootherTest, smoother_AcrossOrigin) SmootherTake smootherTake_operator(level.grid(), level.levelCache(), domain_geometry, *coefficients, DirBC_Interior, maxOpenMPThreads); - Vector rhs = generate_random_sample_data(level.grid(), 69); - Vector start = generate_random_sample_data(level.grid(), 24); - Vector temp = generate_random_sample_data(level.grid(), 8); + Vector rhs = generate_random_sample_data(level.grid(), 69); + ConstVector start = generate_random_sample_data(level.grid(), 24); + Vector temp = generate_random_sample_data(level.grid(), 8); Vector solution_Give("solution_Give", start.size()); copy_vector(solution_Give, start); From 2585f55ef41e1a4af02c8fcd3d730a6d7ad52cea Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Thu, 19 Feb 2026 09:13:28 +0100 Subject: [PATCH 3/5] Update vector_operations.h --- include/LinearAlgebra/Vector/vector_operations.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/LinearAlgebra/Vector/vector_operations.h b/include/LinearAlgebra/Vector/vector_operations.h index 7635dc77..f6ba7393 100644 --- a/include/LinearAlgebra/Vector/vector_operations.h +++ b/include/LinearAlgebra/Vector/vector_operations.h @@ -41,11 +41,7 @@ void copy_vector(Vector dst, ConstVector src) if (dst.size() != src.size()) { throw std::invalid_argument("Vectors must be of the same size."); } - std::size_t n = dst.size(); -#pragma omp parallel for if (n > 10'000) - for (std::size_t i = 0; i < n; ++i) { - dst(i) = src(i); - } + Kokkos::parallel_deep_copy(dst, src); } template From 80c320fd68982ebd5672bafe46bb9b309e3734d8 Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Thu, 19 Feb 2026 09:14:28 +0100 Subject: [PATCH 4/5] Update vector_operations.h --- include/LinearAlgebra/Vector/vector_operations.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/LinearAlgebra/Vector/vector_operations.h b/include/LinearAlgebra/Vector/vector_operations.h index f6ba7393..75b96108 100644 --- a/include/LinearAlgebra/Vector/vector_operations.h +++ b/include/LinearAlgebra/Vector/vector_operations.h @@ -38,9 +38,6 @@ void assign(Vector lhs, const T& value) template void copy_vector(Vector dst, ConstVector src) { - if (dst.size() != src.size()) { - throw std::invalid_argument("Vectors must be of the same size."); - } Kokkos::parallel_deep_copy(dst, src); } From f95ddecf8e40124dfef0c58991496a57e11b0411 Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Thu, 19 Feb 2026 10:12:13 +0100 Subject: [PATCH 5/5] Update vector_operations.h --- include/LinearAlgebra/Vector/vector_operations.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/LinearAlgebra/Vector/vector_operations.h b/include/LinearAlgebra/Vector/vector_operations.h index 75b96108..2f95a1c6 100644 --- a/include/LinearAlgebra/Vector/vector_operations.h +++ b/include/LinearAlgebra/Vector/vector_operations.h @@ -38,7 +38,7 @@ void assign(Vector lhs, const T& value) template void copy_vector(Vector dst, ConstVector src) { - Kokkos::parallel_deep_copy(dst, src); + Kokkos::deep_copy(dst, src); } template