我不明白如何为 MPI 创建结构数据类型

问题描述

我正在尝试创建一个看起来像这样的结构的 MPI_datatype:

struct Body{
      double X;
      double Y;
      double Z;
      double Vx;
      double Vy;
      double Vz;
      double Ax;
      double Ay;
      double Az;
      bool mine;
      int S;
    };

我在网上搜索hot来做,找到了一些例子。在 MPI_Type_struct 的手册页 ( https://www.open-mpi.org/doc/v3.0/man3/MPI_Type_struct.3.php ) 上,它说 C++ 已被弃用,我应该使用 MPI_Type_create_struct。然后是 MPI_Type_create_struct ( https://www.open-mpi.org/doc/v3.0/man3/MPI_Type_create_struct.3.php ) 的手册页。我看到有人使用 MPI_Type_create_struct ( Trouble Understanding MPI_Type_create_struct ) 创建数据类型的示例。但在这里他说你必须调整数据类型的大小,并用 foo、&lb 和 &extend 做一些我不明白的奇怪的事情。 Inc最后,有人说resize dint很有意义,应该使用MPI_Type_create_resized。

我的代码版本是

  Body MPI;
  int count=11;
  const int array_of_blocklengths[11] = {1,1,1};
  MPI_Aint array_of_displacements[11]={16,16,8};
  MPI_Datatype array_of_types[3] = {MPI_DOUBLE,MPI_C_BOOL,MPI_INT};
  MPI_Datatype tmp_type,MPI_BODY;
  MPI_Aint lb,extent;
  MPI_Type_create_struct(count,array_of_blocklengths,array_of_displacements,array_of_types,&tmp_type);
  MPI_Type_get_extent(tmp_type,&lb,&extent);
  MPI_Type_create_resized(tmp_type,lb,extent,&MPI_BODY);
  MPI_Type_commit(&MPI_BODY);

但这不起作用,当我运行它时程序会爆炸。不过编译得很好。

我希望有人能向我解释 array_of_displacements 有什么问题,MPI_Type_get_extent 和 MPI_Type_create_resized 的问题以及我应该怎么做才能创建我的数据类型。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)