将MPI DataType返回到MPI Gather
returning MPI DataType to MPI Gather
我有以下MPI_DataType代码
typedef struct resultset {
int rank, totalProcessed, bracket1, bracket2, bracket3, bracket4;
float bracket1percent, bracket2percent, bracket3percent, bracket4percent;
} resultset;
MPI_Datatype createResultType()
{
// Set-up the arguments for the type constructor
MPI_Datatype new_type;
int count = 2;
int blocklens[] = { 6, 4 };
MPI_Aint indices[2];
indices[0] = 0;
MPI_Type_extent( MPI_FLOAT, &indices[1] );
indices[1] *= 4; // There are 4 float
MPI_Datatype old_types[] = { MPI_INT, MPI_FLOAT };
// Call the data type constructor
MPI_Type_struct(count, blocklens, indices, old_types, &new_type);
MPI_Type_commit(&new_type);
return new_type;
}
我正试图使用以下代码从其他进程接收数据。rank是一个整数,用于定义进程的等级。
MPI_Datatype resType = createResultType();
if(rank != 0){
MPI_Gather(&results, sizeof(resultset), resType, NULL, 1, resType, 0, MPI_COMM_WORLD);
}
else {
resultset* all_results = new resultset[numProcs];
MPI_Gather(&results, sizeof(resultset), resType, all_results, sizeof(resultset), resType, 0, MPI_COMM_WORLD);
}
问题是,我无法使用以下方法循环遍历all_results:
for(int i = 0; i < numProcs; ++i){
std::cout << all_results[i].rank << " processed " << all_results[i].totalProcessed <<std::endl;
}
我相信问题出在我的数据类型上,但我不确定。如有任何建议,我们将不胜感激。
编辑:我遇到了循环的问题,现在我得到了不完整的数据。我在聚集函数中将sizeof(resultset)
更改为1
。现在我收到了正确的数据,除了最后两个浮动是-431602080,而不是0.002223327654。
MPI_Datatype resType = createResultType();
if(rank != 0){
MPI_Gather(&results, 1, resType, NULL, 1, resType, 0, MPI_COMM_WORLD);
}
else {
resultset* all_results = new resultset[numProcs];
MPI_Gather(&results, 1, resType, all_results, 1, resType, 0, MPI_COMM_WORLD);
}
浮动需要为"6"
int blocklens[] = { 6, 4 };
至
int blocklens[] = { 6, 6 };
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- MPI突然停止了对多个核心的操作
- 设置 Visual Studio for MPI: 找不到标识符错误
- 使用 make 编译 MPI,几个命名空间错误,例如"错误:未知类型名称'使用'?
- 如何使用 MPI 的远程内存访问 (RMA) 功能并行化数据聚合?
- 重载 MPI 中的运算符 ()
- MPI:检查是否有任何进程已终止
- 使用 pybind11 共享 MPI 通信器
- 使用 CMake,Microsoft MPI 和 Visual Studio 2017 找不到 mpi.h
- 在具有 MPI 的超立方体中广播
- 通过 mpi 发送 c++ 标准::矢量<bool>
- 使用 MPI 的 C++ 中的并行 for 循环
- 如何将 OpenMP 和 MPI 导入到大型 CLion CMake 项目中?
- 如何通过Boost.MPI发送2d Boost.MultiArray的子阵列?
- HDF5 构建了并行支持,但找不到特定于 mpi 的功能
- MPI 集合通信中的指针分配
- 仅特定内核计数上的 MPI 内存损坏
- 如何在 Mac OS 上安装 boost-mpi 及其对 clang 的依赖关系?
- 从Visual Studio 2017运行MPI应用程序,每个进程在不同的cmd窗口中
- 将MPI DataType返回到MPI Gather