使用MPI_Win_create_dynamic时MPI_Put不起作用,为什么?

时间:2019-04-26 03:53:45

标签: mpic++

我将MPI_Put与MPI_Win_create_dynamic一起使用,但是它不起作用,只是停留在MPI_Win_fence之前,无法通过,不知道为什么?

但是当我添加MPI_Win_flush时,出现以下错误:

[susans-MacBook-Pro:05235] *** An error occurred in MPI_Win_flush
[susans-MacBook-Pro:05235] *** reported by process [3117416449,1]
[susans-MacBook-Pro:05235] *** on win pt2pt window 3
[susans-MacBook-Pro:05235] *** MPI_ERR_RMA_SYNC: error executing rma sync
[susans-MacBook-Pro:05235] *** MPI_ERRORS_ARE_FATAL (processes in this win will now abort,
[susans-MacBook-Pro:05235] ***    and potentially your MPI job)

MPI_Put调用有什么问题吗?

源代码如下:

```mpi-c++
#include <stdio.h>
#include <iostream>
#include "mpi.h"
using namespace std;

#define NROWS 10
#define NCOLS 10

int main(int argc, char *argv[])
{
    int rank, nprocs, A[NROWS][NCOLS], i, j;
    MPI_Win win;
    MPI_Datatype column, xpose;
    int errs = 0;

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

   MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &win);

   if(rank==0)
    { /* rank = 0*/
        for (i=0; i<NROWS; i++)
            for (j=0; j<NCOLS; j++)
                A[i][j] = i*NCOLS + j;
        MPI_Win_attach(win, A, NROWS*NCOLS*sizeof(int));

    }

    MPI_Win_fence(0, win);

    if (rank > 0)
    {
        for (i=0; i<NROWS; i++)
            for (j=0; j<NCOLS; j++)
                A[i][j] = -1;


        int target=0,disp=0;

        MPI_Get(A, NROWS*NCOLS, MPI_INT, target, disp, NROWS*NCOLS, MPI_INT, win)!=MPI_SUCCESS)

        MPI_Win_flush(target,win);

        MPI_Win_fence(0, win);


    }
    else if(rank==0)
    { /* rank = 0 */
        MPI_Win_fence(0, win);
        MPI_Win_detach(win,A);
   }


    MPI_Win_free(&win);
    MPI_Finalize();
    return errs;
}

```

1 个答案:

答案 0 :(得分:0)

似乎,如果我使用MPI_Get_address来获取共享内存的显示,然后对其进行bcast,那么它将很好地工作。

MPI_Get_address(buf_shared, &disp); 
MPI_Bcast(&disp, 1, MPI_AINT, 0, comm);