就一个问题。如果我使用函数 MPI_Reduce,当这是一个动态数组时,只有根可以分配接收缓冲区?例如:
int r = 10;
int *yloc, *y;
...
yloc = calloc(r*sizeof(int)); // for all processes
if (I'm the master process) {
y = calloc(r*sizeof(int)) // inside the if-block ...
...
}
y = calloc(r*sizeof(int)) // ...or outside the if-block?
...
MPI_Reduce(yloc, y, r, MPI_FLOAT, MPI_SUM, ROOT, MPI_COMM_WORLD);
什么是正确的? if 块内部还是外部?提前致谢。
两者都是正确的。但我想你想要的答案是无论是否y
是有效的内存地址仅对根进程重要MPI_Reduce()
称呼。因此,除了根进程之外,无需为任何其他进程分配内存。
为了完整起见,这里摘录MPI_Reduce
的手册页,我们可以在其中看到接收缓冲区仅对根进程有意义:
NAME
MPI_Reduce - Reduces values on all processes to a single value
SYNOPSIS
int MPI_Reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
MPI_Op op, int root, MPI_Comm comm)
INPUT PARAMETERS
sendbuf
- address of send buffer (choice)
count - number of elements in send buffer (integer)
datatype
- data type of elements of send buffer (handle)
op - reduce operation (handle)
root - rank of root process (integer)
comm - communicator (handle)
OUTPUT PARAMETERS
recvbuf
- address of receive buffer (choice, significant only at root )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)