簡體   English   中英

通過 MPI 進程同步數組:不正確使用 MPI_Allgather?

[英]Synchronize array over MPI processes: incorrect use of MPI_Allgather?

我知道之前已經解決了類似的問題,請參閱下文為什么它們不適用於我的案例。 我有一段代碼如下所示:

int current_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &current_rank);

if (current_rank==ROOT_RANK){
   ...
  #pragma omp for
  for (long i = 0; i < num; i++) {
      auto &choumbie = catalogue->get()[i];
      /* array choumbie is modified */}
   ...}

然后我想在所有進程中同步數組“choumbie”。 我試圖按照 這個例子和文檔來實現它。 所以,在 if (current_rank==ROOT_RANK) 之后,我做了:

  int gsize;
  int *rbuf; // address of receive buffer
  auto &choumbie = catalogue->get();

  MPI_Comm_size(comm, &gsize);
  int send_count=num;
  rbuf = (int*)malloc(gsize*send_count*sizeof(double));
  MPI_Allgather(choumbie,send_count, MPI_DOUBLE, rbuf, send_count, MPI_DOUBLE, comm);

我認為我要同步的數組 'choumbie' 不會以這種方式輸入,但我也沒有找到任何其他有用的示例。 看起來第一個參數必須是要發送的數組的 memory 地址,但這似乎與我 上面提供的示例不一致。

PS:每個等級的num都是一樣的。

這個問題對我來說沒有幫助,因為我想使用 MPI_Allgather(也在 C++ 中,而不是 Fortran)。 對我來說也沒有幫助,因為我想避免使用 MPI_Barrier。

只要每個等級上的num相同,這就很接近了。 這取決於什么catalogue->get(); 給你。 我將假設它是一個 integer 數組。 你應該只需要:

MPI_Allgather(choumbie,send_count, MPI_INT, rbuf, send_count, MPI_INT, comm);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM