首页 > 解决方案 > 如何创建仅包含部分类或结构的 MPI 数据类型?

问题描述

我想创建一个新的数据类型,它只指定类或结构中的部分数据。

我已经知道如何使用MPI_Type_create_struct创建一个包含类中所有数据的新数据类型:

class A {
public:
  double value_1;
  double value_2;
  int    value_3;
  char   value_4;
};

// Create a new data type called "MPI_derived_type"
int      count {3};
int      block_lengths[3] = {2, 1, 1};
MPI_Aint displacements[3];
displacements[0] = offsetof (A, value_1);
displacements[1] = offsetof (A, value_3);
displacements[2] = offsetof (A, value_4);
MPI_Datatype types[3] = {MPI_DOUBLE, MPI_INT, MPI_CHAR};
MPI_Type_create_struct (count, block_lengths, displacements, types, &MPI_derived_type);
MPI_Type_commit (&MPI_derived_type);

使用上面的代码,我可以发送和接收class A. 但是,由于一些优化问题,我只需要在课堂上发送部分数据。例如,我只需要发送value_1and value_3

标签: c++mpi

解决方案


推荐阅读