From fb81e845744076249376cbc5c1bc539a81889f94 Mon Sep 17 00:00:00 2001 From: jsandham Date: Thu, 6 Aug 2026 20:13:31 -0400 Subject: [PATCH 1/2] Make csr_matrix templated --- clients/common/utility.cpp | 16 +- clients/common/utility.h | 17 +- clients/examples/gauss_seidel_example.cpp | 10 +- clients/examples/gmres_example.cpp | 19 +- clients/examples/jacobi_example.cpp | 6 +- clients/examples/pcg_example.cpp | 10 +- clients/examples/richardson_example.cpp | 23 +- clients/examples/rsamg_example.cpp | 4 +- clients/examples/saamg_example.cpp | 4 +- clients/examples/sor_example.cpp | 23 +- clients/examples/ssor_example.cpp | 23 +- .../examples/symm_gauss_seidel_example.cpp | 23 +- clients/examples/uaamg_example.cpp | 4 +- clients/testing/test_functions_amg.cpp | 4 +- clients/testing/test_functions_classical.cpp | 4 +- clients/testing/test_functions_csric0.cpp | 8 +- clients/testing/test_functions_csrilu0.cpp | 8 +- ...ions_incomplete_LU_factorization_dense.cpp | 16 +- ...ions_incomplete_cholesky_factorization.cpp | 12 +- ...ncomplete_cholesky_factorization_dense.cpp | 16 +- clients/testing/test_functions_krylov.cpp | 8 +- .../test_functions_multiply_by_matrix.cpp | 14 +- .../test_functions_multiply_by_vector.cpp | 4 +- .../testing/test_functions_ruiz_scaling.cpp | 4 +- clients/testing/test_functions_spgeam.cpp | 8 +- clients/testing/test_functions_sptrsv.cpp | 4 +- .../test_functions_symmetric_ruiz_scaling.cpp | 2 +- clients/testing/test_functions_transpose.cpp | 6 +- .../test_functions_transpose_dense.cpp | 14 +- .../test_functions_triangular_solve.cpp | 4 +- clients/testing/tests/test_BICGSTAB.yaml | 2 +- clients/testing/tests/test_CG.yaml | 2 +- library/include/csr_matrix.h | 73 +++-- library/include/iterative_solvers/amg/amg.h | 12 +- .../iterative_solvers/amg/amg_aggregation.h | 19 +- .../iterative_solvers/amg/amg_strength.h | 15 +- .../include/iterative_solvers/amg/amg_util.h | 10 +- library/include/iterative_solvers/amg/rsamg.h | 7 +- library/include/iterative_solvers/amg/saamg.h | 7 +- library/include/iterative_solvers/amg/uaamg.h | 6 +- .../iterative_solvers/classic/gauss_seidel.h | 12 +- .../iterative_solvers/classic/jacobi.h | 12 +- .../iterative_solvers/classic/richardson.h | 14 +- .../include/iterative_solvers/classic/sor.h | 14 +- .../include/iterative_solvers/classic/ssor.h | 14 +- .../classic/symmetric_gauss_seidel.h | 12 +- .../iterative_solvers/krylov/bicgstab.h | 32 +- library/include/iterative_solvers/krylov/cg.h | 32 +- .../include/iterative_solvers/krylov/gmres.h | 32 +- .../preconditioner/preconditioner.h | 50 ++-- library/include/linalg_math.h | 118 ++++---- .../backend/device/device_amg_aggregation.cpp | 47 +-- .../backend/device/device_amg_aggregation.h | 47 +-- .../backend/device/device_amg_strength.cpp | 18 +- .../src/backend/device/device_amg_strength.h | 18 +- library/src/backend/device/device_csr2csc.cpp | 2 +- library/src/backend/device/device_csr2csc.h | 4 +- library/src/backend/device/device_csrgeam.cpp | 24 +- library/src/backend/device/device_csrgeam.h | 24 +- library/src/backend/device/device_csrgemm.cpp | 28 +- library/src/backend/device/device_csrgemm.h | 28 +- library/src/backend/device/device_csric0.cpp | 6 +- library/src/backend/device/device_csric0.h | 6 +- library/src/backend/device/device_csrilu0.cpp | 6 +- library/src/backend/device/device_csrilu0.h | 6 +- library/src/backend/device/device_csrtrsv.cpp | 22 +- library/src/backend/device/device_csrtrsv.h | 22 +- library/src/backend/device/device_extract.cpp | 14 +- library/src/backend/device/device_extract.h | 16 +- .../backend/device/device_matrix_vector.cpp | 26 +- .../src/backend/device/device_matrix_vector.h | 25 +- .../backend/device/device_ruiz_scaling.cpp | 7 +- .../src/backend/device/device_ruiz_scaling.h | 7 +- library/src/backend/device/device_scale.cpp | 4 +- library/src/backend/device/device_scale.h | 6 +- library/src/backend/device/device_ssor.cpp | 8 +- library/src/backend/device/device_ssor.h | 10 +- .../src/backend/host/host_amg_aggregation.cpp | 41 +-- .../src/backend/host/host_amg_aggregation.h | 46 +-- .../src/backend/host/host_amg_strength.cpp | 16 +- library/src/backend/host/host_amg_strength.h | 16 +- library/src/backend/host/host_csr2csc.cpp | 2 +- library/src/backend/host/host_csr2csc.h | 2 +- library/src/backend/host/host_csrgeam.cpp | 24 +- library/src/backend/host/host_csrgeam.h | 24 +- library/src/backend/host/host_csrgemm.cpp | 28 +- library/src/backend/host/host_csrgemm.h | 28 +- library/src/backend/host/host_csric0.cpp | 6 +- library/src/backend/host/host_csric0.h | 6 +- library/src/backend/host/host_csrilu0.cpp | 6 +- library/src/backend/host/host_csrilu0.h | 6 +- library/src/backend/host/host_csrtrsv.cpp | 22 +- library/src/backend/host/host_csrtrsv.h | 22 +- library/src/backend/host/host_extract.cpp | 14 +- library/src/backend/host/host_extract.h | 14 +- .../src/backend/host/host_matrix_vector.cpp | 26 +- library/src/backend/host/host_matrix_vector.h | 24 +- .../src/backend/host/host_ruiz_scaling.cpp | 7 +- library/src/backend/host/host_ruiz_scaling.h | 7 +- library/src/backend/host/host_scale.cpp | 4 +- library/src/backend/host/host_scale.h | 4 +- library/src/backend/host/host_ssor.cpp | 8 +- library/src/backend/host/host_ssor.h | 8 +- library/src/csr_matrix.cpp | 276 ++++++++++-------- library/src/iterative_solvers/amg/amg.cpp | 72 ++--- .../iterative_solvers/amg/amg_aggregation.cpp | 52 ++-- .../iterative_solvers/amg/amg_strength.cpp | 14 +- .../src/iterative_solvers/amg/amg_util.cpp | 12 +- library/src/iterative_solvers/amg/rsamg.cpp | 27 +- library/src/iterative_solvers/amg/saamg.cpp | 27 +- library/src/iterative_solvers/amg/uaamg.cpp | 28 +- .../classic/gauss_seidel.cpp | 19 +- .../src/iterative_solvers/classic/jacobi.cpp | 23 +- .../iterative_solvers/classic/richardson.cpp | 23 +- library/src/iterative_solvers/classic/sor.cpp | 21 +- .../src/iterative_solvers/classic/ssor.cpp | 23 +- .../classic/symmetric_gauss_seidel.cpp | 20 +- .../src/iterative_solvers/krylov/bicgstab.cpp | 32 +- library/src/iterative_solvers/krylov/cg.cpp | 34 +-- .../src/iterative_solvers/krylov/gmres.cpp | 33 +-- .../preconditioner/preconditioner.cpp | 18 +- library/src/linalg_math.cpp | 114 ++++---- 122 files changed, 1316 insertions(+), 1207 deletions(-) diff --git a/clients/common/utility.cpp b/clients/common/utility.cpp index c4152eb..16264aa 100644 --- a/clients/common/utility.cpp +++ b/clients/common/utility.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -423,12 +423,12 @@ bool load_diagonally_dominant_mtx_file(const std::string& filename, // return true; // } -bool check_solution(const linalg::csr_matrix& A, - const linalg::vector& b, - const linalg::vector& x, - const linalg::vector& initial_x, - double tol, - int norm_type) +bool check_solution(const linalg::csr_matrix& A, + const linalg::vector& b, + const linalg::vector& x, + const linalg::vector& initial_x, + double tol, + int norm_type) { for(size_t i = 0; i < x.get_size(); i++) { @@ -475,7 +475,7 @@ bool check_solution(const linalg::csr_matrix& A, return false; } -bool check_matrix_equality(const linalg::csr_matrix& A, const linalg::csr_matrix& B) +bool check_matrix_equality(const linalg::csr_matrix& A, const linalg::csr_matrix& B) { const int* csr_row_ptr_A = A.get_row_ptr(); const int* csr_col_ind_A = A.get_col_ind(); diff --git a/clients/common/utility.h b/clients/common/utility.h index e48f3d9..8f84213 100644 --- a/clients/common/utility.h +++ b/clients/common/utility.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -51,14 +51,15 @@ bool load_diagonally_dominant_mtx_file(const std::string& filename, // bool load_spd_mtx_file(const std::string &filename, std::vector &csr_row_ptr, std::vector &csr_col_ind, // std::vector &csr_val, int &m, int &n, int &nnz); -bool check_solution(const linalg::csr_matrix& A, - const linalg::vector& b, - const linalg::vector& x, - const linalg::vector& initial_x, - double tol, - int norm_type); +bool check_solution(const linalg::csr_matrix& A, + const linalg::vector& b, + const linalg::vector& x, + const linalg::vector& initial_x, + double tol, + int norm_type); -bool check_matrix_equality(const linalg::csr_matrix& A, const linalg::csr_matrix& B); +bool check_matrix_equality(const linalg::csr_matrix& A, + const linalg::csr_matrix& B); bool check_vector_equality(const linalg::vector& x, const linalg::vector& y); diff --git a/clients/examples/gauss_seidel_example.cpp b/clients/examples/gauss_seidel_example.cpp index c2656fc..6f04a23 100644 --- a/clients/examples/gauss_seidel_example.cpp +++ b/clients/examples/gauss_seidel_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -43,7 +43,7 @@ int main() // std::vector csr_col_ind = { 0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4 }; // std::vector csr_val = { 4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, // -1.0, 4.0 }; - linalg::csr_matrix A; + linalg::csr_matrix A; A.read_mtx("../matrices/SPD/shallow_water2/shallow_water2.mtx"); // Solution vector @@ -59,8 +59,8 @@ int main() linalg::iter_control control; control.max_iter = 1000; - control.rel_tol = 1e-08; - control.abs_tol = 1e-08; + control.rel_tol = 1e-08; + control.abs_tol = 1e-08; int iter = gs.solve(A, x, b, control); @@ -75,4 +75,4 @@ int main() // std::cout << "" << std::endl; return 0; -} \ No newline at end of file +} diff --git a/clients/examples/gmres_example.cpp b/clients/examples/gmres_example.cpp index 7540fc1..ace23b2 100644 --- a/clients/examples/gmres_example.cpp +++ b/clients/examples/gmres_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,8 +31,8 @@ int main() { - int m = 5; - int n = 5; + int m = 5; + int n = 5; int nnz = 15; // 4 3 0 0 2 @@ -40,11 +40,12 @@ int main() // 0 5 4 3 0 // 0 0 1 3 2 // 9 0 0 6 7 - std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; - std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; - std::vector csr_val = {4.0, 3.0, 2.0, 1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 1.0, 3.0, 2.0, 9.0, 6.0, 7.0}; + std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; + std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; + std::vector csr_val + = {4.0, 3.0, 2.0, 1.0, 2.0, 3.0, 5.0, 4.0, 3.0, 1.0, 3.0, 2.0, 9.0, 6.0, 7.0}; - linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); + linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); // Solution vector linalg::vector x(A.get_m()); @@ -65,11 +66,11 @@ int main() // Print solution std::cout << "x" << std::endl; - for (int i = 0; i < x.get_size(); i++) + for(int i = 0; i < x.get_size(); i++) { std::cout << x[i] << " "; } std::cout << "" << std::endl; return 0; -} \ No newline at end of file +} diff --git a/clients/examples/jacobi_example.cpp b/clients/examples/jacobi_example.cpp index 49130f4..3bcb3d9 100644 --- a/clients/examples/jacobi_example.cpp +++ b/clients/examples/jacobi_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -59,11 +59,11 @@ int main() std::vector csr_val = {4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, -1.0, 4.0}; - linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); + linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); A.print_matrix("A"); - linalg::csr_matrix A_copy; + linalg::csr_matrix A_copy; A_copy.copy_from(A); linalg::csric0_descr* descr_IC = nullptr; diff --git a/clients/examples/pcg_example.cpp b/clients/examples/pcg_example.cpp index 1481410..fc4f51f 100644 --- a/clients/examples/pcg_example.cpp +++ b/clients/examples/pcg_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -32,16 +32,16 @@ int main() { - linalg::csr_matrix A; + linalg::csr_matrix A; A.read_mtx("../matrices/SPD/shallow_water2/shallow_water2.mtx"); // Solution vector linalg::vector x(A.get_m()); - + x.move_to_device(); x.zeros(); x.move_to_host(); - + x.zeros(); // Righthand side vector @@ -71,4 +71,4 @@ int main() // std::cout << "" << std::endl; return 0; -} \ No newline at end of file +} diff --git a/clients/examples/richardson_example.cpp b/clients/examples/richardson_example.cpp index 6514cda..d6f30f4 100644 --- a/clients/examples/richardson_example.cpp +++ b/clients/examples/richardson_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,8 +31,8 @@ int main() { - int m = 5; - int n = 5; + int m = 5; + int n = 5; int nnz = 15; // 4 -1 0 0 -1 @@ -40,11 +40,12 @@ int main() // 0 -1 4 -1 0 // 0 0 -1 4 -1 // -1 0 0 -1 4 - std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; - std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; - std::vector csr_val = {4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, -1.0, 4.0}; + std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; + std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; + std::vector csr_val + = {4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, -1.0, 4.0}; - linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); + linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); // Solution vector linalg::vector x(A.get_m()); @@ -59,8 +60,8 @@ int main() linalg::iter_control control; control.max_iter = 1000; - control.rel_tol = 1e-08; - control.abs_tol = 1e-08; + control.rel_tol = 1e-08; + control.abs_tol = 1e-08; int iter = rich.solve(A, x, b, control, 0.5); @@ -68,11 +69,11 @@ int main() // Print solution std::cout << "x" << std::endl; - for (int i = 0; i < x.get_size(); i++) + for(int i = 0; i < x.get_size(); i++) { std::cout << x[i] << " "; } std::cout << "" << std::endl; return 0; -} \ No newline at end of file +} diff --git a/clients/examples/rsamg_example.cpp b/clients/examples/rsamg_example.cpp index a91af00..185e771 100644 --- a/clients/examples/rsamg_example.cpp +++ b/clients/examples/rsamg_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -32,7 +32,7 @@ int main() { - linalg::csr_matrix A; + linalg::csr_matrix A; A.read_mtx("../matrices/SPD/shallow_water2/shallow_water2.mtx"); // Solution vector diff --git a/clients/examples/saamg_example.cpp b/clients/examples/saamg_example.cpp index cac8ce3..fe1041f 100644 --- a/clients/examples/saamg_example.cpp +++ b/clients/examples/saamg_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -32,7 +32,7 @@ int main() { - linalg::csr_matrix A; + linalg::csr_matrix A; A.read_mtx("../matrices/SPD/shallow_water2/shallow_water2.mtx"); // Solution vector diff --git a/clients/examples/sor_example.cpp b/clients/examples/sor_example.cpp index 3a5389f..9477f59 100644 --- a/clients/examples/sor_example.cpp +++ b/clients/examples/sor_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,8 +31,8 @@ int main() { - int m = 5; - int n = 5; + int m = 5; + int n = 5; int nnz = 15; // 4 -1 0 0 -1 @@ -40,11 +40,12 @@ int main() // 0 -1 4 -1 0 // 0 0 -1 4 -1 // -1 0 0 -1 4 - std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; - std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; - std::vector csr_val = {4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, -1.0, 4.0}; + std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; + std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; + std::vector csr_val + = {4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, -1.0, 4.0}; - linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); + linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); // Solution vector linalg::vector x(A.get_m()); @@ -59,8 +60,8 @@ int main() linalg::iter_control control; control.max_iter = 1000; - control.rel_tol = 1e-08; - control.abs_tol = 1e-08; + control.rel_tol = 1e-08; + control.abs_tol = 1e-08; int iter = sor.solve(A, x, b, control, 0.666667); @@ -68,11 +69,11 @@ int main() // Print solution std::cout << "x" << std::endl; - for (int i = 0; i < x.get_size(); i++) + for(int i = 0; i < x.get_size(); i++) { std::cout << x[i] << " "; } std::cout << "" << std::endl; return 0; -} \ No newline at end of file +} diff --git a/clients/examples/ssor_example.cpp b/clients/examples/ssor_example.cpp index 4419377..a0ad0a3 100644 --- a/clients/examples/ssor_example.cpp +++ b/clients/examples/ssor_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,8 +31,8 @@ int main() { - int m = 5; - int n = 5; + int m = 5; + int n = 5; int nnz = 15; // 4 -1 0 0 -1 @@ -40,11 +40,12 @@ int main() // 0 -1 4 -1 0 // 0 0 -1 4 -1 // -1 0 0 -1 4 - std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; - std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; - std::vector csr_val = {4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, -1.0, 4.0}; + std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; + std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; + std::vector csr_val + = {4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, -1.0, 4.0}; - linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); + linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); // Solution vector linalg::vector x(A.get_m()); @@ -59,8 +60,8 @@ int main() linalg::iter_control control; control.max_iter = 1000; - control.rel_tol = 1e-08; - control.abs_tol = 1e-08; + control.rel_tol = 1e-08; + control.abs_tol = 1e-08; int iter = ssor.solve(A, x, b, control, 0.666667); @@ -68,11 +69,11 @@ int main() // Print solution std::cout << "x" << std::endl; - for (int i = 0; i < x.get_size(); i++) + for(int i = 0; i < x.get_size(); i++) { std::cout << x[i] << " "; } std::cout << "" << std::endl; return 0; -} \ No newline at end of file +} diff --git a/clients/examples/symm_gauss_seidel_example.cpp b/clients/examples/symm_gauss_seidel_example.cpp index 0a2eda3..7d2a1e7 100644 --- a/clients/examples/symm_gauss_seidel_example.cpp +++ b/clients/examples/symm_gauss_seidel_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,8 +31,8 @@ int main() { - int m = 5; - int n = 5; + int m = 5; + int n = 5; int nnz = 15; // 4 -1 0 0 -1 @@ -40,11 +40,12 @@ int main() // 0 -1 4 -1 0 // 0 0 -1 4 -1 // -1 0 0 -1 4 - std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; - std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; - std::vector csr_val = {4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, -1.0, 4.0}; + std::vector csr_row_ptr = {0, 3, 6, 9, 12, 15}; + std::vector csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4}; + std::vector csr_val + = {4.0, -1.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, 4.0, -1.0, -1.0, -1.0, 4.0}; - linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); + linalg::csr_matrix A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz); // Solution vector linalg::vector x(A.get_m()); @@ -59,8 +60,8 @@ int main() linalg::iter_control control; control.max_iter = 1000; - control.rel_tol = 1e-08; - control.abs_tol = 1e-08; + control.rel_tol = 1e-08; + control.abs_tol = 1e-08; int iter = sgs.solve(A, x, b, control); @@ -68,11 +69,11 @@ int main() // Print solution std::cout << "x" << std::endl; - for (int i = 0; i < x.get_size(); i++) + for(int i = 0; i < x.get_size(); i++) { std::cout << x[i] << " "; } std::cout << "" << std::endl; return 0; -} \ No newline at end of file +} diff --git a/clients/examples/uaamg_example.cpp b/clients/examples/uaamg_example.cpp index 4e5c1ff..a701e3a 100644 --- a/clients/examples/uaamg_example.cpp +++ b/clients/examples/uaamg_example.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -32,7 +32,7 @@ int main() { - linalg::csr_matrix A; + linalg::csr_matrix A; A.read_mtx("../matrices/SPD/shallow_water2/shallow_water2.mtx"); // Solution vector diff --git a/clients/testing/test_functions_amg.cpp b/clients/testing/test_functions_amg.cpp index 68be15e..d9e2dfa 100644 --- a/clients/testing/test_functions_amg.cpp +++ b/clients/testing/test_functions_amg.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -34,7 +34,7 @@ bool testing::test_amg(AMG_solver solver_type, Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); // Solution vector diff --git a/clients/testing/test_functions_classical.cpp b/clients/testing/test_functions_classical.cpp index c8d5ba4..f4b82b1 100644 --- a/clients/testing/test_functions_classical.cpp +++ b/clients/testing/test_functions_classical.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -40,7 +40,7 @@ bool testing::test_classical(classical_solver solver_type, Arguments arg) return false; } - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); mat_A.make_diagonally_dominant(); diff --git a/clients/testing/test_functions_csric0.cpp b/clients/testing/test_functions_csric0.cpp index 4429e76..7692a13 100644 --- a/clients/testing/test_functions_csric0.cpp +++ b/clients/testing/test_functions_csric0.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -36,18 +36,18 @@ bool testing::test_csric0(Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); std::cout << "Matrix: " << arg.filename << " m: " << mat_A.get_m() << " n: " << mat_A.get_n() << " nnz: " << mat_A.get_nnz() << std::endl; // Make a copy for host computation - linalg::csr_matrix mat_A_host; + linalg::csr_matrix mat_A_host; mat_A_host.copy_from(mat_A); // Make a copy for device computation - linalg::csr_matrix mat_A_device; + linalg::csr_matrix mat_A_device; mat_A_device.copy_from(mat_A); // Prepare for csric0 analysis diff --git a/clients/testing/test_functions_csrilu0.cpp b/clients/testing/test_functions_csrilu0.cpp index 20bd58f..fda2232 100644 --- a/clients/testing/test_functions_csrilu0.cpp +++ b/clients/testing/test_functions_csrilu0.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -36,18 +36,18 @@ bool testing::test_csrilu0(Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); std::cout << "Matrix: " << arg.filename << " m: " << mat_A.get_m() << " n: " << mat_A.get_n() << " nnz: " << mat_A.get_nnz() << std::endl; // Make a copy for host computation - linalg::csr_matrix mat_A_host; + linalg::csr_matrix mat_A_host; mat_A_host.copy_from(mat_A); // Make a copy for device computation - linalg::csr_matrix mat_A_device; + linalg::csr_matrix mat_A_device; mat_A_device.copy_from(mat_A); // Prepare for csrilu0 analysis diff --git a/clients/testing/test_functions_incomplete_LU_factorization_dense.cpp b/clients/testing/test_functions_incomplete_LU_factorization_dense.cpp index 8bbc77b..b3280bc 100644 --- a/clients/testing/test_functions_incomplete_LU_factorization_dense.cpp +++ b/clients/testing/test_functions_incomplete_LU_factorization_dense.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -55,12 +55,12 @@ bool testing::test_compute_incomplete_LU_factorization_dense(Arguments arg) } } - linalg::csr_matrix mat_A(csr_row_ptr, - csr_col_ind, - csr_val, - arg.m, - arg.m, - arg.m * arg.m); // dense + linalg::csr_matrix mat_A(csr_row_ptr, + csr_col_ind, + csr_val, + arg.m, + arg.m, + arg.m * arg.m); // dense mat_A.make_diagonally_dominant(); linalg::vector ones(mat_A.get_n()); @@ -75,7 +75,7 @@ bool testing::test_compute_incomplete_LU_factorization_dense(Arguments arg) linalg::vector z(mat_A.get_n()); z.zeros(); - linalg::csr_matrix mat_transpose; + linalg::csr_matrix mat_transpose; mat_transpose.resize(mat_A.get_n(), mat_A.get_m(), mat_A.get_nnz()); if(arg.backend == backend::GPU) diff --git a/clients/testing/test_functions_incomplete_cholesky_factorization.cpp b/clients/testing/test_functions_incomplete_cholesky_factorization.cpp index 7760670..e2e711d 100644 --- a/clients/testing/test_functions_incomplete_cholesky_factorization.cpp +++ b/clients/testing/test_functions_incomplete_cholesky_factorization.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 202-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -34,8 +34,8 @@ #include "linalg.h" -static bool compute_reference_incomplete_cholesky(const linalg::csr_matrix& A, - linalg::csr_matrix& L) +static bool compute_reference_incomplete_cholesky(const linalg::csr_matrix& A, + linalg::csr_matrix& L) { L.copy_from(A); @@ -114,7 +114,7 @@ static bool compute_reference_incomplete_cholesky(const linalg::csr_matrix& A, bool testing::test_compute_incomplete_cholesky_factorization(Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); if(mat_A.get_m() != mat_A.get_n()) @@ -123,10 +123,10 @@ bool testing::test_compute_incomplete_cholesky_factorization(Arguments arg) return false; } - linalg::csr_matrix mat_A_copy; + linalg::csr_matrix mat_A_copy; mat_A_copy.copy_from(mat_A); - linalg::csr_matrix mat_A_reference; + linalg::csr_matrix mat_A_reference; if(!compute_reference_incomplete_cholesky(mat_A, mat_A_reference)) { std::cerr << "Failed to compute reference Cholesky factorization." << std::endl; diff --git a/clients/testing/test_functions_incomplete_cholesky_factorization_dense.cpp b/clients/testing/test_functions_incomplete_cholesky_factorization_dense.cpp index aa511a0..0e73b24 100644 --- a/clients/testing/test_functions_incomplete_cholesky_factorization_dense.cpp +++ b/clients/testing/test_functions_incomplete_cholesky_factorization_dense.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -54,12 +54,12 @@ bool testing::test_compute_incomplete_cholesky_factorization_dense(Arguments arg } } - linalg::csr_matrix mat_A(csr_row_ptr, - csr_col_ind, - csr_val, - arg.m, - arg.m, - arg.m * arg.m); // Assuming a dense matrix for testing + linalg::csr_matrix mat_A(csr_row_ptr, + csr_col_ind, + csr_val, + arg.m, + arg.m, + arg.m * arg.m); // Assuming a dense matrix for testing mat_A.make_diagonally_dominant(); linalg::vector ones(mat_A.get_n()); @@ -74,7 +74,7 @@ bool testing::test_compute_incomplete_cholesky_factorization_dense(Arguments arg linalg::vector z(mat_A.get_n()); z.zeros(); - linalg::csr_matrix mat_transpose; + linalg::csr_matrix mat_transpose; mat_transpose.resize(mat_A.get_n(), mat_A.get_m(), mat_A.get_nnz()); if(arg.backend == backend::GPU) diff --git a/clients/testing/test_functions_krylov.cpp b/clients/testing/test_functions_krylov.cpp index 8f5702d..ded6199 100644 --- a/clients/testing/test_functions_krylov.cpp +++ b/clients/testing/test_functions_krylov.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -35,13 +35,9 @@ bool testing::test_krylov(krylov_solver solver_type, Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); - linalg::vector D1(mat_A.get_m()); - linalg::vector D2(mat_A.get_m()); - mat_A.apply_ruiz_scaling(D1, D2, 30, 1e-03); - // Solution vector linalg::vector vec_x(mat_A.get_m()); vec_x.zeros(); diff --git a/clients/testing/test_functions_multiply_by_matrix.cpp b/clients/testing/test_functions_multiply_by_matrix.cpp index d2a5af7..c6aff48 100644 --- a/clients/testing/test_functions_multiply_by_matrix.cpp +++ b/clients/testing/test_functions_multiply_by_matrix.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -35,8 +35,8 @@ #include "linalg.h" -static linalg::csr_matrix compute_reference_spgemm(const linalg::csr_matrix& A, - const linalg::csr_matrix& B) +static linalg::csr_matrix compute_reference_spgemm(const linalg::csr_matrix& A, + const linalg::csr_matrix& B) { int m = A.get_m(); int n = B.get_n(); @@ -137,7 +137,7 @@ bool testing::test_multiply_by_matrix(Arguments arg) { std::cout << "Testing multiply_by_matrix with arguments: " << std::endl; - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); for(int i = 0; i < mat_A.get_nnz(); i++) @@ -146,10 +146,10 @@ bool testing::test_multiply_by_matrix(Arguments arg) csr_val[i] = 1; } - linalg::csr_matrix mat_B; + linalg::csr_matrix mat_B; mat_B.copy_from(mat_A); - linalg::csr_matrix mat_C; + linalg::csr_matrix mat_C; mat_C.resize(mat_A.get_m(), mat_B.get_n(), 0); if(arg.backend == backend::GPU) @@ -188,7 +188,7 @@ bool testing::test_multiply_by_matrix(Arguments arg) // mat_C.print_matrix("C"); // Inline host solution - linalg::csr_matrix mat_C_host = compute_reference_spgemm(mat_A, mat_B); + linalg::csr_matrix mat_C_host = compute_reference_spgemm(mat_A, mat_B); // mat_C_host.print_matrix("C_host"); diff --git a/clients/testing/test_functions_multiply_by_vector.cpp b/clients/testing/test_functions_multiply_by_vector.cpp index 404f1e0..2f7092b 100644 --- a/clients/testing/test_functions_multiply_by_vector.cpp +++ b/clients/testing/test_functions_multiply_by_vector.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -36,7 +36,7 @@ bool testing::test_multiply_by_vector(Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); std::mt19937 generator(1234567); diff --git a/clients/testing/test_functions_ruiz_scaling.cpp b/clients/testing/test_functions_ruiz_scaling.cpp index 387b9f2..c66d672 100644 --- a/clients/testing/test_functions_ruiz_scaling.cpp +++ b/clients/testing/test_functions_ruiz_scaling.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2026 James Sandham +// Copyright(c) 2026-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -40,7 +40,7 @@ bool testing::test_ruiz_scaling(Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); linalg::vector D1(mat_A.get_m()); diff --git a/clients/testing/test_functions_spgeam.cpp b/clients/testing/test_functions_spgeam.cpp index d9ca5e4..e130433 100644 --- a/clients/testing/test_functions_spgeam.cpp +++ b/clients/testing/test_functions_spgeam.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -35,13 +35,13 @@ bool testing::test_spgeam(Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); - linalg::csr_matrix mat_B; + linalg::csr_matrix mat_B; mat_B.copy_from(mat_A); - linalg::csr_matrix mat_C; + linalg::csr_matrix mat_C; auto t1 = std::chrono::high_resolution_clock::now(); mat_A.multiply_by_matrix(mat_C, mat_B); diff --git a/clients/testing/test_functions_sptrsv.cpp b/clients/testing/test_functions_sptrsv.cpp index 36a12c8..391ae62 100644 --- a/clients/testing/test_functions_sptrsv.cpp +++ b/clients/testing/test_functions_sptrsv.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -36,7 +36,7 @@ bool testing::test_sptrsv(Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); linalg::vector vec_x(mat_A.get_n()); diff --git a/clients/testing/test_functions_symmetric_ruiz_scaling.cpp b/clients/testing/test_functions_symmetric_ruiz_scaling.cpp index a268d1c..1722b80 100644 --- a/clients/testing/test_functions_symmetric_ruiz_scaling.cpp +++ b/clients/testing/test_functions_symmetric_ruiz_scaling.cpp @@ -42,7 +42,7 @@ bool testing::test_symmetric_ruiz_scaling(Arguments arg) { std::cout << "max_iters: " << arg.max_iters << " tol: " << arg.tol << std::endl; - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); linalg::vector D(mat_A.get_m()); diff --git a/clients/testing/test_functions_transpose.cpp b/clients/testing/test_functions_transpose.cpp index 4a8ad8a..d462201 100644 --- a/clients/testing/test_functions_transpose.cpp +++ b/clients/testing/test_functions_transpose.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -35,10 +35,10 @@ bool testing::test_transpose(Arguments arg) { - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); - linalg::csr_matrix mat_A_transpose; + linalg::csr_matrix mat_A_transpose; mat_A_transpose.resize(mat_A.get_n(), mat_A.get_m(), mat_A.get_nnz()); diff --git a/clients/testing/test_functions_transpose_dense.cpp b/clients/testing/test_functions_transpose_dense.cpp index ee88ac5..e2a756e 100644 --- a/clients/testing/test_functions_transpose_dense.cpp +++ b/clients/testing/test_functions_transpose_dense.cpp @@ -53,14 +53,14 @@ bool testing::test_transpose_dense(Arguments arg) } } - linalg::csr_matrix mat_A(csr_row_ptr, - csr_col_ind, - csr_val, - arg.m, - arg.m, - arg.m * arg.m); // Assuming a dense matrix for testing + linalg::csr_matrix mat_A(csr_row_ptr, + csr_col_ind, + csr_val, + arg.m, + arg.m, + arg.m * arg.m); // Assuming a dense matrix for testing - linalg::csr_matrix mat_A_transpose; + linalg::csr_matrix mat_A_transpose; mat_A_transpose.resize(mat_A.get_n(), mat_A.get_m(), mat_A.get_nnz()); if(arg.backend == backend::GPU) diff --git a/clients/testing/test_functions_triangular_solve.cpp b/clients/testing/test_functions_triangular_solve.cpp index 253e7af..000c886 100644 --- a/clients/testing/test_functions_triangular_solve.cpp +++ b/clients/testing/test_functions_triangular_solve.cpp @@ -41,12 +41,12 @@ bool testing::test_triangular_solve(Arguments arg) { std::cout << "Testing triangular solve with matrix: " << arg.filename << std::endl; - linalg::csr_matrix mat_A; + linalg::csr_matrix mat_A; mat_A.read_mtx(arg.filename); assert(mat_A.get_m() == mat_A.get_n()); - linalg::csr_matrix mat_B; + linalg::csr_matrix mat_B; switch(arg.uplo) { diff --git a/clients/testing/tests/test_BICGSTAB.yaml b/clients/testing/tests/test_BICGSTAB.yaml index 5b005bf..000c06f 100644 --- a/clients/testing/tests/test_BICGSTAB.yaml +++ b/clients/testing/tests/test_BICGSTAB.yaml @@ -1,6 +1,6 @@ Tests: quick_ci: - precond: [none, jacobi, SOR] + precond: [jacobi, SOR] matrix_file: ["matrices/SPD/nos7/nos7.mtx"] max_iters: [400] backend: [CPU] diff --git a/clients/testing/tests/test_CG.yaml b/clients/testing/tests/test_CG.yaml index c436a79..ffe8fcf 100644 --- a/clients/testing/tests/test_CG.yaml +++ b/clients/testing/tests/test_CG.yaml @@ -1,6 +1,6 @@ Tests: quick_ci: - precond: [none, jacobi, SOR] + precond: [jacobi] matrix_file: ["matrices/SPD/nos7/nos7.mtx"] max_iters: [400] backend: [CPU] diff --git a/library/include/csr_matrix.h b/library/include/csr_matrix.h index ae299a9..12c2ee0 100644 --- a/library/include/csr_matrix.h +++ b/library/include/csr_matrix.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -45,6 +45,7 @@ namespace linalg * The CSR format is efficient for storing and operating on sparse matrices, as it only * stores the non-zero elements along with information about their row and column indices. */ + template class csr_matrix { private: @@ -89,7 +90,7 @@ namespace linalg * non-zero element. The values for the non-zero elements in row `i` are stored * in `csr_val[csr_row_ptr[i] : csr_row_ptr[i+1] - 1]`. */ - vector csr_val; + vector csr_val; /*! \brief Flag indicating if the matrix data is currently on the host (CPU) or device (GPU). */ bool on_host; @@ -109,12 +110,12 @@ namespace linalg * \param n The number of columns in the matrix. * \param nnz The total number of non-zero elements in the matrix. */ - csr_matrix(const std::vector& csr_row_ptr, - const std::vector& csr_col_ind, - const std::vector& csr_val, - int m, - int n, - int nnz); + csr_matrix(const std::vector& csr_row_ptr, + const std::vector& csr_col_ind, + const std::vector& csr_val, + int m, + int n, + int nnz); /*! \brief Destructor. * Cleans up any resources allocated by the CSR matrix. @@ -125,13 +126,13 @@ namespace linalg * Prevents direct copying of `csr_matrix` objects to avoid shallow copies and * ensure proper memory management. Use `copy_from` for explicit copying. */ - csr_matrix(const csr_matrix&) = delete; + csr_matrix(const csr_matrix&) = delete; /*! \brief Deleted copy assignment operator. * Prevents direct assignment of one `csr_matrix` to another to avoid shallow copies * and ensure proper memory management. Use `copy_from` for explicit copying. */ - csr_matrix& operator=(const csr_matrix&) = delete; + csr_matrix& operator=(const csr_matrix&) = delete; /*! \brief Checks if the matrix data is currently stored on the host (CPU). * \return `true` if the matrix data is on the host, `false` otherwise (e.g., on a device). @@ -164,9 +165,9 @@ namespace linalg const int* get_col_ind() const; /*! \brief Returns a constant pointer to the beginning of the values array. - * \return A `const double*` to `csr_val`. + * \return A `const T*` to `csr_val`. */ - const double* get_val() const; + const T* get_val() const; /*! \brief Returns a non-constant pointer to the beginning of the row pointer array. * \return An `int*` to `csr_row_ptr`. This allows modification of the array. @@ -179,9 +180,9 @@ namespace linalg int* get_col_ind(); /*! \brief Returns a non-constant pointer to the beginning of the values array. - * \return A `double*` to `csr_val`. This allows modification of the array. + * \return A `T*` to `csr_val`. This allows modification of the array. */ - double* get_val(); + T* get_val(); /*! \brief Resizes the CSR matrix and reallocates memory for its internal arrays. * @@ -199,7 +200,7 @@ namespace linalg * and values) are duplicated. * \param A The source `csr_matrix` to copy from. */ - void copy_from(const csr_matrix& A); + void copy_from(const csr_matrix& A); /*! \brief Copies the lower triangular portion of another csr_matrix into this object.     * @@ -211,7 +212,7 @@ namespace linalg     * \param A The source csr_matrix to copy from.     * \param unit_diag A flag to specify whether the diagonal should be treated as all ones.     */ - void copy_lower_triangular_from(const csr_matrix& A, bool unit_diag); + void copy_lower_triangular_from(const csr_matrix& A, bool unit_diag); /*! \brief Copies the upper triangular portion of another csr_matrix into this object.     * @@ -223,7 +224,7 @@ namespace linalg     * \param A The source csr_matrix to copy from.     * \param unit_diag A flag to specify whether the diagonal should be treated as all ones.     */ - void copy_upper_triangular_from(const csr_matrix& A, bool unit_diag); + void copy_upper_triangular_from(const csr_matrix& A, bool unit_diag); /*! \brief Moves the matrix data from host memory to device memory (e.g., GPU). * \details This method handles the necessary memory transfers if a device is available @@ -242,7 +243,7 @@ namespace linalg * This method populates the provided `vector` with the diagonal elements of the CSR matrix. * \param diag An output `vector` that will store the diagonal elements. */ - void extract_diagonal(vector& diag) const; + void extract_diagonal(vector& diag) const; /*! \brief Scales the diagonal elements of the matrix by a scalar value. * @@ -250,7 +251,7 @@ namespace linalg * Non-diagonal elements remain unchanged. * \param scalar The scalar value by which to multiply the diagonal elements. */ - void scale_diagonal_by(double scalar); + void scale_diagonal_by(T scalar); /*! \brief Scales the matrix by the inverse of its diagonal elements. * @@ -266,7 +267,7 @@ namespace linalg * \param y The output `vector` to store the result of the multiplication. * \param x The input `vector` to multiply with the matrix. */ - void multiply_by_vector(vector& y, const vector& x) const; + void multiply_by_vector(vector& y, const vector& x) const; /*! \brief Multiplies the CSR matrix by a vector and adds the result: \f$y = y + A \cdot x\f$. * @@ -275,7 +276,7 @@ namespace linalg * it contains the accumulated result. * \param x The input `vector` to multiply with the matrix. */ - void multiply_by_vector_and_add(vector& y, const vector& x) const; + void multiply_by_vector_and_add(vector& y, const vector& x) const; /*! \brief Multiplies this CSR matrix by another CSR matrix: \f$C = A \cdot B\f$. * @@ -283,7 +284,7 @@ namespace linalg * \param C The output `csr_matrix` to store the product \f$A \cdot B\f$. * \param B The right-hand side `csr_matrix` in the multiplication. */ - void multiply_by_matrix(csr_matrix& C, const csr_matrix& B) const; + void multiply_by_matrix(csr_matrix& C, const csr_matrix& B) const; /*! \brief Solves the lower triangular system \f$L \cdot x = y\f$ using forward substitution. * @@ -294,9 +295,7 @@ namespace linalg * \param unit_diag If `true`, the diagonal is assumed to be all ones and its stored * values are ignored. If `false`, the actual diagonal values from the matrix are used. */ - void triangular_solve_lower(vector& x, - const vector& y, - bool unit_diag) const; + void triangular_solve_lower(vector& x, const vector& y, bool unit_diag) const; /*! \brief Solves the upper triangular system \f$U \cdot x = y\f$ using back substitution. * @@ -307,9 +306,7 @@ namespace linalg * \param unit_diag If `true`, the diagonal is assumed to be all ones and its stored * values are ignored. If `false`, the actual diagonal values from the matrix are used. */ - void triangular_solve_upper(vector& x, - const vector& y, - bool unit_diag) const; + void triangular_solve_upper(vector& x, const vector& y, bool unit_diag) const; /*! \brief Compute incomplete Cholesky factorization (IC(0)) in-place. * @@ -363,10 +360,10 @@ namespace linalg * * \param T The output `csr_matrix` that will store the transpose of this matrix. */ - void transpose(csr_matrix& T) const; + void transpose(csr_matrix& T) const; - void apply_ruiz_scaling(vector& D1, vector& D2, int max_k, double tol); - void apply_symmetric_ruiz_scaling(vector& D, int max_k, double tol); + void apply_ruiz_scaling(vector& D1, vector& D2, int max_k, T tol); + void apply_symmetric_ruiz_scaling(vector& D, int max_k, T tol); /*! \brief Reads a sparse matrix from a Matrix Market (.mtx) file into this CSR object. * \param filename The path to the .mtx file. @@ -442,13 +439,13 @@ namespace linalg * \param csr_col_ind Reference to the column indices vector (length nnz). * \param csr_val Reference to the values vector (length nnz). */ - static void print_matrix(const std::string name, - int m, - int n, - int nnz, - const std::vector& csr_row_ptr, - const std::vector& csr_col_ind, - const std::vector& csr_val); + static void print_matrix(const std::string name, + int m, + int n, + int nnz, + const std::vector& csr_row_ptr, + const std::vector& csr_col_ind, + const std::vector& csr_val); }; } diff --git a/library/include/iterative_solvers/amg/amg.h b/library/include/iterative_solvers/amg/amg.h index 92c3159..6fec634 100644 --- a/library/include/iterative_solvers/amg/amg.h +++ b/library/include/iterative_solvers/amg/amg.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -72,8 +72,8 @@ namespace linalg * operators between consecutive levels, where `prolongations[i]` maps from * level `i+1` to level `i`. */ - //std::vector prolongations; - std::array prolongations; + //std::vector> prolongations; + std::array, 20> prolongations; /** * @brief Restriction matrices. @@ -84,8 +84,8 @@ namespace linalg * Typically, the restriction operator is related to the transpose of the * prolongation operator. */ - // std::vector restrictions; - std::array restrictions; + // std::vector> restrictions; + std::array, 20> restrictions; /** * @brief Coarse level matrices. @@ -96,7 +96,7 @@ namespace linalg * The size of these matrices decreases as the level number increases. */ // std::vector A_cs; - std::array A_cs; + std::array, 21> A_cs; /** * @brief Number of levels in the hierarchy. diff --git a/library/include/iterative_solvers/amg/amg_aggregation.h b/library/include/iterative_solvers/amg/amg_aggregation.h index 984a25e..c6f9eca 100644 --- a/library/include/iterative_solvers/amg/amg_aggregation.h +++ b/library/include/iterative_solvers/amg/amg_aggregation.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -63,10 +63,10 @@ namespace linalg * \return `true` if aggregation completed successfully, `false` if the input * data are on mixed backends or aggregation failed. */ - LINALGLIB_API bool compute_aggregates_using_pmis(const csr_matrix& A, - const vector& connections, - vector& aggregates, - vector& aggregate_root_nodes); + LINALGLIB_API bool compute_aggregates_using_pmis(const csr_matrix& A, + const vector& connections, + vector& aggregates, + vector& aggregate_root_nodes); /*! \ingroup iterative_solvers_amg * \brief Compute classical C/F point labels for the first coarsening pass. @@ -80,9 +80,9 @@ namespace linalg * \param cfpoints Output vector of point labels. On return, entries are marked * as coarse, fine, or intermediate states produced by the first pass. */ - LINALGLIB_API void compute_cfpoint_first_pass(const csr_matrix& S, - const csr_matrix& ST, - vector& cfpoints); + LINALGLIB_API void compute_cfpoint_first_pass(const csr_matrix& S, + const csr_matrix& ST, + vector& cfpoints); /*! \ingroup iterative_solvers_amg * \brief Finalize classical C/F point labels in the second coarsening pass. @@ -97,7 +97,8 @@ namespace linalg * the first-pass classification; on output it contains the finalized C/F * labeling. */ - LINALGLIB_API void compute_cfpoint_second_pass(const csr_matrix& S, vector& cfpoints); + LINALGLIB_API void compute_cfpoint_second_pass(const csr_matrix& S, + vector& cfpoints); } /*! @} */ diff --git a/library/include/iterative_solvers/amg/amg_strength.h b/library/include/iterative_solvers/amg/amg_strength.h index b21fd28..a9a7294 100644 --- a/library/include/iterative_solvers/amg/amg_strength.h +++ b/library/include/iterative_solvers/amg/amg_strength.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -56,8 +56,9 @@ namespace linalg * \param eps Strength threshold used to decide whether a connection is strong. * \param connections Output vector encoding the detected strong connections. */ - LINALGLIB_API void - compute_strong_connections(const csr_matrix& A, double eps, vector& connections); + LINALGLIB_API void compute_strong_connections(const csr_matrix& A, + double eps, + vector& connections); /*! \ingroup iterative_solvers_amg * \brief Compute the classical AMG strength matrix. @@ -71,10 +72,10 @@ namespace linalg * \param S Output CSR matrix storing the strength-of-connection pattern. * \param connections Output vector describing strong connections per node. */ - LINALGLIB_API void compute_classical_strong_connections(const csr_matrix& A, - double theta, - csr_matrix& S, - vector& connections); + LINALGLIB_API void compute_classical_strong_connections(const csr_matrix& A, + double theta, + csr_matrix& S, + vector& connections); } /*! @} */ diff --git a/library/include/iterative_solvers/amg/amg_util.h b/library/include/iterative_solvers/amg/amg_util.h index f0cfb0d..c7aff5c 100644 --- a/library/include/iterative_solvers/amg/amg_util.h +++ b/library/include/iterative_solvers/amg/amg_util.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -61,10 +61,10 @@ namespace linalg * where \f$n_f\f$ is the number of degrees of freedom on the fine level and \f$n_c\f$ is the * number of degrees of freedom on the coarse level. */ - LINALGLIB_API void galarkin_triple_product(const csr_matrix& R, - const csr_matrix& A, - const csr_matrix& P, - csr_matrix& A_coarse); + LINALGLIB_API void galarkin_triple_product(const csr_matrix& R, + const csr_matrix& A, + const csr_matrix& P, + csr_matrix& A_coarse); } /*! @} */ diff --git a/library/include/iterative_solvers/amg/rsamg.h b/library/include/iterative_solvers/amg/rsamg.h index 7ce0750..fdb4a55 100644 --- a/library/include/iterative_solvers/amg/rsamg.h +++ b/library/include/iterative_solvers/amg/rsamg.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -192,7 +192,7 @@ namespace linalg * for (int level = 0; level <= max_levels; ++level) { * // Assuming hierarchy has a method to get matrix at a level * // This part is illustrative as hierarchy class structure is not provided - * const csr_matrix& A_level = mg_hierarchy.get_matrix(level); + * const csr_matrix& A_level = mg_hierarchy.get_matrix(level); * std::cout << "Level " << level << ": Matrix size = " << A_level.get_num_rows() << "x" << A_level.get_num_cols() << std::endl; * } * @@ -205,7 +205,8 @@ namespace linalg * } * \endcode */ - LINALGLIB_API void rsamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarchy); + LINALGLIB_API void + rsamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarchy); } /*! @} */ diff --git a/library/include/iterative_solvers/amg/saamg.h b/library/include/iterative_solvers/amg/saamg.h index a432837..e2bcc2f 100644 --- a/library/include/iterative_solvers/amg/saamg.h +++ b/library/include/iterative_solvers/amg/saamg.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -179,7 +179,7 @@ namespace linalg * for (int level = 0; level <= max_levels; ++level) { * // Assuming hierarchy has a method to get matrix at a level * // This part is illustrative as hierarchy class structure is not provided - * const csr_matrix& A_level = mg_hierarchy.get_matrix(level); + * const csr_matrix& A_level = mg_hierarchy.get_matrix(level); * std::cout << "Level " << level << ": Matrix size = " << A_level.get_num_rows() << "x" << A_level.get_num_cols() << std::endl; * } * @@ -192,7 +192,8 @@ namespace linalg * } * \endcode */ - LINALGLIB_API void saamg_setup(const csr_matrix& mat_A, int max_level, hierarchy& hierarchy); + LINALGLIB_API void + saamg_setup(const csr_matrix& mat_A, int max_level, hierarchy& hierarchy); } /*! @} */ diff --git a/library/include/iterative_solvers/amg/uaamg.h b/library/include/iterative_solvers/amg/uaamg.h index 06609bd..bf75c49 100644 --- a/library/include/iterative_solvers/amg/uaamg.h +++ b/library/include/iterative_solvers/amg/uaamg.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -176,7 +176,7 @@ namespace linalg * // Assuming hierarchy has a method to get matrix at a level * // And a method to get prolongation/restriction operators * // This part is illustrative as hierarchy class structure is not provided - * const csr_matrix& A_level = mg_hierarchy.get_matrix(level); + * const csr_matrix& A_level = mg_hierarchy.get_matrix(level); * std::cout << "Level " << level << ": Matrix size = " << A_level.get_num_rows() << "x" << A_level.get_num_cols() << std::endl; * } * @@ -189,7 +189,7 @@ namespace linalg * } * \endcode */ - void uaamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarchy); + void uaamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarchy); } /*! @} */ diff --git a/library/include/iterative_solvers/classic/gauss_seidel.h b/library/include/iterative_solvers/classic/gauss_seidel.h index 6e2914d..8207aea 100644 --- a/library/include/iterative_solvers/classic/gauss_seidel.h +++ b/library/include/iterative_solvers/classic/gauss_seidel.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -195,7 +195,7 @@ namespace linalg * of `A` for efficient division in the iterative step. * \param A The sparse matrix in CSR format for which the solver is being built. */ - void build(const csr_matrix& A); + void build(const csr_matrix& A); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the Gauss-Seidel method. * @@ -213,10 +213,10 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Other negative values for errors (e.g., matrix not diagonally dominant, singular diagonal element). */ - int solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control); + int solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control); }; } diff --git a/library/include/iterative_solvers/classic/jacobi.h b/library/include/iterative_solvers/classic/jacobi.h index 11e64d9..0e20366 100644 --- a/library/include/iterative_solvers/classic/jacobi.h +++ b/library/include/iterative_solvers/classic/jacobi.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -203,7 +203,7 @@ namespace linalg * the inverse of the diagonal elements. * \param A The sparse matrix in CSR format for which the solver is being built. */ - void build(const csr_matrix& A); + void build(const csr_matrix& A); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the Jacobi method. * @@ -221,10 +221,10 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Other negative values for errors (e.g., singular diagonal element). */ - int solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control); + int solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control); }; } diff --git a/library/include/iterative_solvers/classic/richardson.h b/library/include/iterative_solvers/classic/richardson.h index 6d74bd0..1fc6f2f 100644 --- a/library/include/iterative_solvers/classic/richardson.h +++ b/library/include/iterative_solvers/classic/richardson.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -194,7 +194,7 @@ namespace linalg * or a copy of the matrix `A` if needed for residual computation. * \param A The sparse matrix in CSR format for which the solver is being built. */ - void build(const csr_matrix& A); + void build(const csr_matrix& A); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the Richardson method. * @@ -213,11 +213,11 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Other negative values for errors (e.g., invalid input). */ - int solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control, - double theta); + int solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control, + double theta); }; } diff --git a/library/include/iterative_solvers/classic/sor.h b/library/include/iterative_solvers/classic/sor.h index 3120b16..344549d 100644 --- a/library/include/iterative_solvers/classic/sor.h +++ b/library/include/iterative_solvers/classic/sor.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -196,7 +196,7 @@ namespace linalg * in the SOR iteration. * \param A The sparse matrix in CSR format for which the solver is being built. */ - void build(const csr_matrix& A); + void build(const csr_matrix& A); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the Successive Over-Relaxation (SOR) method. * @@ -215,11 +215,11 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Other negative values for errors (e.g., invalid omega, singular diagonal element). */ - int solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control, - double omega); + int solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control, + double omega); }; } diff --git a/library/include/iterative_solvers/classic/ssor.h b/library/include/iterative_solvers/classic/ssor.h index 49efca6..2ca6eea 100644 --- a/library/include/iterative_solvers/classic/ssor.h +++ b/library/include/iterative_solvers/classic/ssor.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -189,7 +189,7 @@ namespace linalg * SSOR iteration. * \param A The sparse matrix in CSR format for which the solver is being built. */ - void build(const csr_matrix& A); + void build(const csr_matrix& A); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the Symmetric Successive Over-Relaxation (SSOR) method. * @@ -209,11 +209,11 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Other negative values for errors (e.g., invalid omega, singular diagonal element). */ - int solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control, - double omega); + int solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control, + double omega); }; } diff --git a/library/include/iterative_solvers/classic/symmetric_gauss_seidel.h b/library/include/iterative_solvers/classic/symmetric_gauss_seidel.h index 1162dc7..884b2f7 100644 --- a/library/include/iterative_solvers/classic/symmetric_gauss_seidel.h +++ b/library/include/iterative_solvers/classic/symmetric_gauss_seidel.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -188,7 +188,7 @@ namespace linalg * include extracting the diagonal elements and setting up for triangular solves. * \param A The sparse matrix in CSR format for which the solver is being built. */ - void build(const csr_matrix& A); + void build(const csr_matrix& A); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the Symmetric Gauss-Seidel (SGS) method. * @@ -207,10 +207,10 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Other negative values for errors (e.g., singular diagonal element). */ - int solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control); + int solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control); }; } diff --git a/library/include/iterative_solvers/krylov/bicgstab.h b/library/include/iterative_solvers/krylov/bicgstab.h index cc0867d..237fd2c 100644 --- a/library/include/iterative_solvers/krylov/bicgstab.h +++ b/library/include/iterative_solvers/krylov/bicgstab.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024-2025 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -253,7 +253,7 @@ namespace linalg * of the matrix `A`. * \param A The sparse matrix in CSR format for which the solver is being built. */ - void build(const csr_matrix& A); + void build(const csr_matrix& A); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the non-preconditioned BiCGSTAB method. * @@ -271,10 +271,10 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Negative values indicate potential breakdowns (e.g., division by zero due to loss of orthogonality). */ - int solve_nonprecond(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control); + int solve_nonprecond(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the preconditioned BiCGSTAB method. * @@ -294,11 +294,11 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Negative values indicate potential breakdowns or issues with the preconditioner. */ - int solve_precond(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control); + int solve_precond(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control); /*! \brief Generic solve method for the BiCGSTAB solver (delegates to non-preconditioned or preconditioned). * @@ -313,11 +313,11 @@ namespace linalg * including convergence tolerance and maximum iterations. * \return An integer status code, consistent with `solve_nonprecond` or `solve_precond`. */ - int solve(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control); + int solve(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control); /** * @brief Moves data from device memory to host memory. diff --git a/library/include/iterative_solvers/krylov/cg.h b/library/include/iterative_solvers/krylov/cg.h index a7db738..78bd376 100644 --- a/library/include/iterative_solvers/krylov/cg.h +++ b/library/include/iterative_solvers/krylov/cg.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024-2025 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -237,7 +237,7 @@ namespace linalg * work vectors (`z`, `p`, `res`) to match the dimensions of the matrix `A`. * \param A The sparse matrix in CSR format for which the solver is being built. */ - void build(const csr_matrix& A); + void build(const csr_matrix& A); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the non-preconditioned Conjugate Gradient method. * @@ -257,10 +257,10 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Negative values might indicate issues like a non-positive definite matrix or division by zero. */ - int solve_nonprecond(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control); + int solve_nonprecond(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the preconditioned Conjugate Gradient method. * @@ -283,11 +283,11 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Negative values might indicate issues with the matrix, preconditioner, or numerical stability. */ - int solve_precond(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control); + int solve_precond(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control); /*! \brief Generic solve method for the Conjugate Gradient solver (delegates to non-preconditioned or preconditioned). * @@ -304,11 +304,11 @@ namespace linalg * including convergence tolerance and maximum iterations. * \return An integer status code, consistent with `solve_nonprecond` or `solve_precond`. */ - int solve(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control); + int solve(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control); /** * @brief Moves data from device memory to host memory. diff --git a/library/include/iterative_solvers/krylov/gmres.h b/library/include/iterative_solvers/krylov/gmres.h index efbaabd..59dc5d1 100644 --- a/library/include/iterative_solvers/krylov/gmres.h +++ b/library/include/iterative_solvers/krylov/gmres.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019-2025 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -278,7 +278,7 @@ namespace linalg * \param A The sparse matrix in CSR format for which the solver is being built. * \param restart The restart parameter `m` for GMRES(m). */ - void build(const csr_matrix& A, int restart); + void build(const csr_matrix& A, int restart); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the non-preconditioned GMRES method. * @@ -296,10 +296,10 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Negative values indicate potential breakdowns (e.g., null vectors). */ - int solve_nonprecond(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control); + int solve_nonprecond(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control); /*! \brief Solves the linear system \f$A \cdot x = b\f$ using the preconditioned GMRES method. * @@ -319,11 +319,11 @@ namespace linalg * - `1` if the maximum number of iterations was reached without convergence. * - Negative values indicate potential breakdowns or issues with the preconditioner. */ - int solve_precond(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control); + int solve_precond(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control); /*! \brief Generic solve method for the GMRES solver (delegates to non-preconditioned or preconditioned). * @@ -338,11 +338,11 @@ namespace linalg * including convergence tolerance and total maximum iterations. * \return An integer status code, consistent with `solve_nonprecond` or `solve_precond`. */ - int solve(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control); + int solve(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control); }; } diff --git a/library/include/iterative_solvers/preconditioner/preconditioner.h b/library/include/iterative_solvers/preconditioner/preconditioner.h index 7c022bd..4a12011 100644 --- a/library/include/iterative_solvers/preconditioner/preconditioner.h +++ b/library/include/iterative_solvers/preconditioner/preconditioner.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -68,7 +68,7 @@ namespace linalg * * \param A The input matrix for which the preconditioner is to be built. */ - virtual void build(const csr_matrix& A) = 0; + virtual void build(const csr_matrix& A) = 0; /*! \brief Solves the preconditioning system M*x = rhs. * @@ -128,7 +128,7 @@ namespace linalg * of the input matrix `A`. * \param A The input matrix for which the preconditioner is to be built. */ - void build(const csr_matrix& A) override; + void build(const csr_matrix& A) override; /*! \brief Solves the preconditioning system \f$M \cdot x = \text{rhs}\f$. * @@ -176,8 +176,8 @@ namespace linalg * \details The Gauss-Seidel preconditioner requires access to the * lower triangular part of the original matrix during the solve phase. */ - csr_matrix M; - csrtrsv_descr* descr_M; + csr_matrix M; + csrtrsv_descr* descr_M; /*! \brief Flag indicating if the preconditioner data is currently on the host (CPU) or device (GPU). */ bool on_host; @@ -196,7 +196,7 @@ namespace linalg * part of the original matrix. * \param A The input matrix for which the preconditioner is to be built. */ - void build(const csr_matrix& A) override; + void build(const csr_matrix& A) override; /*! \brief Solves the preconditioning system \f$M \cdot x = \text{rhs}\f$ using forward substitution. * @@ -242,8 +242,8 @@ namespace linalg /*! \brief The relaxation parameter (\f$\omega\f$) for SOR. */ double omega; - csr_matrix M; - csrtrsv_descr* descr_M; + csr_matrix M; + csrtrsv_descr* descr_M; /*! \brief Flag indicating if the preconditioner data is currently on the host (CPU) or device (GPU). */ bool on_host; @@ -264,7 +264,7 @@ namespace linalg * that are used in the SOR solve. * \param A The input matrix for which the preconditioner is to be built. */ - void build(const csr_matrix& A) override; + void build(const csr_matrix& A) override; /*! \brief Solves the preconditioning system \f$M \cdot x = \text{rhs}\f$ using the SOR method. * @@ -305,10 +305,10 @@ namespace linalg class symmetric_gauss_seidel_precond : public preconditioner { private: - csr_matrix L; - csr_matrix U; - csrtrsv_descr* descr_L; - csrtrsv_descr* descr_U; + csr_matrix L; + csr_matrix U; + csrtrsv_descr* descr_L; + csrtrsv_descr* descr_U; /*! \brief Flag indicating if the preconditioner data is currently on the host (CPU) or device (GPU). */ bool on_host; @@ -326,7 +326,7 @@ namespace linalg * pre-calculating the diagonal elements needed for the SGS sweeps. * \param A The input matrix for which the preconditioner is to be built. */ - void build(const csr_matrix& A) override; + void build(const csr_matrix& A) override; /*! \brief Solves the preconditioning system \f$M \cdot x = \text{rhs}\f$ using Symmetric Gauss-Seidel. * @@ -373,10 +373,10 @@ namespace linalg // vector y; - csr_matrix L; - csr_matrix U; - csrtrsv_descr* descr_L; - csrtrsv_descr* descr_U; + csr_matrix L; + csr_matrix U; + csrtrsv_descr* descr_L; + csrtrsv_descr* descr_U; /*! \brief Flag indicating if the preconditioner data is currently on the host (CPU) or device (GPU). */ bool on_host; @@ -394,7 +394,7 @@ namespace linalg * * \param A The input matrix for which the preconditioner is to be built. */ - void build(const csr_matrix& A) override; + void build(const csr_matrix& A) override; /*! \brief Solves the preconditioning system \f$M \cdot x = \text{rhs}\f$ using the SSOR method. * @@ -443,7 +443,7 @@ namespace linalg * of both L (lower triangular) and U (upper triangular) factors, * potentially in a merged format. */ - csr_matrix LU; + csr_matrix LU; csrilu0_descr* descr_ILU; @@ -467,7 +467,7 @@ namespace linalg * is determined by the internal implementation of this method. * \param A The input matrix for which the preconditioner is to be built. */ - void build(const csr_matrix& A) override; + void build(const csr_matrix& A) override; /*! \brief Solves the preconditioning system \f$M \cdot x = \text{rhs}\f$ using the ILU factors. * @@ -516,7 +516,7 @@ namespace linalg * \details For a symmetric positive definite matrix, the `LLT` matrix * will store the lower triangular factor L. */ - csr_matrix LLT; + csr_matrix LLT; csric0_descr* descr_IC; @@ -541,7 +541,7 @@ namespace linalg * internal implementation of this method. * \param A The input symmetric positive definite matrix for which the preconditioner is to be built. */ - void build(const csr_matrix& A) override; + void build(const csr_matrix& A) override; /*! \brief Solves the preconditioning system \f$M \cdot x = \text{rhs}\f$ using the IC factors. * @@ -583,7 +583,7 @@ namespace linalg { private: /*! \brief Stores the lower triangular factor L from the iterative ILU factorization. */ - csr_matrix L; + csr_matrix L; /*! \brief Flag indicating if the preconditioner data is currently on the host (CPU) or device (GPU). */ bool on_host; @@ -601,7 +601,7 @@ namespace linalg * of the input matrix `A`. * \param A The input matrix for which the preconditioner is to be built. */ - void build(const csr_matrix& A) override; + void build(const csr_matrix& A) override; /*! \brief Solves the preconditioning system \f$M \cdot x = \text{rhs}\f$ using the iterative ILU factors. * diff --git a/library/include/linalg_math.h b/library/include/linalg_math.h index 6c361be..e697ae3 100644 --- a/library/include/linalg_math.h +++ b/library/include/linalg_math.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -92,7 +92,7 @@ namespace linalg * @param numeric_zero An optional pointer to an integer that will be set to 1 if a numeric zero * (pivot element is zero) is encountered during factorization, 0 otherwise. Can be `nullptr`. */ - LINALGLIB_API void csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero); + LINALGLIB_API void csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero); /** * @brief Performs an Incomplete LU (ILU) factorization with zero fill-in (ILU(0)). @@ -106,7 +106,7 @@ namespace linalg * @param numeric_zero An optional pointer to an integer that will be set to 1 if a numeric zero * (pivot element is zero) is encountered during factorization, 0 otherwise. Can be `nullptr`. */ - LINALGLIB_API void csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero); + LINALGLIB_API void csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero); /** * @brief Computes the transpose of a CSR matrix. @@ -116,7 +116,8 @@ namespace linalg * @param A The input `csr_matrix` to transpose. * @param transposeA The output `csr_matrix` to store the transposed matrix. */ - LINALGLIB_API void transpose_matrix(const csr_matrix& A, csr_matrix& transposeA); + LINALGLIB_API void transpose_matrix(const csr_matrix& A, + csr_matrix& transposeA); /** * @brief Computes the dot product of two vectors. @@ -140,10 +141,10 @@ namespace linalg * @param b The input right-hand side vector \f$b\f$. * @param res The output vector to store the computed residual $res$. */ - LINALGLIB_API void compute_residual(const csr_matrix& A, - const vector& x, - const vector& b, - vector& res); + LINALGLIB_API void compute_residual(const csr_matrix& A, + const vector& x, + const vector& b, + vector& res); /** * @brief Extracts the diagonal entries of a CSR matrix. @@ -151,7 +152,7 @@ namespace linalg * @param A The input `csr_matrix` from which to extract the diagonal. * @param d The output vector that will store the diagonal elements. */ - LINALGLIB_API void diagonal(const csr_matrix& A, vector& d); + LINALGLIB_API void diagonal(const csr_matrix& A, vector& d); /** * @brief Computes the Euclidean (L2) norm of a vector. @@ -225,10 +226,10 @@ namespace linalg * @param descr The descriptor to populate with analysis results. * @see csrtrsv_solve */ - LINALGLIB_API void csrtrsv_analysis(const csr_matrix& A, - triangular_type tri_type, - diagonal_type diag_type, - csrtrsv_descr* descr); + LINALGLIB_API void csrtrsv_analysis(const csr_matrix& A, + triangular_type tri_type, + diagonal_type diag_type, + csrtrsv_descr* descr); /** * @brief Solves a triangular system \f$A \cdot x = \alpha \cdot b\f$ using CSR format. @@ -244,13 +245,13 @@ namespace linalg * @param descr The descriptor populated by a prior csrtrsv_analysis() call. * @see csrtrsv_analysis */ - LINALGLIB_API void csrtrsv_solve(const csr_matrix& A, - const vector& b, - vector& x, - double alpha, - triangular_type tri_type, - diagonal_type diag_type, - const csrtrsv_descr* descr); + LINALGLIB_API void csrtrsv_solve(const csr_matrix& A, + const vector& b, + vector& x, + double alpha, + triangular_type tri_type, + diagonal_type diag_type, + const csrtrsv_descr* descr); /** * @brief Creates an opaque descriptor for CSR matrix-vector product operations. @@ -283,7 +284,8 @@ namespace linalg * @param descr The descriptor to populate with analysis results. * @see csrmv_solve */ - LINALGLIB_API void csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr); + LINALGLIB_API void + csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr); /** * @brief Computes a CSR matrix-vector product \f$y = \alpha A x + \beta y\f$. @@ -299,13 +301,13 @@ namespace linalg * @param descr The descriptor populated by a prior csrmv_analysis() call. * @see csrmv_analysis */ - LINALGLIB_API void csrmv_solve(double alpha, - const csr_matrix& A, - const vector& x, - double beta, - vector& y, - csrmv_algorithm alg, - const csrmv_descr* descr); + LINALGLIB_API void csrmv_solve(double alpha, + const csr_matrix& A, + const vector& x, + double beta, + vector& y, + csrmv_algorithm alg, + const csrmv_descr* descr); /** * @brief Creates an opaque descriptor for CSR matrix-matrix addition operations. @@ -340,11 +342,11 @@ namespace linalg * @param descr The descriptor to populate with analysis results. * @see csrgeam_solve */ - LINALGLIB_API void csrgeam_nnz(const csr_matrix& A, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - csrgeam_descr* descr); + LINALGLIB_API void csrgeam_nnz(const csr_matrix& A, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + csrgeam_descr* descr); /** * @brief Computes CSR matrix-matrix addition \f$C = \alpha A + \beta B\f$. @@ -361,13 +363,13 @@ namespace linalg * @param descr The descriptor populated by a prior csrgeam_nnz() call. * @see csrgeam_nnz */ - LINALGLIB_API void csrgeam_solve(double alpha, - const csr_matrix& A, - double beta, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - const csrgeam_descr* descr); + LINALGLIB_API void csrgeam_solve(double alpha, + const csr_matrix& A, + double beta, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + const csrgeam_descr* descr); /** * @brief Creates an opaque descriptor for CSR matrix-matrix multiplication operations. @@ -403,12 +405,12 @@ namespace linalg * @param descr The descriptor to populate with analysis results. * @see csrgemm_solve */ - LINALGLIB_API void csrgemm_nnz(const csr_matrix& A, - const csr_matrix& B, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - csrgemm_descr* descr); + LINALGLIB_API void csrgemm_nnz(const csr_matrix& A, + const csr_matrix& B, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + csrgemm_descr* descr); /** * @brief Computes CSR matrix-matrix multiplication \f$C = \alpha A \cdot B + \beta D\f$. @@ -426,14 +428,14 @@ namespace linalg * @param descr The descriptor populated by a prior csrgemm_nnz() call. * @see csrgemm_nnz */ - LINALGLIB_API void csrgemm_solve(double alpha, - const csr_matrix& A, - const csr_matrix& B, - double beta, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - const csrgemm_descr* descr); + LINALGLIB_API void csrgemm_solve(double alpha, + const csr_matrix& A, + const csr_matrix& B, + double beta, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + const csrgemm_descr* descr); /** * @brief Creates an opaque descriptor for CSR incomplete Cholesky (IC(0)) factorization. @@ -464,7 +466,7 @@ namespace linalg * @param descr The descriptor to populate with analysis results. * @see csric0_compute */ - LINALGLIB_API void csric0_analysis(const csr_matrix& A, csric0_descr* descr); + LINALGLIB_API void csric0_analysis(const csr_matrix& A, csric0_descr* descr); /** * @brief Compute an inplace CSR incomplete Cholesky (IC(0)) factorization. @@ -474,7 +476,7 @@ namespace linalg * @param descr The descriptor populated by a prior csric0_analysis() call. * @see csric0_analysis */ - LINALGLIB_API void csric0_compute(csr_matrix& A, const csric0_descr* descr); + LINALGLIB_API void csric0_compute(csr_matrix& A, const csric0_descr* descr); /** * @brief Creates an opaque descriptor for CSR incomplete LU (ILU(0)) factorization. @@ -505,7 +507,7 @@ namespace linalg * @param descr The descriptor to populate with analysis results. * @see csrilu0_compute */ - LINALGLIB_API void csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr); + LINALGLIB_API void csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr); /** * @brief Compute an inplace CSR incomplete LU (ILU(0)) factorization. @@ -515,7 +517,7 @@ namespace linalg * @param descr The descriptor populated by a prior csrilu0_analysis() call. * @see csrilu0_analysis */ - LINALGLIB_API void csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr); + LINALGLIB_API void csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr); } #endif diff --git a/library/src/backend/device/device_amg_aggregation.cpp b/library/src/backend/device/device_amg_aggregation.cpp index f83f83e..0cc569c 100644 --- a/library/src/backend/device/device_amg_aggregation.cpp +++ b/library/src/backend/device/device_amg_aggregation.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -34,10 +34,10 @@ #include "cuda/cuda_amg_aggregation.h" #endif -void linalg::device_initialize_pmis_state(const csr_matrix& A, - const vector& connections, - vector& state, - vector& hash) +void linalg::device_initialize_pmis_state(const csr_matrix& A, + const vector& connections, + vector& state, + vector& hash) { ROUTINE_TRACE("linalg::device_initialize_pmis_state"); @@ -67,13 +67,13 @@ void linalg::device_initialize_pmis_state(const csr_matrix& A, // hash.get_vec()); } -void linalg::device_find_maximum_distance_two_node(const csr_matrix& A, - const vector& connections, - const vector& state, - const vector& hash, - vector& aggregates, - vector& max_state, - bool& complete) +void linalg::device_find_maximum_distance_two_node(const csr_matrix& A, + const vector& connections, + const vector& state, + const vector& hash, + vector& aggregates, + vector& max_state, + bool& complete) { ROUTINE_TRACE("linalg::device_find_maximum_distance_two_node"); @@ -112,12 +112,12 @@ void linalg::device_find_maximum_distance_two_node(const csr_matrix& A, } void linalg::device_add_unassigned_nodes_to_closest_aggregation( - const csr_matrix& A, - const vector& connections, - const vector& state, - vector& aggregates, - vector& aggregate_root_nodes, - vector& max_state) + const csr_matrix& A, + const vector& connections, + const vector& state, + vector& aggregates, + vector& aggregate_root_nodes, + vector& max_state) { ROUTINE_TRACE("linalg::device_add_unassigned_nodes_to_closest_aggregation"); @@ -153,10 +153,13 @@ void linalg::device_add_unassigned_nodes_to_closest_aggregation( // max_state.get_vec()); } -void linalg::device_compute_cfpoint_first_pass(const csr_matrix& S, - const csr_matrix& ST, - vector& cfpoints) +void linalg::device_compute_cfpoint_first_pass(const csr_matrix& S, + const csr_matrix& ST, + vector& cfpoints) { } -void linalg::device_compute_cfpoint_second_pass(const csr_matrix& S, vector& cfpoints) {} \ No newline at end of file +void linalg::device_compute_cfpoint_second_pass(const csr_matrix& S, + vector& cfpoints) +{ +} diff --git a/library/src/backend/device/device_amg_aggregation.h b/library/src/backend/device/device_amg_aggregation.h index 106cc0c..ec99604 100644 --- a/library/src/backend/device/device_amg_aggregation.h +++ b/library/src/backend/device/device_amg_aggregation.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -37,31 +37,32 @@ namespace linalg { // - void device_initialize_pmis_state(const csr_matrix& A, - const vector& connections, - vector& state, - vector& hash); + void device_initialize_pmis_state(const csr_matrix& A, + const vector& connections, + vector& state, + vector& hash); - void device_find_maximum_distance_two_node(const csr_matrix& A, - const vector& connections, - const vector& state, - const vector& hash, - vector& aggregates, - vector& max_state, - bool& complete); + void device_find_maximum_distance_two_node(const csr_matrix& A, + const vector& connections, + const vector& state, + const vector& hash, + vector& aggregates, + vector& max_state, + bool& complete); - void device_add_unassigned_nodes_to_closest_aggregation(const csr_matrix& A, - const vector& connections, - const vector& state, - vector& aggregates, - vector& aggregate_root_nodes, - vector& max_state); + void device_add_unassigned_nodes_to_closest_aggregation(const csr_matrix& A, + const vector& connections, + const vector& state, + vector& aggregates, + vector& aggregate_root_nodes, + vector& max_state); - void device_compute_cfpoint_first_pass(const csr_matrix& S, - const csr_matrix& ST, - vector& cfpoints); + void device_compute_cfpoint_first_pass(const csr_matrix& S, + const csr_matrix& ST, + vector& cfpoints); - void device_compute_cfpoint_second_pass(const csr_matrix& S, vector& cfpoints); + void device_compute_cfpoint_second_pass(const csr_matrix& S, + vector& cfpoints); } -#endif \ No newline at end of file +#endif diff --git a/library/src/backend/device/device_amg_strength.cpp b/library/src/backend/device/device_amg_strength.cpp index 5fa1bdb..16997dd 100644 --- a/library/src/backend/device/device_amg_strength.cpp +++ b/library/src/backend/device/device_amg_strength.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -33,9 +33,9 @@ #include "cuda/cuda_amg_strength.h" #endif -void linalg::device_compute_strong_connections(const csr_matrix& A, - double eps, - vector& connections) +void linalg::device_compute_strong_connections(const csr_matrix& A, + double eps, + vector& connections) { ROUTINE_TRACE("linalg::device_compute_strong_connections"); @@ -75,10 +75,10 @@ void linalg::device_compute_strong_connections(const csr_matrix& A, // connections.get_vec()); } -void linalg::device_compute_classical_strong_connections(const csr_matrix& A, - double theta, - csr_matrix& S, - vector& connections) +void linalg::device_compute_classical_strong_connections(const csr_matrix& A, + double theta, + csr_matrix& S, + vector& connections) { ROUTINE_TRACE("linalg::device_compute_classical_strong_connections"); @@ -114,4 +114,4 @@ void linalg::device_compute_classical_strong_connections(const csr_matrix& A, // S.get_col_ind(), // S.get_val(), // connections.get_vec()); -} \ No newline at end of file +} diff --git a/library/src/backend/device/device_amg_strength.h b/library/src/backend/device/device_amg_strength.h index 9f036ac..495d901 100644 --- a/library/src/backend/device/device_amg_strength.h +++ b/library/src/backend/device/device_amg_strength.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -32,14 +32,14 @@ namespace linalg { - void device_compute_strong_connections(const csr_matrix& A, - double eps, - vector& connections); + void device_compute_strong_connections(const csr_matrix& A, + double eps, + vector& connections); - void device_compute_classical_strong_connections(const csr_matrix& A, - double theta, - csr_matrix& S, - vector& connections); + void device_compute_classical_strong_connections(const csr_matrix& A, + double theta, + csr_matrix& S, + vector& connections); } -#endif \ No newline at end of file +#endif diff --git a/library/src/backend/device/device_csr2csc.cpp b/library/src/backend/device/device_csr2csc.cpp index de62a13..ba6661a 100644 --- a/library/src/backend/device/device_csr2csc.cpp +++ b/library/src/backend/device/device_csr2csc.cpp @@ -37,7 +37,7 @@ #include "cuda/cuda_memory.h" #endif -void linalg::device_transpose_matrix(const csr_matrix& A, csr_matrix& transposeA) +void linalg::device_transpose_matrix(const csr_matrix& A, csr_matrix& transposeA) { ROUTINE_TRACE("linalg::device_transpose_matrix"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_csr2csc.h b/library/src/backend/device/device_csr2csc.h index fb5b749..5da7c29 100644 --- a/library/src/backend/device/device_csr2csc.h +++ b/library/src/backend/device/device_csr2csc.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -30,7 +30,7 @@ namespace linalg { - void device_transpose_matrix(const csr_matrix& A, csr_matrix& transposeA); + void device_transpose_matrix(const csr_matrix& A, csr_matrix& transposeA); } #endif diff --git a/library/src/backend/device/device_csrgeam.cpp b/library/src/backend/device/device_csrgeam.cpp index 11b2562..c92fc83 100644 --- a/library/src/backend/device/device_csrgeam.cpp +++ b/library/src/backend/device/device_csrgeam.cpp @@ -49,11 +49,11 @@ void linalg::free_csrgeam_device_data(csrgeam_descr* descr) } } -void linalg::device_csrgeam_nnz(const csr_matrix& A, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - csrgeam_descr* descr) +void linalg::device_csrgeam_nnz(const csr_matrix& A, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + csrgeam_descr* descr) { ROUTINE_TRACE("linalg::device_csrgeam_nnz"); if constexpr(is_cuda_available()) @@ -81,13 +81,13 @@ void linalg::device_csrgeam_nnz(const csr_matrix& A, } } -void linalg::device_csrgeam_solve(double alpha, - const csr_matrix& A, - double beta, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - const csrgeam_descr* descr) +void linalg::device_csrgeam_solve(double alpha, + const csr_matrix& A, + double beta, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + const csrgeam_descr* descr) { ROUTINE_TRACE("linalg::device_csrgeam_solve"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_csrgeam.h b/library/src/backend/device/device_csrgeam.h index 448deb9..7afac0e 100644 --- a/library/src/backend/device/device_csrgeam.h +++ b/library/src/backend/device/device_csrgeam.h @@ -35,18 +35,18 @@ namespace linalg struct csrgeam_descr; void free_csrgeam_device_data(csrgeam_descr* descr); - void device_csrgeam_nnz(const csr_matrix& A, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - csrgeam_descr* descr); - void device_csrgeam_solve(double alpha, - const csr_matrix& A, - double beta, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - const csrgeam_descr* descr); + void device_csrgeam_nnz(const csr_matrix& A, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + csrgeam_descr* descr); + void device_csrgeam_solve(double alpha, + const csr_matrix& A, + double beta, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + const csrgeam_descr* descr); } #endif diff --git a/library/src/backend/device/device_csrgemm.cpp b/library/src/backend/device/device_csrgemm.cpp index 010870b..84085de 100644 --- a/library/src/backend/device/device_csrgemm.cpp +++ b/library/src/backend/device/device_csrgemm.cpp @@ -49,12 +49,12 @@ void linalg::free_csrgemm_device_data(csrgemm_descr* descr) } } -void linalg::device_csrgemm_nnz(const csr_matrix& A, - const csr_matrix& B, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - csrgemm_descr* descr) +void linalg::device_csrgemm_nnz(const csr_matrix& A, + const csr_matrix& B, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + csrgemm_descr* descr) { ROUTINE_TRACE("linalg::device_csrgemm_nnz"); if constexpr(is_cuda_available()) @@ -95,14 +95,14 @@ void linalg::device_csrgemm_nnz(const csr_matrix& A, } } -void linalg::device_csrgemm_solve(double alpha, - const csr_matrix& A, - const csr_matrix& B, - double beta, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - const csrgemm_descr* descr) +void linalg::device_csrgemm_solve(double alpha, + const csr_matrix& A, + const csr_matrix& B, + double beta, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + const csrgemm_descr* descr) { ROUTINE_TRACE("linalg::device_csrgemm_solve"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_csrgemm.h b/library/src/backend/device/device_csrgemm.h index 9440e03..d919072 100644 --- a/library/src/backend/device/device_csrgemm.h +++ b/library/src/backend/device/device_csrgemm.h @@ -35,20 +35,20 @@ namespace linalg struct csrgemm_descr; void free_csrgemm_device_data(csrgemm_descr* descr); - void device_csrgemm_nnz(const csr_matrix& A, - const csr_matrix& B, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - csrgemm_descr* descr); - void device_csrgemm_solve(double alpha, - const csr_matrix& A, - const csr_matrix& B, - double beta, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - const csrgemm_descr* descr); + void device_csrgemm_nnz(const csr_matrix& A, + const csr_matrix& B, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + csrgemm_descr* descr); + void device_csrgemm_solve(double alpha, + const csr_matrix& A, + const csr_matrix& B, + double beta, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + const csrgemm_descr* descr); } #endif diff --git a/library/src/backend/device/device_csric0.cpp b/library/src/backend/device/device_csric0.cpp index b8ca815..f9acf63 100644 --- a/library/src/backend/device/device_csric0.cpp +++ b/library/src/backend/device/device_csric0.cpp @@ -35,7 +35,7 @@ #include "cuda/cuda_csric0.h" #endif -void linalg::device_csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero) +void linalg::device_csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero) { std::cout << "Error: csric0 on device not implemented" << std::endl; } @@ -54,7 +54,7 @@ void linalg::free_csric0_device_data(csric0_descr* descr) } } -void linalg::device_csric0_analysis(const csr_matrix& A, csric0_descr* descr) +void linalg::device_csric0_analysis(const csr_matrix& A, csric0_descr* descr) { ROUTINE_TRACE("linalg::device_csric0_analysis"); if constexpr(is_cuda_available()) @@ -74,7 +74,7 @@ void linalg::device_csric0_analysis(const csr_matrix& A, csric0_descr* descr) } } -void linalg::device_csric0_compute(csr_matrix& A, const csric0_descr* descr) +void linalg::device_csric0_compute(csr_matrix& A, const csric0_descr* descr) { ROUTINE_TRACE("linalg::device_csric0_compute"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_csric0.h b/library/src/backend/device/device_csric0.h index aff0058..1a25181 100644 --- a/library/src/backend/device/device_csric0.h +++ b/library/src/backend/device/device_csric0.h @@ -31,13 +31,13 @@ namespace linalg { - void device_csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero); + void device_csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero); struct csric0_descr; void free_csric0_device_data(csric0_descr* descr); - void device_csric0_analysis(const csr_matrix& A, csric0_descr* descr); - void device_csric0_compute(csr_matrix& A, const csric0_descr* descr); + void device_csric0_analysis(const csr_matrix& A, csric0_descr* descr); + void device_csric0_compute(csr_matrix& A, const csric0_descr* descr); } #endif diff --git a/library/src/backend/device/device_csrilu0.cpp b/library/src/backend/device/device_csrilu0.cpp index 6221324..a2cdb65 100644 --- a/library/src/backend/device/device_csrilu0.cpp +++ b/library/src/backend/device/device_csrilu0.cpp @@ -35,7 +35,7 @@ #include "cuda/cuda_csrilu0.h" #endif -void linalg::device_csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero) +void linalg::device_csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero) { std::cout << "Error: csrilu0 on device not implemented" << std::endl; } @@ -54,7 +54,7 @@ void linalg::free_csrilu0_device_data(csrilu0_descr* descr) } } -void linalg::device_csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr) +void linalg::device_csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr) { ROUTINE_TRACE("linalg::device_csrilu0_analysis"); if constexpr(is_cuda_available()) @@ -74,7 +74,7 @@ void linalg::device_csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr) } } -void linalg::device_csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr) +void linalg::device_csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr) { ROUTINE_TRACE("linalg::device_csrilu0_compute"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_csrilu0.h b/library/src/backend/device/device_csrilu0.h index 5b44fa6..5036b53 100644 --- a/library/src/backend/device/device_csrilu0.h +++ b/library/src/backend/device/device_csrilu0.h @@ -31,13 +31,13 @@ namespace linalg { - void device_csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero); + void device_csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero); struct csrilu0_descr; void free_csrilu0_device_data(csrilu0_descr* descr); - void device_csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr); - void device_csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr); + void device_csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr); + void device_csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr); } #endif diff --git a/library/src/backend/device/device_csrtrsv.cpp b/library/src/backend/device/device_csrtrsv.cpp index b84cdae..6db3ca8 100644 --- a/library/src/backend/device/device_csrtrsv.cpp +++ b/library/src/backend/device/device_csrtrsv.cpp @@ -49,10 +49,10 @@ void linalg::free_csrtrsv_device_data(csrtrsv_descr* descr) } } -void linalg::device_csrtrsv_analysis(const csr_matrix& A, - triangular_type tri_type, - diagonal_type diag_type, - csrtrsv_descr* descr) +void linalg::device_csrtrsv_analysis(const csr_matrix& A, + triangular_type tri_type, + diagonal_type diag_type, + csrtrsv_descr* descr) { ROUTINE_TRACE("linalg::device_csrtrsv_analysis"); if constexpr(is_cuda_available()) @@ -74,13 +74,13 @@ void linalg::device_csrtrsv_analysis(const csr_matrix& A, } } -void linalg::device_csrtrsv_solve(const csr_matrix& A, - const vector& b, - vector& x, - double alpha, - triangular_type tri_type, - diagonal_type diag_type, - const csrtrsv_descr* descr) +void linalg::device_csrtrsv_solve(const csr_matrix& A, + const vector& b, + vector& x, + double alpha, + triangular_type tri_type, + diagonal_type diag_type, + const csrtrsv_descr* descr) { ROUTINE_TRACE("linalg::device_csrtrsv_solve"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_csrtrsv.h b/library/src/backend/device/device_csrtrsv.h index 99ed30b..dc86048 100644 --- a/library/src/backend/device/device_csrtrsv.h +++ b/library/src/backend/device/device_csrtrsv.h @@ -36,17 +36,17 @@ namespace linalg struct csrtrsv_descr; void free_csrtrsv_device_data(csrtrsv_descr* descr); - void device_csrtrsv_analysis(const csr_matrix& A, - triangular_type tri_type, - diagonal_type diag_type, - csrtrsv_descr* descr); - void device_csrtrsv_solve(const csr_matrix& A, - const vector& b, - vector& x, - double alpha, - triangular_type tri_type, - diagonal_type diag_type, - const csrtrsv_descr* descr); + void device_csrtrsv_analysis(const csr_matrix& A, + triangular_type tri_type, + diagonal_type diag_type, + csrtrsv_descr* descr); + void device_csrtrsv_solve(const csr_matrix& A, + const vector& b, + vector& x, + double alpha, + triangular_type tri_type, + diagonal_type diag_type, + const csrtrsv_descr* descr); } #endif diff --git a/library/src/backend/device/device_extract.cpp b/library/src/backend/device/device_extract.cpp index fa46dc2..6939b50 100644 --- a/library/src/backend/device/device_extract.cpp +++ b/library/src/backend/device/device_extract.cpp @@ -35,7 +35,7 @@ #include "cuda/cuda_extract.h" #endif -void linalg::device_diagonal(const csr_matrix& A, vector& d) +void linalg::device_diagonal(const csr_matrix& A, vector& d) { ROUTINE_TRACE("linalg::device_diagonal"); if constexpr(is_cuda_available()) @@ -55,7 +55,9 @@ void linalg::device_diagonal(const csr_matrix& A, vector& d) } } -void linalg::device_extract_lower_triangular_nnz(const csr_matrix& A, csr_matrix& L, int& nnz_L) +void linalg::device_extract_lower_triangular_nnz(const csr_matrix& A, + csr_matrix& L, + int& nnz_L) { ROUTINE_TRACE("linalg::device_extract_lower_triangular_nnz"); if constexpr(is_cuda_available()) @@ -75,7 +77,7 @@ void linalg::device_extract_lower_triangular_nnz(const csr_matrix& A, csr_matrix } } -void linalg::device_extract_lower_triangular(const csr_matrix& A, csr_matrix& L) +void linalg::device_extract_lower_triangular(const csr_matrix& A, csr_matrix& L) { ROUTINE_TRACE("linalg::device_extract_lower_triangular"); if constexpr(is_cuda_available()) @@ -100,7 +102,9 @@ void linalg::device_extract_lower_triangular(const csr_matrix& A, csr_matrix& L) } } -void linalg::device_extract_upper_triangular_nnz(const csr_matrix& A, csr_matrix& U, int& nnz_U) +void linalg::device_extract_upper_triangular_nnz(const csr_matrix& A, + csr_matrix& U, + int& nnz_U) { ROUTINE_TRACE("linalg::device_extract_upper_triangular_nnz_count"); if constexpr(is_cuda_available()) @@ -120,7 +124,7 @@ void linalg::device_extract_upper_triangular_nnz(const csr_matrix& A, csr_matrix } } -void linalg::device_extract_upper_triangular(const csr_matrix& A, csr_matrix& U) +void linalg::device_extract_upper_triangular(const csr_matrix& A, csr_matrix& U) { ROUTINE_TRACE("linalg::device_extract_upper_triangular"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_extract.h b/library/src/backend/device/device_extract.h index 2ab4a80..6848352 100644 --- a/library/src/backend/device/device_extract.h +++ b/library/src/backend/device/device_extract.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,11 +31,15 @@ namespace linalg { - void device_diagonal(const csr_matrix& A, vector& d); - void device_extract_lower_triangular_nnz(const csr_matrix& A, csr_matrix& L, int& nnz_L); - void device_extract_lower_triangular(const csr_matrix& A, csr_matrix& L); - void device_extract_upper_triangular_nnz(const csr_matrix& A, csr_matrix& U, int& nnz_U); - void device_extract_upper_triangular(const csr_matrix& A, csr_matrix& U); + void device_diagonal(const csr_matrix& A, vector& d); + void device_extract_lower_triangular_nnz(const csr_matrix& A, + csr_matrix& L, + int& nnz_L); + void device_extract_lower_triangular(const csr_matrix& A, csr_matrix& L); + void device_extract_upper_triangular_nnz(const csr_matrix& A, + csr_matrix& U, + int& nnz_U); + void device_extract_upper_triangular(const csr_matrix& A, csr_matrix& U); } #endif diff --git a/library/src/backend/device/device_matrix_vector.cpp b/library/src/backend/device/device_matrix_vector.cpp index d86de8d..e725d2c 100644 --- a/library/src/backend/device/device_matrix_vector.cpp +++ b/library/src/backend/device/device_matrix_vector.cpp @@ -35,10 +35,10 @@ #include "cuda/cuda_matrix_vector.h" #endif -void linalg::device_compute_residual(const csr_matrix& A, - const vector& x, - const vector& b, - vector& res) +void linalg::device_compute_residual(const csr_matrix& A, + const vector& x, + const vector& b, + vector& res) { ROUTINE_TRACE("linalg::device_compute_residual"); if constexpr(is_cuda_available()) @@ -74,7 +74,9 @@ void linalg::free_csrmv_device_data(csrmv_descr* descr) } } -void linalg::device_csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr) +void linalg::device_csrmv_analysis(const csr_matrix& A, + csrmv_algorithm alg, + csrmv_descr* descr) { ROUTINE_TRACE("linalg::device_csrmv_analysis"); if constexpr(is_cuda_available()) @@ -95,13 +97,13 @@ void linalg::device_csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csr } } -void linalg::device_csrmv_solve(double alpha, - const csr_matrix& A, - const vector& x, - double beta, - vector& y, - csrmv_algorithm alg, - const csrmv_descr* descr) +void linalg::device_csrmv_solve(double alpha, + const csr_matrix& A, + const vector& x, + double beta, + vector& y, + csrmv_algorithm alg, + const csrmv_descr* descr) { ROUTINE_TRACE("linalg::device_csrmv_solve"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_matrix_vector.h b/library/src/backend/device/device_matrix_vector.h index 7b92e5c..3ac8abd 100644 --- a/library/src/backend/device/device_matrix_vector.h +++ b/library/src/backend/device/device_matrix_vector.h @@ -32,22 +32,23 @@ namespace linalg { - void device_compute_residual(const csr_matrix& A, - const vector& x, - const vector& b, - vector& res); + void device_compute_residual(const csr_matrix& A, + const vector& x, + const vector& b, + vector& res); struct csrmv_descr; void free_csrmv_device_data(csrmv_descr* descr); - void device_csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr); - void device_csrmv_solve(double alpha, - const csr_matrix& A, - const vector& x, - double beta, - vector& y, - csrmv_algorithm alg, - const csrmv_descr* descr); + void + device_csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr); + void device_csrmv_solve(double alpha, + const csr_matrix& A, + const vector& x, + double beta, + vector& y, + csrmv_algorithm alg, + const csrmv_descr* descr); } #endif diff --git a/library/src/backend/device/device_ruiz_scaling.cpp b/library/src/backend/device/device_ruiz_scaling.cpp index 04d64b3..6e62346 100644 --- a/library/src/backend/device/device_ruiz_scaling.cpp +++ b/library/src/backend/device/device_ruiz_scaling.cpp @@ -36,7 +36,7 @@ #endif void linalg::device_ruiz_scaling( - vector& D1, csr_matrix& A, vector& D2, int max_k, double tol) + vector& D1, csr_matrix& A, vector& D2, int max_k, double tol) { ROUTINE_TRACE("linalg::device_ruiz_scaling"); if constexpr(is_cuda_available()) @@ -57,7 +57,10 @@ void linalg::device_ruiz_scaling( } } -void linalg::device_symmetric_ruiz_scaling(vector& D, csr_matrix& A, int max_k, double tol) +void linalg::device_symmetric_ruiz_scaling(vector& D, + csr_matrix& A, + int max_k, + double tol) { ROUTINE_TRACE("linalg::device_symmetric_ruiz_scaling"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_ruiz_scaling.h b/library/src/backend/device/device_ruiz_scaling.h index 64eed10..89cd3bc 100644 --- a/library/src/backend/device/device_ruiz_scaling.h +++ b/library/src/backend/device/device_ruiz_scaling.h @@ -32,9 +32,12 @@ namespace linalg { void device_ruiz_scaling( - vector& D1, csr_matrix& A, vector& D2, int max_k, double tol); + vector& D1, csr_matrix& A, vector& D2, int max_k, double tol); - void device_symmetric_ruiz_scaling(vector& D, csr_matrix& A, int max_k, double tol); + void device_symmetric_ruiz_scaling(vector& D, + csr_matrix& A, + int max_k, + double tol); } #endif diff --git a/library/src/backend/device/device_scale.cpp b/library/src/backend/device/device_scale.cpp index 96b54a5..1ade232 100644 --- a/library/src/backend/device/device_scale.cpp +++ b/library/src/backend/device/device_scale.cpp @@ -35,7 +35,7 @@ #include "cuda/cuda_scale.h" #endif -void linalg::device_scale_diagonal(csr_matrix& A, double scalar) +void linalg::device_scale_diagonal(csr_matrix& A, double scalar) { ROUTINE_TRACE("linalg::device_scale_diagonal"); if constexpr(is_cuda_available()) @@ -50,7 +50,7 @@ void linalg::device_scale_diagonal(csr_matrix& A, double scalar) } } -void linalg::device_scale_by_inverse_diagonal(csr_matrix& A, const vector& diag) +void linalg::device_scale_by_inverse_diagonal(csr_matrix& A, const vector& diag) { ROUTINE_TRACE("linalg::device_scale_by_inverse_diagonal"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_scale.h b/library/src/backend/device/device_scale.h index 7e1fea0..90cb6ac 100644 --- a/library/src/backend/device/device_scale.h +++ b/library/src/backend/device/device_scale.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,8 +31,8 @@ namespace linalg { - void device_scale_diagonal(csr_matrix& A, double scalar); - void device_scale_by_inverse_diagonal(csr_matrix& A, const vector& diag); + void device_scale_diagonal(csr_matrix& A, double scalar); + void device_scale_by_inverse_diagonal(csr_matrix& A, const vector& diag); } #endif diff --git a/library/src/backend/device/device_ssor.cpp b/library/src/backend/device/device_ssor.cpp index 2b3f29a..289bbc6 100644 --- a/library/src/backend/device/device_ssor.cpp +++ b/library/src/backend/device/device_ssor.cpp @@ -35,7 +35,9 @@ #include "cuda/cuda_ssor.h" #endif -void linalg::device_ssor_fill_lower_precond(const csr_matrix& A, csr_matrix& L, double omega) +void linalg::device_ssor_fill_lower_precond(const csr_matrix& A, + csr_matrix& L, + double omega) { ROUTINE_TRACE("linalg::device_ssor_fill_lower_precond"); if constexpr(is_cuda_available()) @@ -61,7 +63,9 @@ void linalg::device_ssor_fill_lower_precond(const csr_matrix& A, csr_matrix& L, } } -void linalg::device_ssor_fill_upper_precond(const csr_matrix& A, csr_matrix& U, double omega) +void linalg::device_ssor_fill_upper_precond(const csr_matrix& A, + csr_matrix& U, + double omega) { ROUTINE_TRACE("linalg::device_ssor_fill_upper_precond"); if constexpr(is_cuda_available()) diff --git a/library/src/backend/device/device_ssor.h b/library/src/backend/device/device_ssor.h index f9b9914..1429d3d 100644 --- a/library/src/backend/device/device_ssor.h +++ b/library/src/backend/device/device_ssor.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -30,8 +30,12 @@ namespace linalg { - void device_ssor_fill_lower_precond(const csr_matrix& A, csr_matrix& L, double omega); - void device_ssor_fill_upper_precond(const csr_matrix& A, csr_matrix& U, double omega); + void device_ssor_fill_lower_precond(const csr_matrix& A, + csr_matrix& L, + double omega); + void device_ssor_fill_upper_precond(const csr_matrix& A, + csr_matrix& U, + double omega); } #endif diff --git a/library/src/backend/host/host_amg_aggregation.cpp b/library/src/backend/host/host_amg_aggregation.cpp index bd5f06b..0d5e3b1 100644 --- a/library/src/backend/host/host_amg_aggregation.cpp +++ b/library/src/backend/host/host_amg_aggregation.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -37,10 +37,10 @@ static unsigned int hash1(unsigned int x) return x / 2; } -void linalg::host_initialize_pmis_state(const csr_matrix& A, - const vector& connections, - vector& state, - vector& hash) +void linalg::host_initialize_pmis_state(const csr_matrix& A, + const vector& connections, + vector& state, + vector& hash) { ROUTINE_TRACE("initialize_pmis_state"); @@ -92,13 +92,13 @@ static pmis_node lexographical_max(const pmis_node* ti, const pmis_node* tj) return *ti; } -void linalg::host_find_maximum_distance_two_node(const csr_matrix& A, - const vector& connections, - const vector& state, - const vector& hash, - vector& aggregates, - vector& max_state, - bool& complete) +void linalg::host_find_maximum_distance_two_node(const csr_matrix& A, + const vector& connections, + const vector& state, + const vector& hash, + vector& aggregates, + vector& max_state, + bool& complete) { ROUTINE_TRACE("find_maximum_distance_two_node"); @@ -179,10 +179,10 @@ void linalg::host_find_maximum_distance_two_node(const csr_matrix& A, } } -void linalg::host_add_unassigned_nodes_to_closest_aggregation(const csr_matrix& A, - const vector& connections, - const vector& state, - vector& aggregates, +void linalg::host_add_unassigned_nodes_to_closest_aggregation(const csr_matrix& A, + const vector& connections, + const vector& state, + vector& aggregates, vector& aggregate_root_nodes, vector& max_state) { @@ -225,9 +225,9 @@ void linalg::host_add_unassigned_nodes_to_closest_aggregation(const csr_matrix& #define U_POINT 2 // Unassigned point #define FF_POINT 3 // Future F-point -void linalg::host_compute_cfpoint_first_pass(const csr_matrix& S, - const csr_matrix& ST, - vector& cfpoints) +void linalg::host_compute_cfpoint_first_pass(const csr_matrix& S, + const csr_matrix& ST, + vector& cfpoints) { ROUTINE_TRACE("linalg::host_compute_cfpoint_first_pass"); @@ -438,7 +438,8 @@ void linalg::host_compute_cfpoint_first_pass(const csr_matrix& S, } } -void linalg::host_compute_cfpoint_second_pass(const csr_matrix& S, vector& cfpoints) +void linalg::host_compute_cfpoint_second_pass(const csr_matrix& S, + vector& cfpoints) { ROUTINE_TRACE("linalg::host_compute_cfpoint_second_pass"); diff --git a/library/src/backend/host/host_amg_aggregation.h b/library/src/backend/host/host_amg_aggregation.h index 28ccb9f..1b6b586 100644 --- a/library/src/backend/host/host_amg_aggregation.h +++ b/library/src/backend/host/host_amg_aggregation.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -35,31 +35,31 @@ namespace linalg { // - void host_initialize_pmis_state(const csr_matrix& A, - const vector& connections, - vector& state, - vector& hash); + void host_initialize_pmis_state(const csr_matrix& A, + const vector& connections, + vector& state, + vector& hash); - void host_find_maximum_distance_two_node(const csr_matrix& A, - const vector& connections, - const vector& state, - const vector& hash, - vector& aggregates, - vector& max_state, - bool& complete); + void host_find_maximum_distance_two_node(const csr_matrix& A, + const vector& connections, + const vector& state, + const vector& hash, + vector& aggregates, + vector& max_state, + bool& complete); - void host_add_unassigned_nodes_to_closest_aggregation(const csr_matrix& A, - const vector& connections, - const vector& state, - vector& aggregates, - vector& aggregate_root_nodes, - vector& max_state); + void host_add_unassigned_nodes_to_closest_aggregation(const csr_matrix& A, + const vector& connections, + const vector& state, + vector& aggregates, + vector& aggregate_root_nodes, + vector& max_state); - void host_compute_cfpoint_first_pass(const csr_matrix& S, - const csr_matrix& ST, - vector& cfpoints); + void host_compute_cfpoint_first_pass(const csr_matrix& S, + const csr_matrix& ST, + vector& cfpoints); - void host_compute_cfpoint_second_pass(const csr_matrix& S, vector& cfpoints); + void host_compute_cfpoint_second_pass(const csr_matrix& S, vector& cfpoints); } -#endif \ No newline at end of file +#endif diff --git a/library/src/backend/host/host_amg_strength.cpp b/library/src/backend/host/host_amg_strength.cpp index f75a11a..949877c 100644 --- a/library/src/backend/host/host_amg_strength.cpp +++ b/library/src/backend/host/host_amg_strength.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -30,9 +30,9 @@ #include "../../trace.h" -void linalg::host_compute_strong_connections(const csr_matrix& A, - double eps, - vector& connections) +void linalg::host_compute_strong_connections(const csr_matrix& A, + double eps, + vector& connections) { ROUTINE_TRACE("linalg::host_compute_strong_connections"); const int* csr_row_ptr_A = A.get_row_ptr(); @@ -69,10 +69,10 @@ void linalg::host_compute_strong_connections(const csr_matrix& A, } } -void linalg::host_compute_classical_strong_connections(const csr_matrix& A, - double theta, - csr_matrix& S, - vector& connections) +void linalg::host_compute_classical_strong_connections(const csr_matrix& A, + double theta, + csr_matrix& S, + vector& connections) { ROUTINE_TRACE("linalg::host_compute_classical_strong_connections"); //S.m = A.m; diff --git a/library/src/backend/host/host_amg_strength.h b/library/src/backend/host/host_amg_strength.h index 37900ad..3df6358 100644 --- a/library/src/backend/host/host_amg_strength.h +++ b/library/src/backend/host/host_amg_strength.h @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -32,12 +32,14 @@ namespace linalg { - void host_compute_strong_connections(const csr_matrix& A, double eps, vector& connections); + void host_compute_strong_connections(const csr_matrix& A, + double eps, + vector& connections); - void host_compute_classical_strong_connections(const csr_matrix& A, - double theta, - csr_matrix& S, - vector& connections); + void host_compute_classical_strong_connections(const csr_matrix& A, + double theta, + csr_matrix& S, + vector& connections); } -#endif \ No newline at end of file +#endif diff --git a/library/src/backend/host/host_csr2csc.cpp b/library/src/backend/host/host_csr2csc.cpp index 4f7c831..dad2f21 100644 --- a/library/src/backend/host/host_csr2csc.cpp +++ b/library/src/backend/host/host_csr2csc.cpp @@ -27,7 +27,7 @@ #include "host_csr2csc.h" #include "../../trace.h" -void linalg::host_transpose_matrix(const csr_matrix& A, csr_matrix& transposeA) +void linalg::host_transpose_matrix(const csr_matrix& A, csr_matrix& transposeA) { ROUTINE_TRACE("linalg::host_transpose_matrix"); transposeA.resize(A.get_n(), A.get_m(), A.get_nnz()); diff --git a/library/src/backend/host/host_csr2csc.h b/library/src/backend/host/host_csr2csc.h index 7f24338..c914fac 100644 --- a/library/src/backend/host/host_csr2csc.h +++ b/library/src/backend/host/host_csr2csc.h @@ -31,7 +31,7 @@ namespace linalg { - void host_transpose_matrix(const csr_matrix& A, csr_matrix& transposeA); + void host_transpose_matrix(const csr_matrix& A, csr_matrix& transposeA); } #endif diff --git a/library/src/backend/host/host_csrgeam.cpp b/library/src/backend/host/host_csrgeam.cpp index 10d4ad0..550d6ca 100644 --- a/library/src/backend/host/host_csrgeam.cpp +++ b/library/src/backend/host/host_csrgeam.cpp @@ -133,11 +133,11 @@ namespace linalg } } -void linalg::host_csrgeam_nnz(const csr_matrix& A, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - csrgeam_descr* descr) +void linalg::host_csrgeam_nnz(const csr_matrix& A, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + csrgeam_descr* descr) { ROUTINE_TRACE("linalg::host_csrgeam_nnz"); C.resize(A.get_m(), B.get_n(), 0); @@ -157,13 +157,13 @@ void linalg::host_csrgeam_nnz(const csr_matrix& A, C.resize(A.get_m(), B.get_n(), nnz_C); } -void linalg::host_csrgeam_solve(double alpha, - const csr_matrix& A, - double beta, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - const csrgeam_descr* descr) +void linalg::host_csrgeam_solve(double alpha, + const csr_matrix& A, + double beta, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + const csrgeam_descr* descr) { ROUTINE_TRACE("linalg::host_csrgeam_solve"); host_csrgeam_impl(A.get_m(), diff --git a/library/src/backend/host/host_csrgeam.h b/library/src/backend/host/host_csrgeam.h index 767c32c..f7fb3eb 100644 --- a/library/src/backend/host/host_csrgeam.h +++ b/library/src/backend/host/host_csrgeam.h @@ -34,18 +34,18 @@ namespace linalg { struct csrgeam_descr; - void host_csrgeam_nnz(const csr_matrix& A, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - csrgeam_descr* descr); - void host_csrgeam_solve(double alpha, - const csr_matrix& A, - double beta, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - const csrgeam_descr* descr); + void host_csrgeam_nnz(const csr_matrix& A, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + csrgeam_descr* descr); + void host_csrgeam_solve(double alpha, + const csr_matrix& A, + double beta, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + const csrgeam_descr* descr); } #endif diff --git a/library/src/backend/host/host_csrgemm.cpp b/library/src/backend/host/host_csrgemm.cpp index d163a4c..fbcd708 100644 --- a/library/src/backend/host/host_csrgemm.cpp +++ b/library/src/backend/host/host_csrgemm.cpp @@ -183,12 +183,12 @@ namespace linalg } } -void linalg::host_csrgemm_nnz(const csr_matrix& A, - const csr_matrix& B, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - csrgemm_descr* descr) +void linalg::host_csrgemm_nnz(const csr_matrix& A, + const csr_matrix& B, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + csrgemm_descr* descr) { ROUTINE_TRACE("linalg::host_csrgemm_nnz"); C.resize(A.get_m(), B.get_n(), 0); @@ -212,14 +212,14 @@ void linalg::host_csrgemm_nnz(const csr_matrix& A, C.resize(A.get_m(), B.get_n(), nnz_C); } -void linalg::host_csrgemm_solve(double alpha, - const csr_matrix& A, - const csr_matrix& B, - double beta, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - const csrgemm_descr* descr) +void linalg::host_csrgemm_solve(double alpha, + const csr_matrix& A, + const csr_matrix& B, + double beta, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + const csrgemm_descr* descr) { ROUTINE_TRACE("linalg::host_csrgemm_solve"); host_csrgemm_impl(A.get_m(), diff --git a/library/src/backend/host/host_csrgemm.h b/library/src/backend/host/host_csrgemm.h index 9e81f8e..d4af2ae 100644 --- a/library/src/backend/host/host_csrgemm.h +++ b/library/src/backend/host/host_csrgemm.h @@ -34,20 +34,20 @@ namespace linalg { struct csrgemm_descr; - void host_csrgemm_nnz(const csr_matrix& A, - const csr_matrix& B, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - csrgemm_descr* descr); - void host_csrgemm_solve(double alpha, - const csr_matrix& A, - const csr_matrix& B, - double beta, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - const csrgemm_descr* descr); + void host_csrgemm_nnz(const csr_matrix& A, + const csr_matrix& B, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + csrgemm_descr* descr); + void host_csrgemm_solve(double alpha, + const csr_matrix& A, + const csr_matrix& B, + double beta, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + const csrgemm_descr* descr); } #endif diff --git a/library/src/backend/host/host_csric0.cpp b/library/src/backend/host/host_csric0.cpp index 3b78ad3..7674eea 100644 --- a/library/src/backend/host/host_csric0.cpp +++ b/library/src/backend/host/host_csric0.cpp @@ -121,7 +121,7 @@ namespace linalg } } -void linalg::host_csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero) +void linalg::host_csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero) { ROUTINE_TRACE("linalg::host_csric0"); host_csric0_impl(LL.get_m(), @@ -134,12 +134,12 @@ void linalg::host_csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero numeric_zero); } -void linalg::host_csric0_analysis(const csr_matrix& A, csric0_descr* descr) +void linalg::host_csric0_analysis(const csr_matrix& A, csric0_descr* descr) { ROUTINE_TRACE("linalg::host_csric0_analysis"); } -void linalg::host_csric0_compute(csr_matrix& A, const csric0_descr* descr) +void linalg::host_csric0_compute(csr_matrix& A, const csric0_descr* descr) { ROUTINE_TRACE("linalg::host_csric0_compute"); host_csric0_impl(A.get_m(), diff --git a/library/src/backend/host/host_csric0.h b/library/src/backend/host/host_csric0.h index f190827..259184d 100644 --- a/library/src/backend/host/host_csric0.h +++ b/library/src/backend/host/host_csric0.h @@ -31,12 +31,12 @@ namespace linalg { - void host_csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero); + void host_csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero); struct csric0_descr; - void host_csric0_analysis(const csr_matrix& A, csric0_descr* descr); - void host_csric0_compute(csr_matrix& A, const csric0_descr* descr); + void host_csric0_analysis(const csr_matrix& A, csric0_descr* descr); + void host_csric0_compute(csr_matrix& A, const csric0_descr* descr); } #endif diff --git a/library/src/backend/host/host_csrilu0.cpp b/library/src/backend/host/host_csrilu0.cpp index 2b9bb91..4e45f37 100644 --- a/library/src/backend/host/host_csrilu0.cpp +++ b/library/src/backend/host/host_csrilu0.cpp @@ -105,7 +105,7 @@ namespace linalg } } -void linalg::host_csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero) +void linalg::host_csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero) { ROUTINE_TRACE("linalg::host_csrilu0"); host_csrilu0_impl(LU.get_m(), @@ -118,12 +118,12 @@ void linalg::host_csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zer numeric_zero); } -void linalg::host_csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr) +void linalg::host_csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr) { ROUTINE_TRACE("linalg::host_csrilu0_analysis"); } -void linalg::host_csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr) +void linalg::host_csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr) { ROUTINE_TRACE("linalg::host_csrilu0_compute"); host_csrilu0_impl(A.get_m(), diff --git a/library/src/backend/host/host_csrilu0.h b/library/src/backend/host/host_csrilu0.h index e1105df..e41d113 100644 --- a/library/src/backend/host/host_csrilu0.h +++ b/library/src/backend/host/host_csrilu0.h @@ -31,12 +31,12 @@ namespace linalg { - void host_csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero); + void host_csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero); struct csrilu0_descr; - void host_csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr); - void host_csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr); + void host_csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr); + void host_csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr); } #endif diff --git a/library/src/backend/host/host_csrtrsv.cpp b/library/src/backend/host/host_csrtrsv.cpp index 748f7c4..7b2c23b 100644 --- a/library/src/backend/host/host_csrtrsv.cpp +++ b/library/src/backend/host/host_csrtrsv.cpp @@ -98,21 +98,21 @@ namespace linalg } } -void linalg::host_csrtrsv_analysis(const csr_matrix& A, - triangular_type tri_type, - diagonal_type diag_type, - csrtrsv_descr* descr) +void linalg::host_csrtrsv_analysis(const csr_matrix& A, + triangular_type tri_type, + diagonal_type diag_type, + csrtrsv_descr* descr) { ROUTINE_TRACE("linalg::host_csrtrsv_analysis"); } -void linalg::host_csrtrsv_solve(const csr_matrix& A, - const vector& b, - vector& x, - double alpha, - triangular_type tri_type, - diagonal_type diag_type, - const csrtrsv_descr* descr) +void linalg::host_csrtrsv_solve(const csr_matrix& A, + const vector& b, + vector& x, + double alpha, + triangular_type tri_type, + diagonal_type diag_type, + const csrtrsv_descr* descr) { ROUTINE_TRACE("linalg::host_csrtrsv_solve"); if(tri_type == triangular_type::upper) diff --git a/library/src/backend/host/host_csrtrsv.h b/library/src/backend/host/host_csrtrsv.h index bcab894..2f98d48 100644 --- a/library/src/backend/host/host_csrtrsv.h +++ b/library/src/backend/host/host_csrtrsv.h @@ -35,17 +35,17 @@ namespace linalg { struct csrtrsv_descr; - void host_csrtrsv_analysis(const csr_matrix& A, - triangular_type tri_type, - diagonal_type diag_type, - csrtrsv_descr* descr); - void host_csrtrsv_solve(const csr_matrix& A, - const vector& b, - vector& x, - double alpha, - triangular_type tri_type, - diagonal_type diag_type, - const csrtrsv_descr* descr); + void host_csrtrsv_analysis(const csr_matrix& A, + triangular_type tri_type, + diagonal_type diag_type, + csrtrsv_descr* descr); + void host_csrtrsv_solve(const csr_matrix& A, + const vector& b, + vector& x, + double alpha, + triangular_type tri_type, + diagonal_type diag_type, + const csrtrsv_descr* descr); } #endif diff --git a/library/src/backend/host/host_extract.cpp b/library/src/backend/host/host_extract.cpp index df78693..b06009a 100644 --- a/library/src/backend/host/host_extract.cpp +++ b/library/src/backend/host/host_extract.cpp @@ -182,13 +182,15 @@ namespace linalg } } -void linalg::host_diagonal(const csr_matrix& A, vector& d) +void linalg::host_diagonal(const csr_matrix& A, vector& d) { ROUTINE_TRACE("linalg::host_diagonal"); host_diagonal_impl(A.get_row_ptr(), A.get_col_ind(), A.get_val(), d.get_vec(), A.get_m()); } -void linalg::host_extract_lower_triangular_nnz(const csr_matrix& A, csr_matrix& L, int& nnz_L) +void linalg::host_extract_lower_triangular_nnz(const csr_matrix& A, + csr_matrix& L, + int& nnz_L) { ROUTINE_TRACE("linalg::host_extract_lower_triangular_nnz"); host_extract_lower_triangular_nnz_impl(A.get_m(), @@ -200,7 +202,7 @@ void linalg::host_extract_lower_triangular_nnz(const csr_matrix& A, csr_matrix& &nnz_L); } -void linalg::host_extract_lower_triangular(const csr_matrix& A, csr_matrix& L) +void linalg::host_extract_lower_triangular(const csr_matrix& A, csr_matrix& L) { ROUTINE_TRACE("linalg::host_extract_lower_triangular"); host_extract_lower_triangular_impl(A.get_m(), @@ -217,7 +219,9 @@ void linalg::host_extract_lower_triangular(const csr_matrix& A, csr_matrix& L) L.get_val()); } -void linalg::host_extract_upper_triangular_nnz(const csr_matrix& A, csr_matrix& U, int& nnz_U) +void linalg::host_extract_upper_triangular_nnz(const csr_matrix& A, + csr_matrix& U, + int& nnz_U) { ROUTINE_TRACE("linalg::host_extract_upper_triangular_nnz"); host_extract_upper_triangular_nnz_impl(A.get_m(), @@ -229,7 +233,7 @@ void linalg::host_extract_upper_triangular_nnz(const csr_matrix& A, csr_matrix& &nnz_U); } -void linalg::host_extract_upper_triangular(const csr_matrix& A, csr_matrix& U) +void linalg::host_extract_upper_triangular(const csr_matrix& A, csr_matrix& U) { ROUTINE_TRACE("linalg::host_extract_upper_triangular"); host_extract_upper_triangular_impl(A.get_m(), diff --git a/library/src/backend/host/host_extract.h b/library/src/backend/host/host_extract.h index ed2bf1d..f5aff5b 100644 --- a/library/src/backend/host/host_extract.h +++ b/library/src/backend/host/host_extract.h @@ -32,11 +32,15 @@ namespace linalg { - void host_diagonal(const csr_matrix& A, vector& d); - void host_extract_lower_triangular_nnz(const csr_matrix& A, csr_matrix& L, int& nnz_L); - void host_extract_lower_triangular(const csr_matrix& A, csr_matrix& L); - void host_extract_upper_triangular_nnz(const csr_matrix& A, csr_matrix& U, int& nnz_U); - void host_extract_upper_triangular(const csr_matrix& A, csr_matrix& U); + void host_diagonal(const csr_matrix& A, vector& d); + void host_extract_lower_triangular_nnz(const csr_matrix& A, + csr_matrix& L, + int& nnz_L); + void host_extract_lower_triangular(const csr_matrix& A, csr_matrix& L); + void host_extract_upper_triangular_nnz(const csr_matrix& A, + csr_matrix& U, + int& nnz_U); + void host_extract_upper_triangular(const csr_matrix& A, csr_matrix& U); } #endif diff --git a/library/src/backend/host/host_matrix_vector.cpp b/library/src/backend/host/host_matrix_vector.cpp index 207d52c..ec829a7 100644 --- a/library/src/backend/host/host_matrix_vector.cpp +++ b/library/src/backend/host/host_matrix_vector.cpp @@ -84,10 +84,10 @@ namespace linalg } } -void linalg::host_compute_residual(const csr_matrix& A, - const vector& x, - const vector& b, - vector& res) +void linalg::host_compute_residual(const csr_matrix& A, + const vector& x, + const vector& b, + vector& res) { ROUTINE_TRACE("linalg::host_compute_residual"); host_compute_residual_impl(A.get_row_ptr(), @@ -99,18 +99,20 @@ void linalg::host_compute_residual(const csr_matrix& A, A.get_m()); } -void linalg::host_csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr) +void linalg::host_csrmv_analysis(const csr_matrix& A, + csrmv_algorithm alg, + csrmv_descr* descr) { ROUTINE_TRACE("linalg::host_csrmv_analysis"); } -void linalg::host_csrmv_solve(double alpha, - const csr_matrix& A, - const vector& x, - double beta, - vector& y, - csrmv_algorithm alg, - const csrmv_descr* descr) +void linalg::host_csrmv_solve(double alpha, + const csr_matrix& A, + const vector& x, + double beta, + vector& y, + csrmv_algorithm alg, + const csrmv_descr* descr) { ROUTINE_TRACE("linalg::host_csrmv_solve"); switch(alg) diff --git a/library/src/backend/host/host_matrix_vector.h b/library/src/backend/host/host_matrix_vector.h index 1998289..18fcd2a 100644 --- a/library/src/backend/host/host_matrix_vector.h +++ b/library/src/backend/host/host_matrix_vector.h @@ -33,21 +33,21 @@ namespace linalg { - void host_compute_residual(const csr_matrix& A, - const vector& x, - const vector& b, - vector& res); + void host_compute_residual(const csr_matrix& A, + const vector& x, + const vector& b, + vector& res); struct csrmv_descr; - void host_csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr); - void host_csrmv_solve(double alpha, - const csr_matrix& A, - const vector& x, - double beta, - vector& y, - csrmv_algorithm alg, - const csrmv_descr* descr); + void host_csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr); + void host_csrmv_solve(double alpha, + const csr_matrix& A, + const vector& x, + double beta, + vector& y, + csrmv_algorithm alg, + const csrmv_descr* descr); } #endif diff --git a/library/src/backend/host/host_ruiz_scaling.cpp b/library/src/backend/host/host_ruiz_scaling.cpp index 8265bcc..4ca7d92 100644 --- a/library/src/backend/host/host_ruiz_scaling.cpp +++ b/library/src/backend/host/host_ruiz_scaling.cpp @@ -224,7 +224,7 @@ namespace linalg } void linalg::host_ruiz_scaling( - vector& D1, csr_matrix& A, vector& D2, int max_k, double tol) + vector& D1, csr_matrix& A, vector& D2, int max_k, double tol) { ROUTINE_TRACE("linalg::host_ruiz_scaling"); @@ -242,7 +242,10 @@ void linalg::host_ruiz_scaling( tol); } -void linalg::host_symmetric_ruiz_scaling(vector& D, csr_matrix& A, int max_k, double tol) +void linalg::host_symmetric_ruiz_scaling(vector& D, + csr_matrix& A, + int max_k, + double tol) { ROUTINE_TRACE("linalg::host_ruiz_scaling"); diff --git a/library/src/backend/host/host_ruiz_scaling.h b/library/src/backend/host/host_ruiz_scaling.h index 83ed18a..85efcb1 100644 --- a/library/src/backend/host/host_ruiz_scaling.h +++ b/library/src/backend/host/host_ruiz_scaling.h @@ -33,9 +33,12 @@ namespace linalg { void host_ruiz_scaling( - vector& D1, csr_matrix& A, vector& D2, int max_k, double tol); + vector& D1, csr_matrix& A, vector& D2, int max_k, double tol); - void host_symmetric_ruiz_scaling(vector& D, csr_matrix& A, int max_k, double tol); + void host_symmetric_ruiz_scaling(vector& D, + csr_matrix& A, + int max_k, + double tol); } #endif // HOST_APPLY_RUIZ_SCALING_H diff --git a/library/src/backend/host/host_scale.cpp b/library/src/backend/host/host_scale.cpp index 1638ce9..35ac550 100644 --- a/library/src/backend/host/host_scale.cpp +++ b/library/src/backend/host/host_scale.cpp @@ -69,13 +69,13 @@ namespace linalg } } -void linalg::host_scale_diagonal(csr_matrix& A, double scalar) +void linalg::host_scale_diagonal(csr_matrix& A, double scalar) { ROUTINE_TRACE("linalg::host_scale_diagonal"); host_scale_diagonal_impl(A.get_row_ptr(), A.get_col_ind(), A.get_val(), A.get_m(), scalar); } -void linalg::host_scale_by_inverse_diagonal(csr_matrix& A, const vector& diag) +void linalg::host_scale_by_inverse_diagonal(csr_matrix& A, const vector& diag) { ROUTINE_TRACE("linalg::host_scale_by_inverse_diagonal"); host_scale_by_inverse_diagonal_impl( diff --git a/library/src/backend/host/host_scale.h b/library/src/backend/host/host_scale.h index b487d8b..15ab20e 100644 --- a/library/src/backend/host/host_scale.h +++ b/library/src/backend/host/host_scale.h @@ -32,8 +32,8 @@ namespace linalg { - void host_scale_diagonal(csr_matrix& A, double scalar); - void host_scale_by_inverse_diagonal(csr_matrix& A, const vector& diag); + void host_scale_diagonal(csr_matrix& A, double scalar); + void host_scale_by_inverse_diagonal(csr_matrix& A, const vector& diag); } #endif diff --git a/library/src/backend/host/host_ssor.cpp b/library/src/backend/host/host_ssor.cpp index 5bd93c6..f6b4f44 100644 --- a/library/src/backend/host/host_ssor.cpp +++ b/library/src/backend/host/host_ssor.cpp @@ -143,7 +143,9 @@ namespace linalg } } -void linalg::host_ssor_fill_lower_precond(const csr_matrix& A, csr_matrix& L, double omega) +void linalg::host_ssor_fill_lower_precond(const csr_matrix& A, + csr_matrix& L, + double omega) { ROUTINE_TRACE("linalg::host_ssor_fill_lower_precond"); host_ssor_fill_lower_precond_impl(A.get_m(), @@ -161,7 +163,9 @@ void linalg::host_ssor_fill_lower_precond(const csr_matrix& A, csr_matrix& L, do omega); } -void linalg::host_ssor_fill_upper_precond(const csr_matrix& A, csr_matrix& U, double omega) +void linalg::host_ssor_fill_upper_precond(const csr_matrix& A, + csr_matrix& U, + double omega) { ROUTINE_TRACE("linalg::host_ssor_fill_upper_precond"); host_ssor_fill_upper_precond_impl(A.get_m(), diff --git a/library/src/backend/host/host_ssor.h b/library/src/backend/host/host_ssor.h index 7c7f605..f7980a1 100644 --- a/library/src/backend/host/host_ssor.h +++ b/library/src/backend/host/host_ssor.h @@ -31,8 +31,12 @@ namespace linalg { - void host_ssor_fill_lower_precond(const csr_matrix& A, csr_matrix& L, double omega); - void host_ssor_fill_upper_precond(const csr_matrix& A, csr_matrix& U, double omega); + void host_ssor_fill_lower_precond(const csr_matrix& A, + csr_matrix& L, + double omega); + void host_ssor_fill_upper_precond(const csr_matrix& A, + csr_matrix& U, + double omega); } #endif diff --git a/library/src/csr_matrix.cpp b/library/src/csr_matrix.cpp index 01ab192..17535da 100644 --- a/library/src/csr_matrix.cpp +++ b/library/src/csr_matrix.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -42,7 +42,8 @@ using namespace linalg; -csr_matrix::csr_matrix() +template +csr_matrix::csr_matrix() : m(0) , n(0) , nnz(0) @@ -50,12 +51,13 @@ csr_matrix::csr_matrix() { } -csr_matrix::csr_matrix(const std::vector& csr_row_ptr, - const std::vector& csr_col_ind, - const std::vector& csr_val, - int m, - int n, - int nnz) +template +csr_matrix::csr_matrix(const std::vector& csr_row_ptr, + const std::vector& csr_col_ind, + const std::vector& csr_val, + int m, + int n, + int nnz) { this->csr_row_ptr.resize(csr_row_ptr.size()); this->csr_col_ind.resize(csr_col_ind.size()); @@ -70,61 +72,76 @@ csr_matrix::csr_matrix(const std::vector& csr_row_ptr, this->on_host = true; } -csr_matrix::~csr_matrix() {} -bool csr_matrix::is_on_host() const +template +csr_matrix::~csr_matrix() +{ +} + +template +bool csr_matrix::is_on_host() const { return on_host; } -int csr_matrix::get_m() const +template +int csr_matrix::get_m() const { return this->m; } -int csr_matrix::get_n() const +template +int csr_matrix::get_n() const { return this->n; } -int csr_matrix::get_nnz() const +template +int csr_matrix::get_nnz() const { return this->nnz; } -const int* csr_matrix::get_row_ptr() const +template +const int* csr_matrix::get_row_ptr() const { return csr_row_ptr.get_vec(); } -const int* csr_matrix::get_col_ind() const +template +const int* csr_matrix::get_col_ind() const { return csr_col_ind.get_vec(); } -const double* csr_matrix::get_val() const +template +const T* csr_matrix::get_val() const { return csr_val.get_vec(); } -int* csr_matrix::get_row_ptr() +template +int* csr_matrix::get_row_ptr() { return csr_row_ptr.get_vec(); } -int* csr_matrix::get_col_ind() +template +int* csr_matrix::get_col_ind() { return csr_col_ind.get_vec(); } -double* csr_matrix::get_val() +template +T* csr_matrix::get_val() { return csr_val.get_vec(); } -void csr_matrix::resize(int m, int n, int nnz) +template +void csr_matrix::resize(int m, int n, int nnz) { - ROUTINE_TRACE("csr_matrix::resize"); + ROUTINE_TRACE("csr_matrix::resize"); this->csr_row_ptr.resize(m + 1); this->csr_col_ind.resize(nnz); this->csr_val.resize(nnz); @@ -133,9 +150,10 @@ void csr_matrix::resize(int m, int n, int nnz) this->nnz = nnz; } -void csr_matrix::copy_from(const csr_matrix& A) +template +void csr_matrix::copy_from(const csr_matrix& A) { - ROUTINE_TRACE("csr_matrix::copy_from"); + ROUTINE_TRACE("csr_matrix::copy_from"); this->m = A.get_m(); this->n = A.get_n(); @@ -149,9 +167,10 @@ void csr_matrix::copy_from(const csr_matrix& A) this->csr_val.copy_from(A.csr_val); } -void csr_matrix::copy_lower_triangular_from(const csr_matrix& A, bool unit_diag) +template +void csr_matrix::copy_lower_triangular_from(const csr_matrix& A, bool unit_diag) { - ROUTINE_TRACE("csr_matrix::copy_lower_triangular_from"); + ROUTINE_TRACE("csr_matrix::copy_lower_triangular_from"); this->m = A.get_m(); this->n = A.get_n(); @@ -159,7 +178,7 @@ void csr_matrix::copy_lower_triangular_from(const csr_matrix& A, bool unit_diag) this->csr_row_ptr.resize(A.get_m() + 1); // Determine non-zero count in lower triangular portion of A - backend_dispatch("linalg::csr_matrix::copy_lower_triangular_from", + backend_dispatch("linalg::csr_matrix::copy_lower_triangular_from", host_extract_lower_triangular_nnz, device_extract_lower_triangular_nnz, A, @@ -169,16 +188,17 @@ void csr_matrix::copy_lower_triangular_from(const csr_matrix& A, bool unit_diag) this->csr_col_ind.resize(this->nnz); this->csr_val.resize(this->nnz); - backend_dispatch("linalg::csr_matrix::copy_lower_triangular_from", + backend_dispatch("linalg::csr_matrix::copy_lower_triangular_from", host_extract_lower_triangular, device_extract_lower_triangular, A, *this); } -void csr_matrix::copy_upper_triangular_from(const csr_matrix& A, bool unit_diag) +template +void csr_matrix::copy_upper_triangular_from(const csr_matrix& A, bool unit_diag) { - ROUTINE_TRACE("csr_matrix::copy_upper_triangular_from"); + ROUTINE_TRACE("csr_matrix::copy_upper_triangular_from"); this->m = A.get_m(); this->n = A.get_n(); @@ -186,7 +206,7 @@ void csr_matrix::copy_upper_triangular_from(const csr_matrix& A, bool unit_diag) this->csr_row_ptr.resize(A.get_m() + 1); // Determine non-zero count in upper triangular portion of A - backend_dispatch("linalg::csr_matrix::copy_upper_triangular_from", + backend_dispatch("linalg::csr_matrix::copy_upper_triangular_from", host_extract_upper_triangular_nnz, device_extract_upper_triangular_nnz, A, @@ -196,16 +216,17 @@ void csr_matrix::copy_upper_triangular_from(const csr_matrix& A, bool unit_diag) this->csr_col_ind.resize(this->nnz); this->csr_val.resize(this->nnz); - backend_dispatch("linalg::csr_matrix::copy_upper_triangular_from", + backend_dispatch("linalg::csr_matrix::copy_upper_triangular_from", host_extract_upper_triangular, device_extract_upper_triangular, A, *this); } -void csr_matrix::move_to_device() +template +void csr_matrix::move_to_device() { - ROUTINE_TRACE("csr_matrix::move_to_device"); + ROUTINE_TRACE("csr_matrix::move_to_device"); if(!is_device_available()) { @@ -220,9 +241,10 @@ void csr_matrix::move_to_device() on_host = false; } -void csr_matrix::move_to_host() +template +void csr_matrix::move_to_host() { - ROUTINE_TRACE("csr_matrix::move_to_host"); + ROUTINE_TRACE("csr_matrix::move_to_host"); csr_row_ptr.move_to_host(); csr_col_ind.move_to_host(); @@ -231,30 +253,33 @@ void csr_matrix::move_to_host() on_host = true; } -void csr_matrix::extract_diagonal(vector& diag) const +template +void csr_matrix::extract_diagonal(vector& diag) const { - ROUTINE_TRACE("csr_matrix::extract_diagonal"); + ROUTINE_TRACE("csr_matrix::extract_diagonal"); backend_dispatch( - "linalg::csr_matrix::extract_diagonal", host_diagonal, device_diagonal, *this, diag); + "linalg::csr_matrix::extract_diagonal", host_diagonal, device_diagonal, *this, diag); } -void csr_matrix::scale_diagonal_by(double scalar) +template +void csr_matrix::scale_diagonal_by(T scalar) { - ROUTINE_TRACE("csr_matrix::scale_diagonal_by"); + ROUTINE_TRACE("csr_matrix::scale_diagonal_by"); - backend_dispatch("linalg::csr_matrix::scale_diagonal_by", + backend_dispatch("linalg::csr_matrix::scale_diagonal_by", host_scale_diagonal, device_scale_diagonal, *this, scalar); } -void csr_matrix::scale_by_inverse_diagonal() +template +void csr_matrix::scale_by_inverse_diagonal() { - ROUTINE_TRACE("csr_matrix::scale_by_inverse_diagonal"); + ROUTINE_TRACE("csr_matrix::scale_by_inverse_diagonal"); - vector diag(this->m); + vector diag(this->m); if(this->is_on_host()) { diag.move_to_host(); @@ -267,16 +292,17 @@ void csr_matrix::scale_by_inverse_diagonal() this->extract_diagonal(diag); // Scale each row by the inverse of its diagonal element - backend_dispatch("linalg::csr_matrix::scale_by_inverse_diagonal", + backend_dispatch("linalg::csr_matrix::scale_by_inverse_diagonal", host_scale_by_inverse_diagonal, device_scale_by_inverse_diagonal, *this, diag); } -void csr_matrix::multiply_by_vector(vector& y, const vector& x) const +template +void csr_matrix::multiply_by_vector(vector& y, const vector& x) const { - ROUTINE_TRACE("csr_matrix::multiply_by_vector"); + ROUTINE_TRACE("csr_matrix::multiply_by_vector"); csrmv_descr* descr = nullptr; create_csrmv_descr(&descr); @@ -288,9 +314,10 @@ void csr_matrix::multiply_by_vector(vector& y, const vector& x) destroy_csrmv_descr(descr); } -void csr_matrix::multiply_by_vector_and_add(vector& y, const vector& x) const +template +void csr_matrix::multiply_by_vector_and_add(vector& y, const vector& x) const { - ROUTINE_TRACE("csr_matrix::multiply_by_vector_and_add"); + ROUTINE_TRACE("csr_matrix::multiply_by_vector_and_add"); csrmv_descr* descr = nullptr; create_csrmv_descr(&descr); @@ -302,9 +329,10 @@ void csr_matrix::multiply_by_vector_and_add(vector& y, const vector +void csr_matrix::multiply_by_matrix(csr_matrix& C, const csr_matrix& B) const { - ROUTINE_TRACE("csr_matrix::multiply_by_matrix"); + ROUTINE_TRACE("csr_matrix::multiply_by_matrix"); csr_matrix D; // Empty matrix for D @@ -324,11 +352,10 @@ void csr_matrix::multiply_by_matrix(csr_matrix& C, const csr_matrix& B) const destroy_csrgemm_descr(descr); } -void csr_matrix::triangular_solve_lower(vector& x, - const vector& y, - bool unit_diag) const +template +void csr_matrix::triangular_solve_lower(vector& x, const vector& y, bool unit_diag) const { - ROUTINE_TRACE("csr_matrix::triangular_solve_lower"); + ROUTINE_TRACE("csr_matrix::triangular_solve_lower"); csrtrsv_descr* descr = nullptr; create_csrtrsv_descr(&descr); @@ -342,7 +369,7 @@ void csr_matrix::triangular_solve_lower(vector& x, csrtrsv_solve(*this, y, x, - static_cast(1.0), + static_cast(1.0), triangular_type::lower, unit_diag ? diagonal_type::unit : diagonal_type::non_unit, descr); @@ -350,11 +377,10 @@ void csr_matrix::triangular_solve_lower(vector& x, destroy_csrtrsv_descr(descr); } -void csr_matrix::triangular_solve_upper(vector& x, - const vector& y, - bool unit_diag) const +template +void csr_matrix::triangular_solve_upper(vector& x, const vector& y, bool unit_diag) const { - ROUTINE_TRACE("csr_matrix::triangular_solve_upper"); + ROUTINE_TRACE("csr_matrix::triangular_solve_upper"); csrtrsv_descr* descr = nullptr; create_csrtrsv_descr(&descr); @@ -368,7 +394,7 @@ void csr_matrix::triangular_solve_upper(vector& x, csrtrsv_solve(*this, y, x, - static_cast(1.0), + static_cast(1.0), triangular_type::upper, unit_diag ? diagonal_type::unit : diagonal_type::non_unit, descr); @@ -376,9 +402,10 @@ void csr_matrix::triangular_solve_upper(vector& x, destroy_csrtrsv_descr(descr); } -void csr_matrix::compute_incomplete_cholesky_factorization() +template +void csr_matrix::compute_incomplete_cholesky_factorization() { - ROUTINE_TRACE("csr_matrix::compute_incomplete_cholesky_factorization"); + ROUTINE_TRACE("csr_matrix::compute_incomplete_cholesky_factorization"); csric0_descr* descr = nullptr; create_csric0_descr(&descr); @@ -391,9 +418,10 @@ void csr_matrix::compute_incomplete_cholesky_factorization() destroy_csric0_descr(descr); } -void csr_matrix::compute_incomplete_LU_factorization() +template +void csr_matrix::compute_incomplete_LU_factorization() { - ROUTINE_TRACE("csr_matrix::compute_incomplete_LU_factorization"); + ROUTINE_TRACE("csr_matrix::compute_incomplete_LU_factorization"); csrilu0_descr* descr = nullptr; create_csrilu0_descr(&descr); @@ -406,19 +434,24 @@ void csr_matrix::compute_incomplete_LU_factorization() destroy_csrilu0_descr(descr); } -void csr_matrix::transpose(csr_matrix& T) const +template +void csr_matrix::transpose(csr_matrix& T) const { - ROUTINE_TRACE("csr_matrix::transpose"); + ROUTINE_TRACE("csr_matrix::transpose"); - backend_dispatch( - "linalg::csr_matrix::transpose", host_transpose_matrix, device_transpose_matrix, *this, T); + backend_dispatch("linalg::csr_matrix::transpose", + host_transpose_matrix, + device_transpose_matrix, + *this, + T); } -void csr_matrix::apply_ruiz_scaling(vector& D1, vector& D2, int max_k, double tol) +template +void csr_matrix::apply_ruiz_scaling(vector& D1, vector& D2, int max_k, T tol) { - ROUTINE_TRACE("csr_matrix::apply_ruiz_scaling"); + ROUTINE_TRACE("csr_matrix::apply_ruiz_scaling"); - backend_dispatch("linalg::csr_matrix::apply_ruiz_scaling", + backend_dispatch("linalg::csr_matrix::apply_ruiz_scaling", host_ruiz_scaling, device_ruiz_scaling, D1, @@ -428,11 +461,12 @@ void csr_matrix::apply_ruiz_scaling(vector& D1, vector& D2, int tol); } -void csr_matrix::apply_symmetric_ruiz_scaling(vector& D, int max_k, double tol) +template +void csr_matrix::apply_symmetric_ruiz_scaling(vector& D, int max_k, T tol) { - ROUTINE_TRACE("csr_matrix::apply_symmetric_ruiz_scaling"); + ROUTINE_TRACE("csr_matrix::apply_symmetric_ruiz_scaling"); - backend_dispatch("linalg::csr_matrix::apply_symmetric_ruiz_scaling", + backend_dispatch("linalg::csr_matrix::apply_symmetric_ruiz_scaling", host_symmetric_ruiz_scaling, device_symmetric_ruiz_scaling, D, @@ -442,14 +476,15 @@ void csr_matrix::apply_symmetric_ruiz_scaling(vector& D, int max_k, doub } // Structure to hold triplet (COO) format data +template struct triplet { - int row; - int col; - double value; + int row; + int col; + T value; // For sorting: primarily by row, then by column - bool operator<(const triplet& other) const + bool operator<(const triplet& other) const { if(row != other.row) { @@ -485,9 +520,10 @@ static bool read_file_into_string(const std::string& filename, std::string& file return false; } -bool csr_matrix::read_mtx(const std::string& filename) +template +bool csr_matrix::read_mtx(const std::string& filename) { - ROUTINE_TRACE("csr_matrix::read_mtx"); + ROUTINE_TRACE("csr_matrix::read_mtx"); if(!this->is_on_host()) { @@ -590,7 +626,7 @@ bool csr_matrix::read_mtx(const std::string& filename) return false; } - std::vector triplets; + std::vector> triplets; triplets.reserve(is_symmetric ? nnz_coo * 2 : nnz_coo); // Reserve enough space for symmetric case @@ -611,9 +647,9 @@ bool csr_matrix::read_mtx(const std::string& filename) size_t second_space = line.find(' ', first_space + 1); // Extract substrings and convert to numbers - int r = std::stoi(line.substr(0, first_space)); - int c = std::stoi(line.substr(first_space + 1, second_space - (first_space + 1))); - double val = std::stod(line.substr(second_space + 1)); + int r = std::stoi(line.substr(0, first_space)); + int c = std::stoi(line.substr(first_space + 1, second_space - (first_space + 1))); + T val = std::stod(line.substr(second_space + 1)); triplets.push_back({r - 1, c - 1, val}); // Matrix Market is 1-indexed @@ -634,7 +670,7 @@ bool csr_matrix::read_mtx(const std::string& filename) // Also, sum values if multiple entries refer to the same (row, col) if(!triplets.empty()) { - std::vector unique_triplets; + std::vector> unique_triplets; unique_triplets.reserve(triplets.size()); unique_triplets.push_back(triplets[0]); @@ -676,7 +712,7 @@ bool csr_matrix::read_mtx(const std::string& filename) for(int64_t i = 0; i < nnz; ++i) { - const triplet& t = triplets[i]; + const triplet& t = triplets[i]; csr_row_ptr[t.row + 1]++; csr_col_ind[i] = t.col; @@ -692,9 +728,10 @@ bool csr_matrix::read_mtx(const std::string& filename) return true; } -bool csr_matrix::write_mtx(const std::string& filename) +template +bool csr_matrix::write_mtx(const std::string& filename) { - ROUTINE_TRACE("csr_matrix::write_mtx"); + ROUTINE_TRACE("csr_matrix::write_mtx"); if(!this->is_on_host()) { @@ -717,11 +754,11 @@ bool csr_matrix::write_mtx(const std::string& filename) // Determine data type for the header std::string data_type_str; - if(std::is_floating_point::value) + if(std::is_floating_point::value) { data_type_str = "real"; } - else if(std::is_integral::value) + else if(std::is_integral::value) { data_type_str = "integer"; } @@ -737,7 +774,7 @@ bool csr_matrix::write_mtx(const std::string& filename) file << m << " " << n << " " << nnz << "\n"; // Set precision for floating-point numbers if applicable - if(std::is_floating_point::value) + if(std::is_floating_point::value) { file << std::fixed << std::setprecision(10); // Adjust precision as needed } @@ -756,9 +793,10 @@ bool csr_matrix::write_mtx(const std::string& filename) return true; } -void csr_matrix::make_diagonally_dominant() +template +void csr_matrix::make_diagonally_dominant() { - ROUTINE_TRACE("csr_matrix::make_diagonally_dominant"); + ROUTINE_TRACE("csr_matrix::make_diagonally_dominant"); if(!this->is_on_host()) { @@ -797,7 +835,7 @@ void csr_matrix::make_diagonally_dominant() int start = csr_row_ptr[i]; int end = csr_row_ptr[i + 1]; - double row_sum = 0; + T row_sum = 0; for(int j = start; j < end; j++) { if(csr_col_ind[j] != i) @@ -810,16 +848,17 @@ void csr_matrix::make_diagonally_dominant() { if(csr_col_ind[j] == i) { - csr_val[j] = std::max(std::abs(csr_val[j]), 1.1 * row_sum); + csr_val[j] = std::max(std::abs(csr_val[j]), static_cast(1.1) * row_sum); break; } } } } -void csr_matrix::print_matrix(const std::string name) const +template +void csr_matrix::print_matrix(const std::string name) const { - ROUTINE_TRACE("csr_matrix::print_matrix"); + ROUTINE_TRACE("csr_matrix::print_matrix"); if(!this->is_on_host()) { @@ -833,7 +872,7 @@ void csr_matrix::print_matrix(const std::string name) const int start = csr_row_ptr[i]; int end = csr_row_ptr[i + 1]; - std::vector temp(n, 0.0); + std::vector temp(n, 0.0); for(int j = start; j < end; j++) { temp[csr_col_ind[j]] = (csr_val.get_size() != 0) ? csr_val[j] : 1.0; @@ -848,9 +887,10 @@ void csr_matrix::print_matrix(const std::string name) const std::cout << "" << std::endl; } -void csr_matrix::print_row_ptr(const std::string name) const +template +void csr_matrix::print_row_ptr(const std::string name) const { - ROUTINE_TRACE("csr_matrix::print_row_ptr"); + ROUTINE_TRACE("csr_matrix::print_row_ptr"); if(!this->is_on_host()) { @@ -865,9 +905,11 @@ void csr_matrix::print_row_ptr(const std::string name) const } std::cout << "" << std::endl; } -void csr_matrix::print_col_ind(const std::string name) const + +template +void csr_matrix::print_col_ind(const std::string name) const { - ROUTINE_TRACE("csr_matrix::print_col_ind"); + ROUTINE_TRACE("csr_matrix::print_col_ind"); if(!this->is_on_host()) { @@ -882,9 +924,11 @@ void csr_matrix::print_col_ind(const std::string name) const } std::cout << "" << std::endl; } -void csr_matrix::print_values(const std::string name) const + +template +void csr_matrix::print_values(const std::string name) const { - ROUTINE_TRACE("csr_matrix::print_values"); + ROUTINE_TRACE("csr_matrix::print_values"); if(!this->is_on_host()) { @@ -900,15 +944,16 @@ void csr_matrix::print_values(const std::string name) const std::cout << "" << std::endl; } -void csr_matrix::print_matrix(const std::string name, - int m, - int n, - int nnz, - const std::vector& csr_row_ptr, - const std::vector& csr_col_ind, - const std::vector& csr_val) +template +void csr_matrix::print_matrix(const std::string name, + int m, + int n, + int nnz, + const std::vector& csr_row_ptr, + const std::vector& csr_col_ind, + const std::vector& csr_val) { - ROUTINE_TRACE("csr_matrix::print_matrix"); + ROUTINE_TRACE("csr_matrix::print_matrix"); std::cout << name << std::endl; for(int i = 0; i < m; i++) @@ -916,7 +961,7 @@ void csr_matrix::print_matrix(const std::string name, int start = csr_row_ptr[i]; int end = csr_row_ptr[i + 1]; - std::vector temp(n, 0.0); + std::vector temp(n, 0.0); for(int j = start; j < end; j++) { temp[csr_col_ind[j]] = (nnz != 0) ? csr_val[j] : 1.0; @@ -930,3 +975,6 @@ void csr_matrix::print_matrix(const std::string name, } std::cout << "" << std::endl; } + +// template class linalg::csr_matrix; +template class linalg::csr_matrix; diff --git a/library/src/iterative_solvers/amg/amg.cpp b/library/src/iterative_solvers/amg/amg.cpp index d82bf87..a2ab528 100644 --- a/library/src/iterative_solvers/amg/amg.cpp +++ b/library/src/iterative_solvers/amg/amg.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -88,27 +88,29 @@ namespace linalg on_host = true; } - void jacobi_iteration(const csr_matrix& A, - vector& x, - const vector& xold, - const vector& b); - void gauss_seidel_iteration(const csr_matrix& A, vector& x, const vector& b); - void symm_gauss_seidel_iteration(const csr_matrix& A, - vector& x, - const vector& b); - void sor_iteration(const csr_matrix& A, - vector& x, - const vector& b, - const double omega); - void ssor_iteration(const csr_matrix& A, - vector& x, - const vector& b, - const double omega); - - static void apply_smoother(const csr_matrix& A, - vector& x, - const vector& b, - smoother smoother) + void jacobi_iteration(const csr_matrix& A, + vector& x, + const vector& xold, + const vector& b); + void gauss_seidel_iteration(const csr_matrix& A, + vector& x, + const vector& b); + void symm_gauss_seidel_iteration(const csr_matrix& A, + vector& x, + const vector& b); + void sor_iteration(const csr_matrix& A, + vector& x, + const vector& b, + const double omega); + void ssor_iteration(const csr_matrix& A, + vector& x, + const vector& b, + const double omega); + + static void apply_smoother(const csr_matrix& A, + vector& x, + const vector& b, + smoother smoother) { ROUTINE_TRACE("apply_smoother"); @@ -150,15 +152,15 @@ namespace linalg ROUTINE_TRACE("vcycle"); // A_coarse = R*A*P - const csr_matrix& A = hierarchy.A_cs[currentLevel]; + const csr_matrix& A = hierarchy.A_cs[currentLevel]; int N = A.get_m(); // size of A at current level if(currentLevel < hierarchy.total_levels) { - const csr_matrix& R = hierarchy.restrictions[currentLevel]; - const csr_matrix& P = hierarchy.prolongations[currentLevel]; - const csr_matrix& A_coarse = hierarchy.A_cs[currentLevel + 1]; + const csr_matrix& R = hierarchy.restrictions[currentLevel]; + const csr_matrix& P = hierarchy.prolongations[currentLevel]; + const csr_matrix& A_coarse = hierarchy.A_cs[currentLevel + 1]; int Nc = A_coarse.get_m(); // size of A at next course level @@ -276,15 +278,15 @@ namespace linalg ROUTINE_TRACE("wcycle"); // A_coarse = R*A*P - const csr_matrix& A = hierarchy.A_cs[currentLevel]; + const csr_matrix& A = hierarchy.A_cs[currentLevel]; int N = A.get_m(); // size of A at current level if(currentLevel < hierarchy.total_levels) { - const csr_matrix& R = hierarchy.restrictions[currentLevel]; - const csr_matrix& P = hierarchy.prolongations[currentLevel]; - const csr_matrix& A_coarse = hierarchy.A_cs[currentLevel + 1]; + const csr_matrix& R = hierarchy.restrictions[currentLevel]; + const csr_matrix& P = hierarchy.prolongations[currentLevel]; + const csr_matrix& A_coarse = hierarchy.A_cs[currentLevel + 1]; int Nc = A_coarse.get_m(); // size of A at next course level @@ -399,15 +401,15 @@ namespace linalg ROUTINE_TRACE("fcycle"); // A_coarse = R*A*P - const csr_matrix& A = hierarchy.A_cs[currentLevel]; + const csr_matrix& A = hierarchy.A_cs[currentLevel]; int N = A.get_m(); // size of A at current level if(currentLevel < hierarchy.total_levels) { - const csr_matrix& R = hierarchy.restrictions[currentLevel]; - const csr_matrix& P = hierarchy.prolongations[currentLevel]; - const csr_matrix& A_coarse = hierarchy.A_cs[currentLevel + 1]; + const csr_matrix& R = hierarchy.restrictions[currentLevel]; + const csr_matrix& P = hierarchy.prolongations[currentLevel]; + const csr_matrix& A_coarse = hierarchy.A_cs[currentLevel + 1]; int Nc = A_coarse.get_m(); // size of A at next course level @@ -524,7 +526,7 @@ int linalg::amg_solve(const hierarchy& hierarchy, auto t1 = std::chrono::high_resolution_clock::now(); - const csr_matrix& A = hierarchy.A_cs[0]; + const csr_matrix& A = hierarchy.A_cs[0]; vector residual(A.get_m()); compute_residual(A, x, b, residual); diff --git a/library/src/iterative_solvers/amg/amg_aggregation.cpp b/library/src/iterative_solvers/amg/amg_aggregation.cpp index 7e716ff..93af320 100644 --- a/library/src/iterative_solvers/amg/amg_aggregation.cpp +++ b/library/src/iterative_solvers/amg/amg_aggregation.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -44,10 +44,10 @@ namespace linalg { - static void initialize_pmis_state(const csr_matrix& A, - const vector& connections, - vector& state, - vector& hash) + static void initialize_pmis_state(const csr_matrix& A, + const vector& connections, + vector& state, + vector& hash) { ROUTINE_TRACE("initialize_pmis_state"); @@ -60,13 +60,13 @@ namespace linalg hash); } - static void find_maximum_distance_two_node(const csr_matrix& A, - const vector& connections, - const vector& state, - const vector& hash, - vector& aggregates, - vector& max_state, - bool& complete) + static void find_maximum_distance_two_node(const csr_matrix& A, + const vector& connections, + const vector& state, + const vector& hash, + vector& aggregates, + vector& max_state, + bool& complete) { ROUTINE_TRACE("find_maximum_distance_two_node"); @@ -82,12 +82,12 @@ namespace linalg complete); } - static void add_unassigned_nodes_to_closest_aggregation(const csr_matrix& A, - const vector& connections, - const vector& state, - vector& aggregates, - vector& aggregate_root_nodes, - vector& max_state) + static void add_unassigned_nodes_to_closest_aggregation(const csr_matrix& A, + const vector& connections, + const vector& state, + vector& aggregates, + vector& aggregate_root_nodes, + vector& max_state) { ROUTINE_TRACE("add_unassigned_nodes_to_closest_aggregation"); @@ -103,10 +103,10 @@ namespace linalg } } -bool linalg::compute_aggregates_using_pmis(const csr_matrix& A, - const vector& connections, - vector& aggregates, - vector& aggregate_root_nodes) +bool linalg::compute_aggregates_using_pmis(const csr_matrix& A, + const vector& connections, + vector& aggregates, + vector& aggregate_root_nodes) { ROUTINE_TRACE("linalg::compute_aggregates_using_pmis"); @@ -222,9 +222,9 @@ bool linalg::compute_aggregates_using_pmis(const csr_matrix& A, #define U_POINT 2 // Unassigned point #define FF_POINT 3 // Future F-point -void linalg::compute_cfpoint_first_pass(const csr_matrix& S, - const csr_matrix& ST, - vector& cfpoints) +void linalg::compute_cfpoint_first_pass(const csr_matrix& S, + const csr_matrix& ST, + vector& cfpoints) { ROUTINE_TRACE("linalg::compute_cfpoint_first_pass"); @@ -239,7 +239,7 @@ void linalg::compute_cfpoint_first_pass(const csr_matrix& S, //------------------------------------------------------------------------------- // function for finding c-points and f-points (second pass) //------------------------------------------------------------------------------- -void linalg::compute_cfpoint_second_pass(const csr_matrix& S, vector& cfpoints) +void linalg::compute_cfpoint_second_pass(const csr_matrix& S, vector& cfpoints) { ROUTINE_TRACE("linalg::compute_cfpoint_second_pass"); diff --git a/library/src/iterative_solvers/amg/amg_strength.cpp b/library/src/iterative_solvers/amg/amg_strength.cpp index 2cfcb1d..5c85098 100644 --- a/library/src/iterative_solvers/amg/amg_strength.cpp +++ b/library/src/iterative_solvers/amg/amg_strength.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -37,7 +37,9 @@ #include "../../backend/device/device_amg_strength.h" #include "../../backend/host/host_amg_strength.h" -void linalg::compute_strong_connections(const csr_matrix& A, double eps, vector& connections) +void linalg::compute_strong_connections(const csr_matrix& A, + double eps, + vector& connections) { ROUTINE_TRACE("compute_strong_connections"); @@ -52,10 +54,10 @@ void linalg::compute_strong_connections(const csr_matrix& A, double eps, vector< //------------------------------------------------------------------------------- // -A[i,j] >= theta * max( -A[i,k] ) where k != i //------------------------------------------------------------------------------- -void linalg::compute_classical_strong_connections(const csr_matrix& A, - double theta, - csr_matrix& S, - vector& connections) +void linalg::compute_classical_strong_connections(const csr_matrix& A, + double theta, + csr_matrix& S, + vector& connections) { ROUTINE_TRACE("compute_classical_strong_connections"); diff --git a/library/src/iterative_solvers/amg/amg_util.cpp b/library/src/iterative_solvers/amg/amg_util.cpp index d44dd14..6ee16b9 100644 --- a/library/src/iterative_solvers/amg/amg_util.cpp +++ b/library/src/iterative_solvers/amg/amg_util.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -28,15 +28,15 @@ #include "../../trace.h" -void linalg::galarkin_triple_product(const csr_matrix& R, - const csr_matrix& A, - const csr_matrix& P, - csr_matrix& A_coarse) +void linalg::galarkin_triple_product(const csr_matrix& R, + const csr_matrix& A, + const csr_matrix& P, + csr_matrix& A_coarse) { ROUTINE_TRACE("galarkin_triple_product"); // Compute AP = A * P; - csr_matrix AP; + csr_matrix AP; A.multiply_by_matrix(AP, P); // Compute A_coarse = R * A * P diff --git a/library/src/iterative_solvers/amg/rsamg.cpp b/library/src/iterative_solvers/amg/rsamg.cpp index feb01b4..2debaed 100644 --- a/library/src/iterative_solvers/amg/rsamg.cpp +++ b/library/src/iterative_solvers/amg/rsamg.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -39,7 +39,6 @@ #include #include - #include "../../trace.h" // //------------------------------------------------------------------------------- @@ -670,10 +669,10 @@ namespace linalg { - static void direct_interpolation(const csr_matrix& A, - const csr_matrix& S, - csr_matrix& P, - vector& cfpoints) + static void direct_interpolation(const csr_matrix& A, + const csr_matrix& S, + csr_matrix& P, + vector& cfpoints) { // Determine number of C points. The prolongation operator will have number // of columns equal to the number of C points @@ -867,7 +866,7 @@ namespace linalg } } -void linalg::rsamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarchy) +void linalg::rsamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarchy) { ROUTINE_TRACE("rsamg_setup"); @@ -888,13 +887,13 @@ void linalg::rsamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarch { std::cout << "Compute operators at coarse level: " << level << std::endl; - const csr_matrix& A_fine = hierarchy.A_cs[level]; - csr_matrix& A_coarse = hierarchy.A_cs[level + 1]; - csr_matrix& P = hierarchy.prolongations[level]; - csr_matrix& R = hierarchy.restrictions[level]; + const csr_matrix& A_fine = hierarchy.A_cs[level]; + csr_matrix& A_coarse = hierarchy.A_cs[level + 1]; + csr_matrix& P = hierarchy.prolongations[level]; + csr_matrix& R = hierarchy.restrictions[level]; - csr_matrix S; - csr_matrix ST; + csr_matrix S; + csr_matrix ST; vector connections(A_fine.get_nnz(), 0); vector cfpoints(A_fine.get_m(), 0); @@ -945,4 +944,4 @@ void linalg::rsamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarch std::chrono::duration ms_double = t2 - t1; std::cout << "Ruge Steuben amg setup time: " << ms_double.count() << "ms" << std::endl; -} \ No newline at end of file +} diff --git a/library/src/iterative_solvers/amg/saamg.cpp b/library/src/iterative_solvers/amg/saamg.cpp index 2965708..ea6c293 100644 --- a/library/src/iterative_solvers/amg/saamg.cpp +++ b/library/src/iterative_solvers/amg/saamg.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -49,12 +49,12 @@ namespace linalg { static bool construct_prolongation_using_smoothed_aggregation( - const csr_matrix& A, - const vector& connections, - const vector& aggregates, - const vector& aggregate_root_nodes, - double relax, - csr_matrix& prolongation) + const csr_matrix& A, + const vector& connections, + const vector& aggregates, + const vector& aggregate_root_nodes, + double relax, + csr_matrix& prolongation) { ROUTINE_TRACE("construct_prolongation_using_smoothed_aggregation"); @@ -63,7 +63,6 @@ namespace linalg aggregates.print_vector("aggregates"); } - // Determine number of columns in the prolongation matrix. This will be // the maximum aggregate plus one. int64_t n = -1; @@ -208,7 +207,7 @@ namespace linalg } } -void linalg::saamg_setup(const csr_matrix& mat_A, int max_level, hierarchy& hierarchy) +void linalg::saamg_setup(const csr_matrix& mat_A, int max_level, hierarchy& hierarchy) { ROUTINE_TRACE("saamg_setup"); @@ -234,10 +233,10 @@ void linalg::saamg_setup(const csr_matrix& mat_A, int max_level, hierarchy& hier { std::cout << "Compute operators at coarse level: " << level << std::endl; - const csr_matrix& A_fine = hierarchy.A_cs[level]; - csr_matrix& A_coarse = hierarchy.A_cs[level + 1]; - csr_matrix& P = hierarchy.prolongations[level]; - csr_matrix& R = hierarchy.restrictions[level]; + const csr_matrix& A_fine = hierarchy.A_cs[level]; + csr_matrix& A_coarse = hierarchy.A_cs[level + 1]; + csr_matrix& P = hierarchy.prolongations[level]; + csr_matrix& R = hierarchy.restrictions[level]; connections.resize(A_fine.get_nnz(), 0); aggregates.resize(A_fine.get_m(), 0); @@ -280,4 +279,4 @@ void linalg::saamg_setup(const csr_matrix& mat_A, int max_level, hierarchy& hier std::chrono::duration ms_double = t2 - t1; std::cout << "Smoothed Aggregation amg setup time: " << ms_double.count() << "ms" << std::endl; -} \ No newline at end of file +} diff --git a/library/src/iterative_solvers/amg/uaamg.cpp b/library/src/iterative_solvers/amg/uaamg.cpp index a4e016f..e8efcb8 100644 --- a/library/src/iterative_solvers/amg/uaamg.cpp +++ b/library/src/iterative_solvers/amg/uaamg.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -47,11 +47,11 @@ namespace linalg { static bool construct_prolongation_using_unsmoothed_aggregation( - const csr_matrix& A, - const vector& connections, - const vector& aggregates, - const vector& aggregate_root_nodes, - csr_matrix& prolongation) + const csr_matrix& A, + const vector& connections, + const vector& aggregates, + const vector& aggregate_root_nodes, + csr_matrix& prolongation) { ROUTINE_TRACE("construct_prolongation_using_unsmoothed_aggregation"); @@ -128,7 +128,7 @@ namespace linalg } } -void linalg::uaamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarchy) +void linalg::uaamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarchy) { ROUTINE_TRACE("uaamg_setup"); @@ -160,10 +160,10 @@ void linalg::uaamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarch { std::cout << "Compute operators at coarse level: " << level << std::endl; - const csr_matrix& A_fine = hierarchy.A_cs[level]; - csr_matrix& A_coarse = hierarchy.A_cs[level + 1]; - csr_matrix& P = hierarchy.prolongations[level]; - csr_matrix& R = hierarchy.restrictions[level]; + const csr_matrix& A_fine = hierarchy.A_cs[level]; + csr_matrix& A_coarse = hierarchy.A_cs[level + 1]; + csr_matrix& P = hierarchy.prolongations[level]; + csr_matrix& R = hierarchy.restrictions[level]; // A_fine.print_matrix("A_fine"); @@ -202,9 +202,9 @@ void linalg::uaamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarch // Compute coarse grid matrix using Galarkin triple product A_c = R * A_f * P galarkin_triple_product(R, A_fine, P, A_coarse); - std::cout << "R.m: " << R.get_m() << " R.n: " << R.get_n() + std::cout << "R.m: " << R.get_m() << " R.n: " << R.get_n() << " A_fine.get_m(): " << A_fine.get_m() << " A_fine.get_n(): " << A_fine.get_n() - << " P.m: " << P.get_m() << " P.n: " << P.get_n() << std::endl; + << " P.m: " << P.get_m() << " P.n: " << P.get_n() << std::endl; level++; eps *= 0.5; @@ -221,4 +221,4 @@ void linalg::uaamg_setup(const csr_matrix& A, int max_level, hierarchy& hierarch std::chrono::duration ms_double = t2 - t1; std::cout << "Unsmoothed Aggregation amg setup time: " << ms_double.count() << "ms" << std::endl; -} \ No newline at end of file +} diff --git a/library/src/iterative_solvers/classic/gauss_seidel.cpp b/library/src/iterative_solvers/classic/gauss_seidel.cpp index 486a337..59c7c75 100644 --- a/library/src/iterative_solvers/classic/gauss_seidel.cpp +++ b/library/src/iterative_solvers/classic/gauss_seidel.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,7 +31,6 @@ #include #include - #include "../../trace.h" using namespace linalg; @@ -48,7 +47,9 @@ using namespace linalg; //------------------------------------------------------------------------------- namespace linalg { - void gauss_seidel_iteration(const csr_matrix& A, vector& x, const vector& b) + void gauss_seidel_iteration(const csr_matrix& A, + vector& x, + const vector& b) { ROUTINE_TRACE("gauss_seidel_iteration"); @@ -90,15 +91,15 @@ gs_solver::gs_solver() {} gs_solver::~gs_solver() {} -void gs_solver::build(const csr_matrix& A) +void gs_solver::build(const csr_matrix& A) { res.resize(A.get_m()); } -int gs_solver::solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control) +int gs_solver::solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control) { ROUTINE_TRACE("gs_solver::solve"); @@ -133,4 +134,4 @@ int gs_solver::solve(const csr_matrix& A, std::cout << "Gauss Seidel time: " << ms_double.count() << "ms" << std::endl; return iter; -} \ No newline at end of file +} diff --git a/library/src/iterative_solvers/classic/jacobi.cpp b/library/src/iterative_solvers/classic/jacobi.cpp index 7813767..6962064 100644 --- a/library/src/iterative_solvers/classic/jacobi.cpp +++ b/library/src/iterative_solvers/classic/jacobi.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,7 +31,6 @@ #include #include - #include "../../trace.h" using namespace linalg; @@ -41,10 +40,10 @@ using namespace linalg; //------------------------------------------------------------------------------- namespace linalg { - void jacobi_iteration(const csr_matrix& A, - vector& x, - const vector& xold, - const vector& b) + void jacobi_iteration(const csr_matrix& A, + vector& x, + const vector& xold, + const vector& b) { ROUTINE_TRACE("jacobi_iteration"); @@ -80,16 +79,16 @@ jacobi_solver::jacobi_solver() {} jacobi_solver::~jacobi_solver() {} -void jacobi_solver::build(const csr_matrix& A) +void jacobi_solver::build(const csr_matrix& A) { xold.resize(A.get_m()); res.resize(A.get_m()); } -int jacobi_solver::solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control) +int jacobi_solver::solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control) { ROUTINE_TRACE("jacobi_solver::solve"); @@ -129,4 +128,4 @@ int jacobi_solver::solve(const csr_matrix& A, std::cout << "Jacobi time: " << ms_double.count() << "ms" << std::endl; return iter; -} \ No newline at end of file +} diff --git a/library/src/iterative_solvers/classic/richardson.cpp b/library/src/iterative_solvers/classic/richardson.cpp index 746069b..354abce 100644 --- a/library/src/iterative_solvers/classic/richardson.cpp +++ b/library/src/iterative_solvers/classic/richardson.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2019 James Sandham +// Copyright(c) 2019-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,7 +31,6 @@ #include #include - #include "../../trace.h" using namespace linalg; @@ -41,10 +40,10 @@ using namespace linalg; //------------------------------------------------------------------------------- namespace linalg { - void richardson_iteration(const csr_matrix& A, - vector& x, - vector& res, - double theta) + void richardson_iteration(const csr_matrix& A, + vector& x, + vector& res, + double theta) { ROUTINE_TRACE("richardson_iteration"); @@ -66,16 +65,16 @@ rich_solver::rich_solver() {} rich_solver::~rich_solver() {} -void rich_solver::build(const csr_matrix& A) +void rich_solver::build(const csr_matrix& A) { res.resize(A.get_m()); } -int rich_solver::solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control, - double theta) +int rich_solver::solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control, + double theta) { ROUTINE_TRACE("rich_solver::solve"); diff --git a/library/src/iterative_solvers/classic/sor.cpp b/library/src/iterative_solvers/classic/sor.cpp index fc8f03e..35d5ca0 100644 --- a/library/src/iterative_solvers/classic/sor.cpp +++ b/library/src/iterative_solvers/classic/sor.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,7 +31,6 @@ #include #include - #include "../../trace.h" using namespace linalg; @@ -41,8 +40,10 @@ using namespace linalg; //------------------------------------------------------------------------------- namespace linalg { - void - sor_iteration(const csr_matrix& A, vector& x, const vector& b, double omega) + void sor_iteration(const csr_matrix& A, + vector& x, + const vector& b, + double omega) { ROUTINE_TRACE("sor_iteration"); @@ -85,16 +86,16 @@ sor_solver::sor_solver() {} sor_solver::~sor_solver() {} -void sor_solver::build(const csr_matrix& A) +void sor_solver::build(const csr_matrix& A) { res.resize(A.get_m()); } -int sor_solver::solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control, - double omega) +int sor_solver::solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control, + double omega) { ROUTINE_TRACE("sor_solver::solve"); diff --git a/library/src/iterative_solvers/classic/ssor.cpp b/library/src/iterative_solvers/classic/ssor.cpp index e9a4ab2..f0a34f5 100644 --- a/library/src/iterative_solvers/classic/ssor.cpp +++ b/library/src/iterative_solvers/classic/ssor.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,7 +31,6 @@ #include #include - #include "../../trace.h" using namespace linalg; @@ -41,10 +40,10 @@ using namespace linalg; //------------------------------------------------------------------------------- namespace linalg { - void ssor_iteration(const csr_matrix& A, - vector& x, - const vector& b, - double omega) + void ssor_iteration(const csr_matrix& A, + vector& x, + const vector& b, + double omega) { ROUTINE_TRACE("ssor_iteration"); @@ -114,16 +113,16 @@ ssor_solver::ssor_solver() {} ssor_solver::~ssor_solver() {} -void ssor_solver::build(const csr_matrix& A) +void ssor_solver::build(const csr_matrix& A) { res.resize(A.get_m()); } -int ssor_solver::solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control, - double omega) +int ssor_solver::solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control, + double omega) { ROUTINE_TRACE("ssor_solver::solve"); diff --git a/library/src/iterative_solvers/classic/symmetric_gauss_seidel.cpp b/library/src/iterative_solvers/classic/symmetric_gauss_seidel.cpp index 35fb846..ec8f871 100644 --- a/library/src/iterative_solvers/classic/symmetric_gauss_seidel.cpp +++ b/library/src/iterative_solvers/classic/symmetric_gauss_seidel.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -31,7 +31,6 @@ #include #include - #include "../../trace.h" using namespace linalg; @@ -41,8 +40,9 @@ using namespace linalg; //------------------------------------------------------------------------------- namespace linalg { - void - symm_gauss_seidel_iteration(const csr_matrix& A, vector& x, const vector& b) + void symm_gauss_seidel_iteration(const csr_matrix& A, + vector& x, + const vector& b) { ROUTINE_TRACE("symm_gauss_seidel_iteration"); @@ -112,15 +112,15 @@ sgs_solver::sgs_solver() {} sgs_solver::~sgs_solver() {} -void sgs_solver::build(const csr_matrix& A) +void sgs_solver::build(const csr_matrix& A) { res.resize(A.get_m()); } -int sgs_solver::solve(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control) +int sgs_solver::solve(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control) { ROUTINE_TRACE("sgs_solver::solve"); @@ -155,4 +155,4 @@ int sgs_solver::solve(const csr_matrix& A, std::cout << "Symmetric Gauss Seidel time: " << ms_double.count() << "ms" << std::endl; return iter; -} \ No newline at end of file +} diff --git a/library/src/iterative_solvers/krylov/bicgstab.cpp b/library/src/iterative_solvers/krylov/bicgstab.cpp index 7df3166..ee82a91 100644 --- a/library/src/iterative_solvers/krylov/bicgstab.cpp +++ b/library/src/iterative_solvers/krylov/bicgstab.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024-2025 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -50,7 +50,7 @@ bicgstab_solver::bicgstab_solver() bicgstab_solver::~bicgstab_solver() {} -void bicgstab_solver::build(const csr_matrix& A) +void bicgstab_solver::build(const csr_matrix& A) { r.resize(A.get_m()); r0.resize(A.get_m()); @@ -61,10 +61,10 @@ void bicgstab_solver::build(const csr_matrix& A) q.resize(A.get_m()); } -int bicgstab_solver::solve_nonprecond(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control) +int bicgstab_solver::solve_nonprecond(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control) { ROUTINE_TRACE("bicgstab_solver::solve_nonprecond"); @@ -140,11 +140,11 @@ int bicgstab_solver::solve_nonprecond(const csr_matrix& A, return iter; } -int bicgstab_solver::solve_precond(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control) +int bicgstab_solver::solve_precond(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control) { ROUTINE_TRACE("bicgstab_solver::solve_precond"); @@ -231,11 +231,11 @@ int bicgstab_solver::solve_precond(const csr_matrix& A, return iter; } -int bicgstab_solver::solve(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control) +int bicgstab_solver::solve(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control) { ROUTINE_TRACE("bicgstab_solver::solve"); diff --git a/library/src/iterative_solvers/krylov/cg.cpp b/library/src/iterative_solvers/krylov/cg.cpp index 4a3418f..f012bc8 100644 --- a/library/src/iterative_solvers/krylov/cg.cpp +++ b/library/src/iterative_solvers/krylov/cg.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2024-2025 James Sandham +// Copyright(c) 2024-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -50,17 +50,17 @@ cg_solver::cg_solver() cg_solver::~cg_solver() {} -void cg_solver::build(const csr_matrix& A) +void cg_solver::build(const csr_matrix& A) { p.resize(A.get_m()); z.resize(A.get_m()); res.resize(A.get_m()); } -int cg_solver::solve_nonprecond(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control) +int cg_solver::solve_nonprecond(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control) { ROUTINE_TRACE("cg_solver::solve_nonprecond"); @@ -133,11 +133,11 @@ int cg_solver::solve_nonprecond(const csr_matrix& A, return iter; } -int cg_solver::solve_precond(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control) +int cg_solver::solve_precond(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control) { ROUTINE_TRACE("cg_solver::solve_precond"); @@ -222,11 +222,11 @@ int cg_solver::solve_precond(const csr_matrix& A, return iter; } -int cg_solver::solve(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control) +int cg_solver::solve(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control) { ROUTINE_TRACE("cg_solver::solve"); @@ -265,4 +265,4 @@ void cg_solver::move_to_device() bool cg_solver::is_on_host() const { return on_host; -} \ No newline at end of file +} diff --git a/library/src/iterative_solvers/krylov/gmres.cpp b/library/src/iterative_solvers/krylov/gmres.cpp index 504c555..2010704 100644 --- a/library/src/iterative_solvers/krylov/gmres.cpp +++ b/library/src/iterative_solvers/krylov/gmres.cpp @@ -33,7 +33,6 @@ #include #include - #include "../../trace.h" using namespace linalg; @@ -209,7 +208,7 @@ gmres_solver::gmres_solver() gmres_solver::~gmres_solver() {} -void gmres_solver::build(const csr_matrix& A, int restart) +void gmres_solver::build(const csr_matrix& A, int restart) { this->restart = std::min(restart, A.get_m() - 1); @@ -222,10 +221,10 @@ void gmres_solver::build(const csr_matrix& A, int restart) s.resize(restart); } -int gmres_solver::solve_nonprecond(const csr_matrix& A, - vector& x, - const vector& b, - iter_control control) +int gmres_solver::solve_nonprecond(const csr_matrix& A, + vector& x, + const vector& b, + iter_control control) { ROUTINE_TRACE("gmres_solver::solve_nonprecond"); @@ -368,11 +367,11 @@ int gmres_solver::solve_nonprecond(const csr_matrix& A, return iter; } -int gmres_solver::solve_precond(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control) +int gmres_solver::solve_precond(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control) { ROUTINE_TRACE("gmres_solver::solve_precond"); @@ -523,11 +522,11 @@ int gmres_solver::solve_precond(const csr_matrix& A, return iter; } -int gmres_solver::solve(const csr_matrix& A, - vector& x, - const vector& b, - const preconditioner* precond, - iter_control control) +int gmres_solver::solve(const csr_matrix& A, + vector& x, + const vector& b, + const preconditioner* precond, + iter_control control) { ROUTINE_TRACE("gmres_solver::solve"); @@ -539,4 +538,4 @@ int gmres_solver::solve(const csr_matrix& A, { return solve_precond(A, x, b, precond, control); } -} \ No newline at end of file +} diff --git a/library/src/iterative_solvers/preconditioner/preconditioner.cpp b/library/src/iterative_solvers/preconditioner/preconditioner.cpp index e47e945..f7e13c4 100644 --- a/library/src/iterative_solvers/preconditioner/preconditioner.cpp +++ b/library/src/iterative_solvers/preconditioner/preconditioner.cpp @@ -2,7 +2,7 @@ // // MIT License // -// Copyright(c) 2025 James Sandham +// Copyright(c) 2025-2026 James Sandham // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this softwareand associated documentation files(the "Software"), to deal @@ -44,7 +44,7 @@ jacobi_precond::jacobi_precond() } jacobi_precond::~jacobi_precond() {} -void jacobi_precond::build(const csr_matrix& A) +void jacobi_precond::build(const csr_matrix& A) { ROUTINE_TRACE("jacobi_precond::build"); @@ -87,7 +87,7 @@ gauss_seidel_precond::~gauss_seidel_precond() destroy_csrtrsv_descr(descr_M); } -void gauss_seidel_precond::build(const csr_matrix& A) +void gauss_seidel_precond::build(const csr_matrix& A) { ROUTINE_TRACE("gauss_seidel_precond::build"); @@ -134,7 +134,7 @@ SOR_precond::~SOR_precond() destroy_csrtrsv_descr(descr_M); } -void SOR_precond::build(const csr_matrix& A) +void SOR_precond::build(const csr_matrix& A) { ROUTINE_TRACE("SOR_precond::build"); @@ -184,7 +184,7 @@ symmetric_gauss_seidel_precond::~symmetric_gauss_seidel_precond() destroy_csrtrsv_descr(descr_U); } -void symmetric_gauss_seidel_precond::build(const csr_matrix& A) +void symmetric_gauss_seidel_precond::build(const csr_matrix& A) { ROUTINE_TRACE("symmetric_gauss_seidel_precond::build"); @@ -280,7 +280,7 @@ SSOR_precond::~SSOR_precond() destroy_csrtrsv_descr(descr_U); } -void SSOR_precond::build(const csr_matrix& A) +void SSOR_precond::build(const csr_matrix& A) { ROUTINE_TRACE("SSOR_precond::build"); @@ -429,7 +429,7 @@ ilu_precond::~ilu_precond() destroy_csrtrsv_descr(descr_U); } -void ilu_precond::build(const csr_matrix& A) +void ilu_precond::build(const csr_matrix& A) { ROUTINE_TRACE("ilu_precond::build"); @@ -492,7 +492,7 @@ ic_precond::~ic_precond() destroy_csrtrsv_descr(descr_LT); } -void ic_precond::build(const csr_matrix& A) +void ic_precond::build(const csr_matrix& A) { ROUTINE_TRACE("ic_precond::build"); @@ -547,7 +547,7 @@ itilu_precond::itilu_precond() } itilu_precond::~itilu_precond() {} -void itilu_precond::build(const csr_matrix& A) +void itilu_precond::build(const csr_matrix& A) { // this->LU.copy_from(A); diff --git a/library/src/linalg_math.cpp b/library/src/linalg_math.cpp index 0ff4101..c28c150 100644 --- a/library/src/linalg_math.cpp +++ b/library/src/linalg_math.cpp @@ -72,7 +72,7 @@ void linalg::axpbypgz(double alpha, } // Incomplete IC factorization -void linalg::csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero) +void linalg::csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero) { ROUTINE_TRACE("linalg::csric0"); @@ -81,7 +81,7 @@ void linalg::csric0(csr_matrix& LL, int* structural_zero, int* numeric_zero) } // Incomplete LU factorization -void linalg::csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero) +void linalg::csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero) { ROUTINE_TRACE("linalg::csrilu0"); @@ -90,7 +90,7 @@ void linalg::csrilu0(csr_matrix& LU, int* structural_zero, int* numeric_zero) } // Transpose matrix -void linalg::transpose_matrix(const csr_matrix& A, csr_matrix& transposeA) +void linalg::transpose_matrix(const csr_matrix& A, csr_matrix& transposeA) { ROUTINE_TRACE("linalg::transpose_matrix"); @@ -107,10 +107,10 @@ double linalg::dot_product(const vector& x, const vector& y) } // Compute residual -void linalg::compute_residual(const csr_matrix& A, - const vector& x, - const vector& b, - vector& res) +void linalg::compute_residual(const csr_matrix& A, + const vector& x, + const vector& b, + vector& res) { ROUTINE_TRACE("linalg::compute_residual"); @@ -119,7 +119,7 @@ void linalg::compute_residual(const csr_matrix& A, } // Extract diagonal entries -void linalg::diagonal(const csr_matrix& A, vector& d) +void linalg::diagonal(const csr_matrix& A, vector& d) { ROUTINE_TRACE("linalg::diagonal"); @@ -164,10 +164,10 @@ void linalg::destroy_csrtrsv_descr(csrtrsv_descr* descr) } } -void linalg::csrtrsv_analysis(const csr_matrix& A, - triangular_type tri_type, - diagonal_type diag_type, - csrtrsv_descr* descr) +void linalg::csrtrsv_analysis(const csr_matrix& A, + triangular_type tri_type, + diagonal_type diag_type, + csrtrsv_descr* descr) { ROUTINE_TRACE("linalg::csrtrsv_analysis"); @@ -180,13 +180,13 @@ void linalg::csrtrsv_analysis(const csr_matrix& A, descr); } -void linalg::csrtrsv_solve(const csr_matrix& A, - const vector& b, - vector& x, - double alpha, - triangular_type tri_type, - diagonal_type diag_type, - const csrtrsv_descr* descr) +void linalg::csrtrsv_solve(const csr_matrix& A, + const vector& b, + vector& x, + double alpha, + triangular_type tri_type, + diagonal_type diag_type, + const csrtrsv_descr* descr) { ROUTINE_TRACE("linalg::csrtrsv_solve"); @@ -221,7 +221,7 @@ void linalg::destroy_csrmv_descr(csrmv_descr* descr) } } -void linalg::csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr) +void linalg::csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_descr* descr) { ROUTINE_TRACE("linalg::csrmv_analysis"); @@ -229,13 +229,13 @@ void linalg::csrmv_analysis(const csr_matrix& A, csrmv_algorithm alg, csrmv_desc "linalg::csrmv_analysis", host_csrmv_analysis, device_csrmv_analysis, A, alg, descr); } -void linalg::csrmv_solve(double alpha, - const csr_matrix& A, - const vector& x, - double beta, - vector& y, - csrmv_algorithm alg, - const csrmv_descr* descr) +void linalg::csrmv_solve(double alpha, + const csr_matrix& A, + const vector& x, + double beta, + vector& y, + csrmv_algorithm alg, + const csrmv_descr* descr) { ROUTINE_TRACE("linalg::csrmv_solve"); @@ -272,11 +272,11 @@ void linalg::destroy_csrgeam_descr(csrgeam_descr* descr) } } -void linalg::csrgeam_nnz(const csr_matrix& A, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - csrgeam_descr* descr) +void linalg::csrgeam_nnz(const csr_matrix& A, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + csrgeam_descr* descr) { ROUTINE_TRACE("linalg::csrgeam_nnz"); @@ -284,13 +284,13 @@ void linalg::csrgeam_nnz(const csr_matrix& A, "linalg::csrgeam_nnz", host_csrgeam_nnz, device_csrgeam_nnz, A, B, C, alg, descr); } -void linalg::csrgeam_solve(double alpha, - const csr_matrix& A, - double beta, - const csr_matrix& B, - csr_matrix& C, - csrgeam_algorithm alg, - const csrgeam_descr* descr) +void linalg::csrgeam_solve(double alpha, + const csr_matrix& A, + double beta, + const csr_matrix& B, + csr_matrix& C, + csrgeam_algorithm alg, + const csrgeam_descr* descr) { ROUTINE_TRACE("linalg::csrgeam_solve"); @@ -327,26 +327,26 @@ void linalg::destroy_csrgemm_descr(csrgemm_descr* descr) } } -void linalg::csrgemm_nnz(const csr_matrix& A, - const csr_matrix& B, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - csrgemm_descr* descr) +void linalg::csrgemm_nnz(const csr_matrix& A, + const csr_matrix& B, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + csrgemm_descr* descr) { ROUTINE_TRACE("linalg::csrgemm_nnz"); return backend_dispatch( "linalg::csrgemm_nnz", host_csrgemm_nnz, device_csrgemm_nnz, A, B, D, C, alg, descr); } -void linalg::csrgemm_solve(double alpha, - const csr_matrix& A, - const csr_matrix& B, - double beta, - const csr_matrix& D, - csr_matrix& C, - csrgemm_algorithm alg, - const csrgemm_descr* descr) +void linalg::csrgemm_solve(double alpha, + const csr_matrix& A, + const csr_matrix& B, + double beta, + const csr_matrix& D, + csr_matrix& C, + csrgemm_algorithm alg, + const csrgemm_descr* descr) { ROUTINE_TRACE("linalg::csrgemm_solve"); @@ -385,7 +385,7 @@ void linalg::destroy_csric0_descr(csric0_descr* descr) } } -void linalg::csric0_analysis(const csr_matrix& A, csric0_descr* descr) +void linalg::csric0_analysis(const csr_matrix& A, csric0_descr* descr) { ROUTINE_TRACE("linalg::csric0_analysis"); @@ -393,7 +393,7 @@ void linalg::csric0_analysis(const csr_matrix& A, csric0_descr* descr) "linalg::csric0_analysis", host_csric0_analysis, device_csric0_analysis, A, descr); } -void linalg::csric0_compute(csr_matrix& A, const csric0_descr* descr) +void linalg::csric0_compute(csr_matrix& A, const csric0_descr* descr) { ROUTINE_TRACE("linalg::csric0_compute"); @@ -422,7 +422,7 @@ void linalg::destroy_csrilu0_descr(csrilu0_descr* descr) } } -void linalg::csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr) +void linalg::csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr) { ROUTINE_TRACE("linalg::csrilu0_analysis"); @@ -430,7 +430,7 @@ void linalg::csrilu0_analysis(const csr_matrix& A, csrilu0_descr* descr) "linalg::csrilu0_analysis", host_csrilu0_analysis, device_csrilu0_analysis, A, descr); } -void linalg::csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr) +void linalg::csrilu0_compute(csr_matrix& A, const csrilu0_descr* descr) { ROUTINE_TRACE("linalg::csrilu0_compute"); From ff2e01fa6064e7b6fb1266cf7ba9bac2580d0c7a Mon Sep 17 00:00:00 2001 From: jsandham Date: Thu, 6 Aug 2026 20:18:42 -0400 Subject: [PATCH 2/2] Fix compile failure --- library/include/csr_matrix.h | 2 +- library/src/csr_matrix.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/include/csr_matrix.h b/library/include/csr_matrix.h index 12c2ee0..f732c80 100644 --- a/library/include/csr_matrix.h +++ b/library/include/csr_matrix.h @@ -360,7 +360,7 @@ namespace linalg * * \param T The output `csr_matrix` that will store the transpose of this matrix. */ - void transpose(csr_matrix& T) const; + void transpose(csr_matrix& Trans) const; void apply_ruiz_scaling(vector& D1, vector& D2, int max_k, T tol); void apply_symmetric_ruiz_scaling(vector& D, int max_k, T tol); diff --git a/library/src/csr_matrix.cpp b/library/src/csr_matrix.cpp index 17535da..81a2a77 100644 --- a/library/src/csr_matrix.cpp +++ b/library/src/csr_matrix.cpp @@ -435,7 +435,7 @@ void csr_matrix::compute_incomplete_LU_factorization() } template -void csr_matrix::transpose(csr_matrix& T) const +void csr_matrix::transpose(csr_matrix& Trans) const { ROUTINE_TRACE("csr_matrix::transpose"); @@ -443,7 +443,7 @@ void csr_matrix::transpose(csr_matrix& T) const host_transpose_matrix, device_transpose_matrix, *this, - T); + Trans); } template