NVIDIA / NVIDIA/AMGX

Error in amgx_mpi_poisson5pt.c example

Open
#40 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug tracking internally
Dominant language
Cuda
Stars
692
Forks
197
PR merge metrics
No merged PRs in 30d

Description

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.

output.log

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the amgx_mpi_poisson5pt.c example and inspect the matrix-generation conditions at lines 5 and 52. Correct the two conditions described in the issue, then run the example for the 4x4 matrix and compare its output with output.log and the reported MATLAB solution.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
distributed-systems, hpc
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.