c++ - 如何创建仅包含部分类或结构的 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_1
and value_3
。
- 如何创建仅包含
value_1
andvalue_3
但不包含value_2
and的新数据类型value_4
? - 我可以使用MPI_Type_create_struct只为以后的通信指定部分结构吗?
解决方案
推荐阅读
- android - 启动 APK 安装程序 Kitkat
- java - 如何解决 ClassNotFoundException:com.beust.jcommander.ParameterException
- scala - 为什么一个演员要开始两次?
- javascript - 使用 MochaJS 在 setInterval() 中测试对外部函数的回调
- java - 通过蓝牙 (Android-Studio) 向 OBD-ii 设备发送数据时应用程序崩溃
- progressive-web-apps - 取消发送的 Web 推送通知
- d3.js - 如何在 D3.js 中动态翻译 SVG 组?
- python-2.7 - 如果excel文件不存在如何创建
- python-3.x - 如何从包含前两列组合的熊猫数据框中删除行
- algorithm - Photoshop调色刀效果背后的算法是什么?