且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MPI_Gather 2D数组

更新时间:2023-11-27 13:51:10

变量global_grid不会在除等级0之外的其他等级中初始化.因此,该等式

The variable global_grid is not initialized in ranks other than rank 0. Thus, this equation

&(global_grid[0][0])

或这个:

global_grid[0]

导致分段错误,因为它尝试访问global_grid的第一个元素.

leads to a segmentation fault, because it tries to access the first element of global_grid.

只需拨打两次MPI_Gather呼叫,一次呼叫0级,一次呼叫其他级别:

Just make two calls to MPI_Gather, one for rank 0 and one for the other ones:

if(id == 0) {
    MPI_Gather(gridPtr[0], 1, rowType, global_grid[0], 1, rowType, 0, MPI_COMM_WORLD);
} else {
    MPI_Gather(gridPtr[0], 1, rowType, NULL, 0, rowType, 0, MPI_COMM_WORLD);
}