C MPI,使用多个节点,首先在节点级别上降低,然后减小到头节点
C++ MPI, using multiple node, first reduce at node level, then reduce to the head node
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
的过程。
还重申评论 - 我怀疑您会通过重新实现减少而获得任何好处。试图优化瓶颈不完全理解的性能问题通常是一个坏主意。
相关文章:
- 反向给定链表中的K节点
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- Boost Graph Library,修复节点大小
- C++A*算法并不总是在路径中具有目标节点
- 如何找到2个单链表的公共节点
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- boost::asio如何生成多个协同程序,然后加入它们
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- 为什么我的删除节点函数实际上没有删除节点?
- 在std::thread中,joinable()然后join()线程安全吗
- 我们可以删除链表中静态内存中的节点吗
- 如何在pugixml中获取节点的内部XML
- 为什么我们要为avl树实现返回一个指向节点的指针,而不是void函数
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- C MPI,使用多个节点,首先在节点级别上降低,然后减小到头节点
- 使用 ros launch 创建一个目录,然后将其路径传递给不同的节点
- 如何将xml文件的节点存储在字符串数组中,然后在c++中存储到结构中