0

私は MPI のプログラミングが初めてで、より大きな行列を動的に割り当てることが困難です。現れた問題は次のとおりです。

行コマンド:

$ 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).
--------------------------------------------------------------------------
$

コード:

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>

#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(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&taskid);
(MPI_COMM_WORLD,&numtasks);

numworkers = numtasks-1;

if (taskid == 0){

a = (float **) malloc (max * sizeof(float *));
for ( i = 0; i < max; i++ )
    a[i] = (float*) malloc (max * sizeof(float));

aux_a = (float **) malloc (max * sizeof(float *));
for ( i = 0; i < max; i++ )
    aux_a[i] = (float*) malloc (max * sizeof(float));

for (i=0; i<max; i++)
    for (j=0; j<max; j++)
        a[i][j]= i+1;

for (dest=1; dest<=numworkers; dest++){

    MPI_Send(&a, max*max, MPI_FLOAT, dest, 1, MPI_COMM_WORLD);

}

for (i=1; i<=numworkers; i++){

    source = i;
    MPI_Recv(&aux_a, max*max, MPI_FLOAT, source, 1, MPI_COMM_WORLD, &status);

}

printf("******************************************************\n");
printf("Result Matrix:\n");
for (i=0; i<max; i++){
    printf("\n"); 
    for (j=0; j<max; j++) 
       printf("%6.2f   ", aux_a[i][j]);
}
printf("\n******************************************************\n");
printf ("Done.\n");
}

if (taskid > 0)
{
a = (float **) malloc (max * sizeof(float *));
for ( i = 0; i < max; i++ )
    a[i] = (float*) malloc (max * sizeof(float));

aux_a = (float **) malloc (max * sizeof(float *));
for ( i = 0; i < max; i++ )
    aux_a[i] = (float*) malloc (max * sizeof(float));

MPI_Recv(&a, max*max, MPI_FLOAT, 0, 1, MPI_COMM_WORLD, &status);

for (i=0; i<max; i++)
   for (j=0; j<max; j++)
aux_a[i][j] = a[i][j];

MPI_Send(&aux_a, max*max, MPI_FLOAT, 0, 1, MPI_COMM_WORLD);
}

MPI_Finalize();
}

手伝って頂けますか?

4

0 に答える 0