Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions clients/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<double>& b,
const linalg::vector<double>& x,
const linalg::vector<double>& initial_x,
double tol,
int norm_type)
bool check_solution(const linalg::csr_matrix<double>& A,
const linalg::vector<double>& b,
const linalg::vector<double>& x,
const linalg::vector<double>& initial_x,
double tol,
int norm_type)
{
for(size_t i = 0; i < x.get_size(); i++)
{
Expand Down Expand Up @@ -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<double>& A, const linalg::csr_matrix<double>& B)
{
const int* csr_row_ptr_A = A.get_row_ptr();
const int* csr_col_ind_A = A.get_col_ind();
Expand Down
17 changes: 9 additions & 8 deletions clients/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<int> &csr_row_ptr, std::vector<int> &csr_col_ind,
// std::vector<double> &csr_val, int &m, int &n, int &nnz);

bool check_solution(const linalg::csr_matrix& A,
const linalg::vector<double>& b,
const linalg::vector<double>& x,
const linalg::vector<double>& initial_x,
double tol,
int norm_type);
bool check_solution(const linalg::csr_matrix<double>& A,
const linalg::vector<double>& b,
const linalg::vector<double>& x,
const linalg::vector<double>& 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<double>& A,
const linalg::csr_matrix<double>& B);

bool check_vector_equality(const linalg::vector<double>& x, const linalg::vector<double>& y);

Expand Down
10 changes: 5 additions & 5 deletions clients/examples/gauss_seidel_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,7 +43,7 @@ int main()
// std::vector<int> csr_col_ind = { 0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4 };
// std::vector<double> 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<double> A;
A.read_mtx("../matrices/SPD/shallow_water2/shallow_water2.mtx");

// Solution vector
Expand All @@ -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);

Expand All @@ -75,4 +75,4 @@ int main()
// std::cout << "" << std::endl;

return 0;
}
}
19 changes: 10 additions & 9 deletions clients/examples/gmres_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,20 +31,21 @@

int main()
{
int m = 5;
int n = 5;
int m = 5;
int n = 5;
int nnz = 15;

// 4 3 0 0 2
// 1 2 3 0 0
// 0 5 4 3 0
// 0 0 1 3 2
// 9 0 0 6 7
std::vector<int> csr_row_ptr = {0, 3, 6, 9, 12, 15};
std::vector<int> csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4};
std::vector<double> 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<int> csr_row_ptr = {0, 3, 6, 9, 12, 15};
std::vector<int> csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4};
std::vector<double> 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<double> A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz);

// Solution vector
linalg::vector<double> x(A.get_m());
Expand All @@ -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;
}
}
6 changes: 3 additions & 3 deletions clients/examples/jacobi_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,11 +59,11 @@ int main()
std::vector<double> 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<double> A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz);

A.print_matrix("A");

linalg::csr_matrix A_copy;
linalg::csr_matrix<double> A_copy;
A_copy.copy_from(A);

linalg::csric0_descr* descr_IC = nullptr;
Expand Down
10 changes: 5 additions & 5 deletions clients/examples/pcg_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -32,16 +32,16 @@

int main()
{
linalg::csr_matrix A;
linalg::csr_matrix<double> A;
A.read_mtx("../matrices/SPD/shallow_water2/shallow_water2.mtx");

// Solution vector
linalg::vector<double> x(A.get_m());

x.move_to_device();
x.zeros();
x.move_to_host();

x.zeros();

// Righthand side vector
Expand Down Expand Up @@ -71,4 +71,4 @@ int main()
// std::cout << "" << std::endl;

return 0;
}
}
23 changes: 12 additions & 11 deletions clients/examples/richardson_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,20 +31,21 @@

int main()
{
int m = 5;
int n = 5;
int m = 5;
int n = 5;
int nnz = 15;

// 4 -1 0 0 -1
// -1 4 -1 0 0
// 0 -1 4 -1 0
// 0 0 -1 4 -1
// -1 0 0 -1 4
std::vector<int> csr_row_ptr = {0, 3, 6, 9, 12, 15};
std::vector<int> csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4};
std::vector<double> 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<int> csr_row_ptr = {0, 3, 6, 9, 12, 15};
std::vector<int> csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4};
std::vector<double> 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<double> A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz);

// Solution vector
linalg::vector<double> x(A.get_m());
Expand All @@ -59,20 +60,20 @@ 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);

std::cout << "iter: " << iter << std::endl;

// 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;
}
}
4 changes: 2 additions & 2 deletions clients/examples/rsamg_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -32,7 +32,7 @@

int main()
{
linalg::csr_matrix A;
linalg::csr_matrix<double> A;
A.read_mtx("../matrices/SPD/shallow_water2/shallow_water2.mtx");

// Solution vector
Expand Down
4 changes: 2 additions & 2 deletions clients/examples/saamg_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -32,7 +32,7 @@

int main()
{
linalg::csr_matrix A;
linalg::csr_matrix<double> A;
A.read_mtx("../matrices/SPD/shallow_water2/shallow_water2.mtx");

// Solution vector
Expand Down
23 changes: 12 additions & 11 deletions clients/examples/sor_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,20 +31,21 @@

int main()
{
int m = 5;
int n = 5;
int m = 5;
int n = 5;
int nnz = 15;

// 4 -1 0 0 -1
// -1 4 -1 0 0
// 0 -1 4 -1 0
// 0 0 -1 4 -1
// -1 0 0 -1 4
std::vector<int> csr_row_ptr = {0, 3, 6, 9, 12, 15};
std::vector<int> csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4};
std::vector<double> 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<int> csr_row_ptr = {0, 3, 6, 9, 12, 15};
std::vector<int> csr_col_ind = {0, 1, 4, 0, 1, 2, 1, 2, 3, 2, 3, 4, 0, 3, 4};
std::vector<double> 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<double> A(csr_row_ptr, csr_col_ind, csr_val, m, n, nnz);

// Solution vector
linalg::vector<double> x(A.get_m());
Expand All @@ -59,20 +60,20 @@ 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);

std::cout << "iter: " << iter << std::endl;

// 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;
}
}
Loading
Loading