C语言中的MPI前缀和

C语言中的MPI前缀和,c,mpi,C,Mpi,我很难使用MPI实现前缀和。我想我遗漏了几行,但我不知道遗漏了哪些,以及应该放在哪里。以下是我所拥有的: int main(int argc, char** argv){ int i, size, nprocs, rank; int array[atoi(argv[1])]; int Destination, Destination_tag; int Source, Source_tag, RecvData; int len = sizeof(array)/sizeof(int);

我很难使用MPI实现前缀和。我想我遗漏了几行,但我不知道遗漏了哪些,以及应该放在哪里。以下是我所拥有的:

int main(int argc, char** argv){  
 int i, size, nprocs, rank;
 int array[atoi(argv[1])];

int Destination, Destination_tag;
int Source, Source_tag, RecvData;

int len = sizeof(array)/sizeof(int);

for(i = 0; i < size; i++) 
     {
    array[i] = i+rank*size;
}

MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

int id = rank;

      //I believe the error is here
for(i = 0; i < size, i++)
{
    message = (rank - pow(2,x));

    Destination = message ;
    Destination_tag = array.id; 
    MPI_Send(&message, 1, MPI_INT, Destination, Destination_tag, MPI_COMM_WORLD); 

    Source = message ;
    Source_tag = message; 
    MPI_Recv(&RecvData, 1, MPI_INT, Source, Source_tag, MPI_COMM_WORLD, &Status); 
   //End of problem area
    printf("My rank is  %d n =%d \n",i,size); 

    MPI_Finalize();
    return 0;
intmain(intargc,char**argv){
国际一级、规模、非建议制定规则的组织、等级;
int数组[atoi(argv[1])];
int Destination,Destination_标签;
int Source、Source_标记、RecvData;
int len=sizeof(数组)/sizeof(int);
对于(i=0;i

}

您的MPI发送和接收呼叫可能是错误的。一般来说,我被教导您应该始终通过

 if (rank == 0)
    {
      MPI_Send(...
    }

if (rank == 1)
    {
     MPI_Recieve(...

与使用
MPI\u Send
MPI\u Recv
手动计算前缀和不同,使用
MPI\u Scan
MPI\u Scan
可以对进程{0}中的元素进行部分包含性缩减,以处理{your rank},从而可以非常轻松(有效地)执行前缀和

例如,假设单个整数分布在如下进程中:
进程0=2
过程1=3
过程2=4
过程3=5

调用
MPI\u Scan
后,使用
MPI\u SUM
作为还原操作,结果如下:
进程0=2
过程1=5
过程2=9
过程3=14

调用
MPI\u Exscan
进行独占扫描,这意味着还原将不包括调用进程在还原中保留的数据。结果如下所示:
进程0=未定义(将recv_缓冲区设置为0,否则将有垃圾)
过程1=2
过程2=5

过程3=9

你能告诉我你想做什么吗?我不明白。