Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

c++ - One-sided communications / RMA - Error in MPI_Rput

I'm trying to write and read elements in MPI windows located on different processes. Basically this amounts to a large array split among several processes. Unfortunately, I keep obtaining the error An error occurred in MPI_Rput, MPI_ERR_RMA_SYNC: error executing rma sync.

I have tried using, instead of fences, functions such as MPI_Win_(un)lock(_all) and MPI_Win_flush_all but it does not solve the problem.

Thanks!

#include <mpi.h>
#include <iostream>


int main(){

  // MPI initialisation
  MPI_Init(0, nullptr);
  int rank, size;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &size);


  // Window intialisation
  int n=10;
  double* data;
  MPI_Win window;
  MPI_Alloc_mem(n*sizeof(double), MPI_INFO_NULL, &data);
  MPI_Win_create(data, n*sizeof(double), sizeof(double), MPI_INFO_NULL, MPI_COMM_WORLD, &window);


  MPI_Win_fence(0, window);


  // Writing to windows in other processes from the master process
  int i, j, k;
  double x=0;
  MPI_Request request;
  MPI_Status status;
  if(rank==0){
    for(i=0; i<size; ++i){
      for(j=0; j<n; ++j){
        MPI_Rput(&x, 1, MPI_DOUBLE, i, j, 1, MPI_DOUBLE, window, &request);
        MPI_Wait(&request, &status);
        ++x;
      }
    }
  }

  
  MPI_Win_fence(0, window);


  // Read the array on all processes from all processes
  k=0;
  double epsilon=1e-8;
  for(i=0; i<size; ++i){
    for(j=0; j<n; ++j){
      MPI_Rget(&x, 1, MPI_DOUBLE, i, j, 1, MPI_DOUBLE, window, &request);
      MPI_Wait(&request, &status);
      if(abs(x-k)>epsilon){
    std::cout << "error
";
      }
      ++k;
    }
  }
 

  MPI_Win_fence(0, window);


  // Cleaning up
  MPI_Win_free(&window);
  MPI_Free_mem(data);
  MPI_Finalize();

  return 0;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...