使用MPI_Scatter导致错误EXIT CODE 139

时间:2013-11-19 09:19:56

标签: c parallel-processing mpi distributed-computing

我正在尝试使用并行计算处理某些图像。 我的代码是:

int main(int argc, char **argv){
int myid, numprocs, rows_per_process;
int N, i, j, x, y;
int    namelen,num_of_pixels;
double startwtime = 0.0 , endwtime;
char   processor_name[MPI_MAX_PROCESSOR_NAME];
PPMImage *image;

MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Get_processor_name(processor_name,&namelen);

if( myid==0){
    startwtime = MPI_Wtime();
    image = readPPM("pic.ppm");
    x = image->x;
    y = image->y;
}

MPI_Barrier(MPI_COMM_WORLD);
MPI_Bcast( &x , 1 , MPI_INT , 0 , MPI_COMM_WORLD);
MPI_Bcast( &y , 1 , MPI_INT , 0 , MPI_COMM_WORLD);

unsigned char *pic_array;
unsigned char *old_pic, *new_pic;
rows_per_process = y/numprocs;
old_pic = (unsigned char*)malloc(sizeof(unsigned char)*(x*rows_per_process*3));
new_pic = (unsigned char*)malloc(sizeof(unsigned char)*(x*rows_per_process*3));

fprintf(stdout,"total rgb pixels =  %d\n",x*y*3);

if (myid == 0){
    num_of_pixels = image->x * image->y;
    pic_array = (unsigned char*)malloc(sizeof(unsigned char)*(rows_per_process*numprocs*3*x));
    for(i=0;i<rows_per_process*numprocs*x;i++){
        pic_array[3*i] = image->data[i].red;
        pic_array[3*i+1] = image->data[i].green;
        pic_array[3*i+2] = image->data[i].blue;
    }
    fprintf(stdout,"FINISH \n");
}

MPI_Barrier(MPI_COMM_WORLD);

    fprintf(stdout,"BARRIER x = %d\n",x);

MPI_Scatter(pic_array, rows_per_process*numprocs*3*x ,MPI_UNSIGNED_CHAR, old_pic,  rows_per_process * x * 3 ,MPI_UNSIGNED_CHAR,0, MPI_COMM_WORLD);

N = .8 * x;

其中x和y是图像的分辨率参数。 问题是,由于某种原因,我将此作为输出,我无法弄清楚原因:

total rgb pixels =  5992704

total rgb pixels =  5992704

total rgb pixels =  5992704

total rgb pixels =  5992704

FINISH

BARRIER x = 1224

BARRIER x = 1224

BARRIER x = 1224

BARRIER x = 1224

===================================================================================
=   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
=   EXIT CODE: 139
=   CLEANING UP REMAINING PROCESSES
=   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES

感谢您的帮助

0 个答案:

没有答案