MPI_Gather 2D数组 [英] MPI_Gather 2D array
问题描述
N
为4,N_glob
也是如此.它恰好具有相同的大小. p
是4.
N
is 4, so is N_glob
. It happens to be of the same size. p
is 4.
这是代码的一小部分:
float **global_grid;
float **gridPtr;
lengthSubN = N/pSqrt;
subN = lengthSubN + 2;
grid = allocate2D(grid, subN, subN);
..
MPI_Type_contiguous(lengthSubN, MPI_FLOAT, &rowType);
MPI_Type_commit(&rowType);
..
gridPtr = grid;
..
MPI_Barrier(MPI_COMM_WORLD);
if(id == 0) {
global_grid = allocate2D(global_grid, N_glob, N_glob);
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Gather(&(gridPtr[0][0]), 1, rowType,
&(global_grid[0][0]), 1, rowType, 0, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
if(id == 0)
print(global_grid, N_glob, N_glob);
我有p
个子矩阵,我试图在根过程中收集所有这些子矩阵,而全局矩阵则在其中等待它们.但是,这只会引发错误,有什么想法吗?
where I have p
submatrices and I am trying to gather them all in the root process, where the global matrix waits for them. However, it will just throw an error, any ideas?
我收到段错误:
您的一个申请程序的错误终止 PID 29058在linux16上运行 出口编号:139 您的应用程序被退出字符串终止:分段错误(信号11)
BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES PID 29058 RUNNING AT linux16 EXIT CODE: 139 YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)
我发现了这个问题 MPI_Gather分段错误,我将global_grid
初始化为NULL,但是没运气.但是,如果我这样做:
I found this question MPI_Gather segmentation fault and I initialized global_grid
to NULL, but no luck. However, if I do:
//if(id == 0) {
global_grid = allocate2D(global_grid, N_glob, N_glob);
//}
然后一切正常.但是全局矩阵不应该只存在于根过程中吗?
then everything works. But shouldn't the global matrix live only in the root process?
EDIT_2:
如果我这样做:
if(id == 0) {
global_grid = allocate2D(global_grid, N_glob, N_glob);
} else {
global_grid = NULL;
}
然后它将在此处崩溃:
MPI_Gather(&gridPtr[0][0], 1, rowType,
global_grid[0], 1, rowType, 0, MPI_COMM_WORLD);
推荐答案
变量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);
}
这篇关于MPI_Gather 2D数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!