Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem might lie <code>printMatrix()</code> and <code>fillMatrix()</code>. <code>clang</code> refused to compile your definition of <code>fillMatrix()</code>:</p> <pre><code>so_mpi.c:22:31: error: use of undeclared identifier 'len' void fillMatrix(int (*matrix)[len], int len){ ^ </code></pre> <p>Dropping <code>len</code> from the prototype just creates another problem:</p> <pre><code>so_mpi.c:26:19: error: subscript of pointer to incomplete type 'int []' matrix[i][j]=j; ~~~~~~^ </code></pre> <p>What did work was this:</p> <pre><code>void fillMatrix(int *matrix, int len) { int i, j; for (i = 0; i &lt; len; ++i) { int *row = &amp;matrix[i * len]; for(j = 0; j &lt; len; ++j) { row[j] = j; } } } fillMatrix((int *)a, MAX); fillMatrix((int *)b, MAX); </code></pre> <p>With that change, everything seems to work fine. I used <code>MAX = 5</code> and 5 nodes. I prefixed logging statements with the node's rank and added a few more logging statements. Here was the result:</p> <pre><code>$ mpirun -np 5 ./so_mpi node 1 of 5 node 4 of 5 node 0 of 5 0: filling matrices 0: matrix B: 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0: matrix A: 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0: broadcast of B complete 0: sending 1 rows (5 elements) of A to node 1 0: sending 1 rows (5 elements) of A to node 2 0: sending 1 rows (5 elements) of A to node 3 0: sending 1 rows (5 elements) of A to node 4 0: matrix A: 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 1: broadcast of B complete 1: received portion of matrix 1: matrix A: 0 0 0 0 0 0 1 2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 node 2 of 5 2: broadcast of B complete 2: received portion of matrix 2: matrix A: 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 0 0 0 0 0 0 0 0 0 0 node 3 of 5 3: broadcast of B complete 3: received portion of matrix 3: matrix A: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 0 0 0 0 0 4: broadcast of B complete 4: received portion of matrix 4: matrix A: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload