C MPI,使用多个节点,首先在节点级别上降低,然后减小到头节点

C++ MPI, using multiple node, first reduce at node level, then reduce to the head node

本文关键字:节点 然后 MPI      更新时间:2023-10-16

i使用12个节点Windows HPC群集(每个核心(运行C MPI程序(使用Boost MPI(。一个用MPI减少的运行,一条评论降低了MPI(仅用于速度测试(。运行时间是01:17:23和01:03:49。在我看来,MPI减少需要大部分时间。我认为可能值得首先在节点级别上降低,然后减少到头节点以提高性能。

以下是一个简单的测试目的示例。假设有4个计算机节点,每个节点有2个核心。我想首先使用MPI来减少每个节点。之后,减少到头节点。我对MPI不太熟悉,以下程序崩溃。

#include <iostream>
#include <boost/mpi.hpp>
namespace mpi = boost::mpi;
using namespace std;
int main()
{
  mpi::environment env;
  mpi::communicator world;
  int i = world.rank();

  boost::mpi::communicator local = world.split(world.rank()/2); // total 8 cores, divide in 4 groups
  boost::mpi::communicator heads = world.split(world.rank()%4);
  int res = 0;
  boost::mpi::reduce(local, i, res, std::plus<int>(), 0);
  if(world.rank()%2==0)
  cout<<res<<endl;
  boost::mpi::reduce(heads, res, res, std::plus<int>(), 0);
  if(world.rank()==0)
      cout<<res<<endl;
  return 0;
}

输出是难以辨认的,类似于此

Z
h
h
h
h
a
a
a
a
n
n
n
n
g
g
g
g




b
b
b
b
o
o
o
o
o
o
o
o
s
...
...
...

错误消息是

Test.exe ended prematurely and may have crashed. exit code 3

我怀疑我对小组分裂/或减少的事情做错了什么,但无法通过几次试验弄清楚。我如何更改以进行这项工作?谢谢。

现金的原因是因为您在以下行中两次将相同的变量传递给MPI

boost::mpi::reduce(heads, res, res, std::plus<int>(), 0);

这在boost.mpi中并没有得到很好的记录,但是boost通过参考将其带到了各自的指针到MPI。MPI通常禁止您将同一缓冲区传递两次到同一呼叫。确切地

您可以通过创建res的副本来轻松解决此问题。

我还认为您可能想限制使用local.rank() == 0的过程。

还重申评论 - 我怀疑您会通过重新实现减少而获得任何好处。试图优化瓶颈不完全理解的性能问题通常是一个坏主意。