title: Segmentation fault and MPI
body: <p>In my program I need to do some matrix multiplication using MPI.
  When I run my program, I get the following error:</p>
  
  <pre><code>=====================================================================================
  =   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
  =   EXIT CODE: 139
  =   CLEANING UP REMAINING PROCESSES
  =   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
  =====================================================================================
  APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)
  </code></pre>
  
  <p>It executes:</p>
  
  <pre><code> printf("Sent a\n");  
  </code></pre>
  
  <p>The error is in:</p>
  
  <pre><code> MPI_Send(&amp;b, nColA*nColB, MPI_FLOAT, dest, mtype, MPI_COMM_WORLD);
  </code></pre>
  
  <p>It doesn't execute:</p>
  
  <pre><code> printf("Sent b\n");
  </code></pre>
  
  <p>I don't now why.</p>
  
  <p>Can you help me?</p>
  
  <pre><code>void multiplicaMatriz (int taskid, int numtasks, float **a, float **b, float **c, long int nLinA, long int nColA, long int nLinB, long int nColB)
  {
      long int    i, j, k, rc;           /* misc */
  
      int numworkers,        /* number of worker tasks */
      source,                /* task id of message source */
      dest,                  /* task id of message destination */
      mtype,                 /* message type */
      rows,                  /* rows of matrix A sent to each worker */
      averow, extra, offset; /* used to determine rows sent to each worker */
  
      MPI_Status status;
  
      numworkers = numtasks-1;
  
  
     /**************************** master task ************************************/
     if (taskid == MASTER)
     {
        printf("mpi_mm has started with %d tasks.\n",numtasks);
  
        /* Send matrix data to the worker tasks */
        averow = nLinA/numworkers;
        extra = nLinA%numworkers;
        offset = 0;
        mtype = FROM_MASTER;
        for (dest=1; dest&lt;=numworkers; dest++)
        {
           rows = (dest &lt;= extra) ? averow+1 : averow;    
           printf("Sending %d rows to task %d offset=%d\n",rows,dest,offset);
           MPI_Send(&amp;offset, 1, MPI_INT, dest, mtype, MPI_COMM_WORLD);
           printf("Sent offset %d\n", offset);
           MPI_Send(&amp;rows, 1, MPI_INT, dest, mtype, MPI_COMM_WORLD);
           printf("Sent rows %d\n", rows);
           MPI_Send(&amp;a[offset][0], rows*nColA, MPI_FLOAT, dest, mtype,
                     MPI_COMM_WORLD);
           printf("Sent a\n");          
           MPI_Send(&amp;b, nColA*nColB, MPI_FLOAT, dest, mtype, MPI_COMM_WORLD);
           printf("Sent b\n");
           offset = offset + rows;
        }
  
        /* Receive results from worker tasks */
        mtype = FROM_WORKER;
        for (i=1; i&lt;=numworkers; i++)
        {
           source = i;
           MPI_Recv(&amp;offset, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &amp;status);
           MPI_Recv(&amp;rows, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &amp;status);
           MPI_Recv(&amp;c[offset][0], rows*nColB, MPI_FLOAT, source, mtype, 
                    MPI_COMM_WORLD, &amp;status);
           printf("Received results from task %d\n",source);
        }
  
        /* Print results */
        printf("******************************************************\n");
        printf("Result Matrix:\n");
        for (i=0; i&lt;nLinA; i++)
        {
           printf("\n"); 
           for (j=0; j&lt;nColB; j++) 
              printf("%6.2f   ", c[i][j]);
        }
        printf("\n******************************************************\n");
        printf ("Done.\n");
     }
  
  
     /**************************** worker task ************************************/
     if (taskid &gt; MASTER)
     {
        mtype = FROM_MASTER;
        MPI_Recv(&amp;offset, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD, &amp;status);
        MPI_Recv(&amp;rows, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD, &amp;status);
        MPI_Recv(&amp;a, rows*nColA, MPI_FLOAT, MASTER, mtype, MPI_COMM_WORLD, &amp;status);
        MPI_Recv(&amp;b, nColA*nColB, MPI_FLOAT, MASTER, mtype, MPI_COMM_WORLD, &amp;status);
  
        for (k=0; k&lt;nColB; k++)
           for (i=0; i&lt;rows; i++)
           {
              c[i][k] = 0.0;
              for (j=0; j&lt;nColA; j++)
                 c[i][k] = c[i][k] + a[i][j] * b[j][k];
           }
        mtype = FROM_WORKER;
        MPI_Send(&amp;offset, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD);
        MPI_Send(&amp;rows, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD);
        MPI_Send(&amp;c, rows*nColB, MPI_FLOAT, MASTER, mtype, MPI_COMM_WORLD);
     }
   }
  </code></pre>