MPI_Barrier 和 MPI_Gather 使用小数据集还是大数据集?
MPI_Barrier with MPI_Gather using small vs. large data set sizes?
我一直在使用 MPI_Scatter / MPI_Gather 进行各种并行计算。我注意到的一件事是 MPI_Barrier() 通常被调用来同步处理器,类似于 OpenMP 屏障指令。我正在为一个项目调整我的代码并在下面注释掉我的 MPI_Barrier() 行,发现计算仍然正确。为什么会这样?我可以理解为什么需要第一个 MPI_Barrier() - 其他处理器不需要等待;一旦他们从处理器 MASTER 获得数据,他们就可以开始计算。但是在 MPI_Gather 之后是否需要 MPI_Barrier,或者 MPI_Gather 中是否已经有一个隐含的障碍?
编辑:在这种情况下,正在处理的数据大小重要吗?
MPI_Scatter(&sendingbuffer,sendingcount,MPI_FLOAT,receivingbuffer,sendcount,
MPI_INT,MASTER_ID,MPI_COMM_WORLD);
// PERFORM SOME COMPUTATIONS
MPI_Barrier(); //<--- I understand why this is needed
MPI_Gather(localdata,sendcount, MPI_INT, global,sendcount, MPI_INT, MASTER_ID, MPI_COMM_WORLD);
//MPI_Barrier(); <------ is this ever needed?
MPI_Gather()
内部没有隐式屏障。
问:采集后需要结界吗?
没有
如您所见When do I need to use MPI_Barrier()?:
All collective operations in MPI before MPI-3.0 are blocking, which
means that it is safe to use all buffers passed to them after they
return. In particular, this means that all data was received when one
of these functions returns. (However, it does not imply that all data
was sent!) So MPI_Barrier is not necessary (or very helpful)
before/after collective operations, if all buffers are valid already.
需要None个关卡!
MPI_Gather
是阻塞操作,即调用完成后输出可用。这并不意味着障碍,因为允许但不保证在根/其他等级开始其操作之前完成非根等级。但是,在 MASTER_ID
等级上访问 global
并在本地调用完成后在任何等级上重用 localdata
是完全安全的。
与基于消息的 MPI 同步与共享内存 OpenMP 不同。对于阻塞通信,通常不需要显式同步 - 结果保证在调用完成后可用。
非阻塞通信需要各种同步,但这是通过 MPI_Test
/MPI_Wait
对特定消息完成的 - 如果您尝试替换,障碍甚至可能会提供错误的正确感MPI_Wait
和 MPI_Barrier
。单方面的沟通,事情变得更加复杂,障碍可以发挥作用。
实际上,您很少需要屏障,而是避免它们不引入任何不必要的同步。
编辑:鉴于其他答案相互矛盾,这里是标准(MPI 3.1,第 5.1 节)引用(强调我的)。
Collective operations can (but are not required to) complete as soon
as the caller’s participation in the collective communication is
finished. A blocking operation is complete as soon as the call
returns. A nonblocking (immediate) call requires a separate completion
call (cf. Section 3.7). The completion of a collective operation
indicates that the caller is free to modify locations in the
communication buffer. It does not indicate that other processes in the
group have completed or even started the operation (unless otherwise
implied by the description of the operation). Thus, a collective
communication operation may, or may not, have the effect of
synchronizing all calling processes. This statement excludes, of
course, the barrier operation.
解决最近的编辑问题:不,在这种情况下,数据大小对正确性没有影响。 MPI 中的数据大小有时会影响不正确的 MPI 程序是否会死锁。
我一直在使用 MPI_Scatter / MPI_Gather 进行各种并行计算。我注意到的一件事是 MPI_Barrier() 通常被调用来同步处理器,类似于 OpenMP 屏障指令。我正在为一个项目调整我的代码并在下面注释掉我的 MPI_Barrier() 行,发现计算仍然正确。为什么会这样?我可以理解为什么需要第一个 MPI_Barrier() - 其他处理器不需要等待;一旦他们从处理器 MASTER 获得数据,他们就可以开始计算。但是在 MPI_Gather 之后是否需要 MPI_Barrier,或者 MPI_Gather 中是否已经有一个隐含的障碍?
编辑:在这种情况下,正在处理的数据大小重要吗?
MPI_Scatter(&sendingbuffer,sendingcount,MPI_FLOAT,receivingbuffer,sendcount,
MPI_INT,MASTER_ID,MPI_COMM_WORLD);
// PERFORM SOME COMPUTATIONS
MPI_Barrier(); //<--- I understand why this is needed
MPI_Gather(localdata,sendcount, MPI_INT, global,sendcount, MPI_INT, MASTER_ID, MPI_COMM_WORLD);
//MPI_Barrier(); <------ is this ever needed?
MPI_Gather()
内部没有隐式屏障。
问:采集后需要结界吗?
没有
如您所见When do I need to use MPI_Barrier()?:
All collective operations in MPI before MPI-3.0 are blocking, which means that it is safe to use all buffers passed to them after they return. In particular, this means that all data was received when one of these functions returns. (However, it does not imply that all data was sent!) So MPI_Barrier is not necessary (or very helpful) before/after collective operations, if all buffers are valid already.
None个关卡!
MPI_Gather
是阻塞操作,即调用完成后输出可用。这并不意味着障碍,因为允许但不保证在根/其他等级开始其操作之前完成非根等级。但是,在 MASTER_ID
等级上访问 global
并在本地调用完成后在任何等级上重用 localdata
是完全安全的。
与基于消息的 MPI 同步与共享内存 OpenMP 不同。对于阻塞通信,通常不需要显式同步 - 结果保证在调用完成后可用。
非阻塞通信需要各种同步,但这是通过 MPI_Test
/MPI_Wait
对特定消息完成的 - 如果您尝试替换,障碍甚至可能会提供错误的正确感MPI_Wait
和 MPI_Barrier
。单方面的沟通,事情变得更加复杂,障碍可以发挥作用。
实际上,您很少需要屏障,而是避免它们不引入任何不必要的同步。
编辑:鉴于其他答案相互矛盾,这里是标准(MPI 3.1,第 5.1 节)引用(强调我的)。
Collective operations can (but are not required to) complete as soon as the caller’s participation in the collective communication is finished. A blocking operation is complete as soon as the call returns. A nonblocking (immediate) call requires a separate completion call (cf. Section 3.7). The completion of a collective operation indicates that the caller is free to modify locations in the communication buffer. It does not indicate that other processes in the group have completed or even started the operation (unless otherwise implied by the description of the operation). Thus, a collective communication operation may, or may not, have the effect of synchronizing all calling processes. This statement excludes, of course, the barrier operation.
解决最近的编辑问题:不,在这种情况下,数据大小对正确性没有影响。 MPI 中的数据大小有时会影响不正确的 MPI 程序是否会死锁。