AMGX
AMGX copied to clipboard
Error in amgx_mpi_poisson5pt.c example
There are two errors in the 5 point 2D discretization of Poisson's equation. The A matrix is generated in the example code that comes along with AmgX library as follows:
1. for (int i = 0; i < n; i ++)
2. {
3. row_ptrs[i] = nnz;
4.
5. if (rank > 0 || i > ny)
6. {
7. col_indices[nnz] = (i + start_idx - ny);
8.
9. if (sizeof_m_val == 4)
10. {
11. ((float *)values)[nnz] = -1.f;
12. }
13. else if (sizeof_m_val == 8)
14. {
15. ((double *)values)[nnz] = -1.;
16. }
17.
18. nnz++;
19. }
20.
21. if (i % ny != 0)
22. {
23. col_indices[nnz] = (i + start_idx - 1);
24.
25. if (sizeof_m_val == 4)
26. {
27. ((float *)values)[nnz] = -1.f;
28. }
29. else if (sizeof_m_val == 8)
30. {
31. ((double *)values)[nnz] = -1.;
32. }
33.
34. nnz++;
35. }
36.
37. {
38. col_indices[nnz] = (i + start_idx);
39.
40. if (sizeof_m_val == 4)
41. {
42. ((float *)values)[nnz] = 4.f;
43. }
44. else if (sizeof_m_val == 8)
45. {
46. ((double *)values)[nnz] = 4.;
47. }
48.
49. nnz++;
50. }
51.
52. if ((i + 1) % ny == 0)
53. {
54. col_indices[nnz] = (i + start_idx + 1);
55.
56. if (sizeof_m_val == 4)
57. {
58. ((float *)values)[nnz] = -1.f;
59. }
60. else if (sizeof_m_val == 8)
61. {
62. ((double *)values)[nnz] = -1.;
63. }
64.
65. nnz++;
66. }
67.
68. if ( (rank != nranks - 1) || (i / ny != (nx - 1)) )
69. {
70. col_indices[nnz] = (i + start_idx + ny);
71.
72. if (sizeof_m_val == 4)
73. {
74. ((float *)values)[nnz] = -1.f;
75. }
76. else if (sizeof_m_val == 8)
77. {
78. ((double *)values)[nnz] = -1.;
79. }
80.
81. nnz++;
82. }
83. }
The two errors are in the following conditions: Line 5. if (rank > 0 || i > ny) Line 52. if ((i + 1) % ny == 0)
The correct statement should be: Line 5. if (rank > 0 || i >= ny) Line 52. if ((i + 1) % ny != 0)
After the above mentioned correction, the output for 4x4 matrix is attached. The solution has been verified against matlab solution.
Thanks for the report! Actually it seems this fix is also slightly incorrect with some input parameters. Will track this internally and fix: AMGX-55