微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决我不明白如何为 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 举报,一经查实,本站将立刻删除。