简体   繁体   English

使用MPI / OpenMP的具有派生数据类型(嵌套类对象)容器的C ++程序

[英]C++ program with derived data type (nested class object) container using MPI/OpenMP

I have developed a program in C++11 and I want to speed up the performance. 我已经用C ++ 11开发了一个程序,我想提高性能。

I will use a simple example to show the structure of the program (not complete). 我将使用一个简单的示例来显示程序的结构(不完整)。

   //main.cpp
   #include "a.h"
   int main()
   {
     std::vector<a> a_container;
     for (auto i=0; i< 10K; i++)
     {
       a a_obj;
       a_container.push_back(a_obj);
     }

     for(time = 1; time< long_time; time++)
     {
       //i used openmp here already
       for (auto i=0; i< 10K; i++)
       {
         a_container[i].dosomething();
       }
       for (auto i=0; i< 10K; i++)
       {
         a_container[i].update();
       }
     }
     return 1;
   }
   //a.cpp
   //a.h
   #include "b.h"
   class a
   {
     int d;
     b b_obj;
     int dosomething();
   }
   //b.cpp
   //b.h

   class b
   {
      int c;
      double d;
      int dosomething();
   }

So in order to speed up the program, I want to use both MPI and OpenMP, mainly for the loop (could be up to 1 million~1 billion instances). 因此,为了加快程序运行速度,我想同时使用MPI和OpenMP,主要用于循环(最多可能有100万个至10亿个实例)。

The class object a and b both contain complex member variables (standard and other containers, etc.) and functions. 类对象a和b都包含复杂的成员变量(标准和其他容器等)和函数。

By using OpenMP, I can take advantage of one HPC node with all cores/threads. 通过使用OpenMP,我可以利用具有所有内核/线程的一个HPC节点。 But if I want to use MPI, I need to distribute all the instances to many nodes. 但是,如果要使用MPI,则需要将所有实例分发到许多节点。

I haven't found a good solution to this yet, the closest thing I have right now is; 我还没有找到一个好的解决方案,我现在最接近的是: http://mpi-forum.org/docs/mpi-2.2/mpi22-report/node83.htm#Node83 and https://blogs.cisco.com/performance/how-to-send-cxx-stl-objects-in-mpi Please provide some suggestion. http://mpi-forum.org/docs/mpi-2.2/mpi22-report/node83.htm#Node83https://blogs.cisco.com/performance/how-to-send-cxx-stl-objects- in-mpi请提供一些建议。 Thanks. 谢谢。

Sending non-trivially-copyable objects over MPI is just the same as sending them over any other byte transport: you have to serialize. 通过MPI发送不可复制的对象与通过任何其他字节传输发送它们相同:您必须序列化。 You can use stringstream to hold the buffer on either end, if it helps. 如果有帮助,可以使用stringstream在任一端保留缓冲区。

However, it's very likely that you shouldn't do this at all. 但是,您很可能根本不应该这样做。 The data needed to create your objects ( eg , loop bounds and initial values) is probably much smaller and simpler than the form used for ongoing computation. 创建对象所需的数据( 例如 ,循环边界和初始值)可能比正在进行的计算所用的表单要小得多和简单得多。 Send that instead, and you can create your complicated objects in parallel as well as reducing communication. 而是发送它,您可以并行创建复杂的对象并减少通信。 (If the parameters are known statically, you don't have to send anything: each process can just start working on the known initialization.) (如果参数是静态已知的,则不必发送任何内容:每个进程都可以开始进行已知的初始化。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM