Note that there are some explanatory texts on larger screens.

plurals
  1. POHow allocate larger matrix?
    primarykey
    data
    text
    <p>I'm new in programming MPI and my difficulty is allocate dynamically a larger matrix. The problem that appeared was:</p> <p>Line command:</p> <pre><code>$ mpicc teste5.c -o teste5 $ mpirun -np 2 teste5 [frontend:13283] *** Process received signal *** -------------------------------------------------------------------------- mpirun noticed that process rank 1 with PID 13283 on node frontend exited on signal 11 (Segmentation fault). -------------------------------------------------------------------------- $ </code></pre> <p>Code:</p> <pre><code>#include "mpi.h" #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #define max 5000 int main (int argc, char *argv[]){ int numtasks, /* number of tasks in partition */ taskid, /* a task identifier */ numworkers, /* number of worker tasks */ source, /* task id of message source */ dest, /* task id of message destination */ i, j, k; /* misc */ // float a[max][max],aux_a[max][max]; /* See comments */ float **a, **aux_a; MPI_Status status; MPI_Init(&amp;argc,&amp;argv); MPI_Comm_rank(MPI_COMM_WORLD,&amp;taskid); (MPI_COMM_WORLD,&amp;numtasks); numworkers = numtasks-1; if (taskid == 0){ a = (float **) malloc (max * sizeof(float *)); for ( i = 0; i &lt; max; i++ ) a[i] = (float*) malloc (max * sizeof(float)); aux_a = (float **) malloc (max * sizeof(float *)); for ( i = 0; i &lt; max; i++ ) aux_a[i] = (float*) malloc (max * sizeof(float)); for (i=0; i&lt;max; i++) for (j=0; j&lt;max; j++) a[i][j]= i+1; for (dest=1; dest&lt;=numworkers; dest++){ MPI_Send(&amp;a, max*max, MPI_FLOAT, dest, 1, MPI_COMM_WORLD); } for (i=1; i&lt;=numworkers; i++){ source = i; MPI_Recv(&amp;aux_a, max*max, MPI_FLOAT, source, 1, MPI_COMM_WORLD, &amp;status); } printf("******************************************************\n"); printf("Result Matrix:\n"); for (i=0; i&lt;max; i++){ printf("\n"); for (j=0; j&lt;max; j++) printf("%6.2f ", aux_a[i][j]); } printf("\n******************************************************\n"); printf ("Done.\n"); } if (taskid &gt; 0) { a = (float **) malloc (max * sizeof(float *)); for ( i = 0; i &lt; max; i++ ) a[i] = (float*) malloc (max * sizeof(float)); aux_a = (float **) malloc (max * sizeof(float *)); for ( i = 0; i &lt; max; i++ ) aux_a[i] = (float*) malloc (max * sizeof(float)); MPI_Recv(&amp;a, max*max, MPI_FLOAT, 0, 1, MPI_COMM_WORLD, &amp;status); for (i=0; i&lt;max; i++) for (j=0; j&lt;max; j++) aux_a[i][j] = a[i][j]; MPI_Send(&amp;aux_a, max*max, MPI_FLOAT, 0, 1, MPI_COMM_WORLD); } MPI_Finalize(); } </code></pre> <p>Can you help me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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