你那么萌可以吃吗 2019-04-25 22:47 采纳率: 0%
浏览 882

MPI写的一个找寻数组最大值的问题,一直出错

#include
#include
#include
int main(int argc,char **argv)
{

int N;
int *array;
int i=0;
int max_mpi=0,min_mpi;
int maxx=0,minn=99999999;
int rank,size;

MPI_Status status;
MPI_Comm comm=MPI_COMM_WORLD;
MPI_Init(&argc,&argv);
MPI_Comm_size(comm,&size);
MPI_Comm_rank(comm,&rank);

if(rank==0)
{
    printf("please input the N :\n");
    scanf("%d",&N);
    array=(int*)malloc(sizeof(int)*N);
    for(i=0;i<N;i++)
    {
        array[i]=0;
        array[i]=rand()%100000;
    }

    for(i=1;i<size;i++)
    {
        MPI_Send(&N,1,MPI_INT,i,97,comm);
        MPI_Send(&array,N,MPI_INT,i,97,comm);
    }

    for(i=1;i<size;i++)
    {
        MPI_Recv(&maxx,1,MPI_INT,i,96,comm,&status);
        MPI_Recv(&minn,1,MPI_INT,i,96,comm,&status);
        if(max_mpi<maxx)
            max_mpi=maxx;
        if(min_mpi>minn)
            min_mpi=minn;
    }
    printf("❤❤❤❤❤❤❤❤❤❤❤❤❤\n");
    printf("The maximum value of the array is(by t he mpi): %d \n",max_mpi);
    printf("The minimum value of the array is(by the mpi): %d \n",min_mpi);
    printf("❤❤❤❤❤❤❤❤❤❤❤❤❤\n");
}
else
{
    int local_N;
    MPI_Recv(&local_N,1,MPI_INT,0,97,comm,&status);
    int *local_array;
    local_array=(int*)malloc(sizeof(int)*local_N);
    MPI_Recv(&local_array,N,MPI_INT,0,97,comm,&status);
    int beg,end;
    beg=(rank-1)*(local_N/(size-1));
    end=rank*(local_N/(size-1));
    for(i=beg;i<=end;i++)
    {
        if(maxx<local_array[i])
            maxx=local_array[i];
        if(minn>local_array[i])
            minn=local_array[i];
    }
    printf("in process [%d] maxx is (%d),minn is (%d), begin from %d end in %d\n", rank, maxx,minn, beg,end);
    MPI_Send(&maxx,1,MPI_INT,0,96,comm);
    MPI_Send(&minn,1,MPI_INT,0,96,comm);
}
MPI_Finalize();

}

错误提示如下:
Fatal error in PMPI_Recv: Message truncated, error stack:
PMPI_Recv(171)....................: MPI_Recv(buf=0x7fff11568950, count=0, MPI_INT, src=0, tag=97, MPI_COMM_WORLD, status=0x7fff11568920) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 0 and tag 97 truncated; 400 bytes received but buffer size is 0
Fatal error in PMPI_Recv: Message truncated, error stack:
PMPI_Recv(171)....................: MPI_Recv(buf=0x7fff44eee630, count=0, MPI_INT, src=0, tag=97, MPI_COMM_WORLD, status=0x7fff44eee600) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 0 and tag 97 truncated; 400 bytes received but buffer size is 0
Fatal error in PMPI_Recv: Message truncated, error stack:
PMPI_Recv(171)....................: MPI_Recv(buf=0x7ffd14d7a450, count=0, MPI_INT, src=0, tag=97, MPI_COMM_WORLD, status=0x7ffd14d7a420) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 0 and tag 97 truncated; 400 bytes received but buffer size is 0
Fatal error in PMPI_Recv: Message truncated, error stack:
PMPI_Recv(171)....................: MPI_Recv(buf=0x7ffc241a4300, count=0, MPI_INT, src=0, tag=97, MPI_COMM_WORLD, status=0x7ffc241a42d0) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 0 and tag 97 truncated; 400 bytes received but buffer size is 0
Fatal error in PMPI_Recv: Message truncated, error stack:
PMPI_Recv(171)....................: MPI_Recv(buf=0x7ffeb1d9ca00, count=0, MPI_INT, src=0, tag=97, MPI_COMM_WORLD, status=0x7ffeb1d9c9d0) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 0 and tag 97 truncated; 400 bytes received but buffer size is 0
❤❤❤❤❤❤❤100

Fatal error in PMPI_Recv: Message truncated, error stack:
PMPI_Recv(171)....................: MPI_Recv(buf=0x7ffff9b335b0, count=0, MPI_INT, src=0, tag=97, MPI_COMM_WORLD, status=0x7ffff9b33580) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 0 and tag 97 truncated; 400 bytes received but buffer size is 0
❤❤❤❤❤❤❤100

Fatal error in PMPI_Recv: Message truncated, error stack:
PMPI_Recv(171)....................: MPI_Recv(buf=0x7fff60aa3650, count=0, MPI_INT, src=0, tag=97, MPI_COMM_WORLD, status=0x7fff60aa3620) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 0 and tag 97 truncated; 400 bytes received but buffer size is 0
❤❤❤❤❤❤❤100

Fatal error in PMPI_Recv: Message truncated, error stack:
PMPI_Recv(171)....................: MPI_Recv(buf=0x7ffcd6bed240, count=0, MPI_INT, src=0, tag=97, MPI_COMM_WORLD, status=0x7ffcd6bed210) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 0 and tag 97 truncated; 400 bytes received but buffer size is 0
❤❤❤❤❤❤❤100

Fatal error in PMPI_Recv: Message truncated, error stack:
PMPI_Recv(171)....................: MPI_Recv(buf=0x7ffff3192220, count=0, MPI_INT, src=0, tag=97, MPI_COMM_WORLD, status=0x7ffff31921f0) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 0 and tag 97 truncated; 400 bytes received but buffer size is 0

please input the N :
100

= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= PID 24244 RUNNING AT localhost.localdomain
= EXIT CODE: 11
= CLEANING UP REMAINING PROCESSES

= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES

YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)
This typically refers to a problem with your application.
Please see the FAQ page for debugging suggestions

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-09 16:30
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)