首页 > 解决方案 > c++中的mpi all to all v

问题描述

我正在尝试生成 4 个整数并使用 alltoall 将它们全部发送到 P0 我有这个:(堆栈溢出不喜欢 linux 行结尾)

int * sendbuf=new int [4];
for(int x=0;x<4;x++){sendbuf[x]=12/4*x;}

 int* sendcounts =new int [4];
 sendcounts[0]=4;
 sendcounts[1]=0;
 sendcounts[2]=0;
 sendcounts[3]=0;

 int* displs=new int [4];
 sendcounts[0]=0*sizeof(int);
 sendcounts[1]=4*sizeof(int);
 sendcounts[2]=4*sizeof(int);
 sendcounts[3]=4*sizeof(int);
 int * recvbuf=new int [16];

for(int x=0;x<16;x++){recvbuf[x]=0;}
 int* recvcounts=new int [4];
 recvcounts[0]=4;
 recvcounts[1]=4;
 recvcounts[2]=4;
 recvcounts[3]=4;

int* rdispls=new int [4];
 rdispls[0]=0;
 rdispls[1]=4;
 rdispls[2]=8;
 rdispls[3]=12;

MPI_Alltoallv(sendbuf,sendcounts,displs,MPI_INT,recvbuf,recvcounts, rdispls,MPI_INT,MPI_COMM_WORLD);

if(id==0)
{
     for(int x=0;x<16;x++){cout<<recvbuf;}
}

我收到一条消息被截断的错误,我做错了什么?

标签: c++mpi

解决方案


推荐阅读