MPI中的C++双重类型
C++ double type in MPI
MPI中发生了一些奇怪的事情,我不太明白。我有以下简单的代码:
MPI_Init(&argc, &argv);
int rank;
int size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (rank == 0) {
double ridiculous = 7.9;
printf("Process 0 will be sending number %dn", ridiculous);
MPI_Send(&ridiculous, 1, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD);
printf("Process 0 sent number %dn", ridiculous);
}
else {
double received = 0.;
MPI_Recv(&received, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
printf("Process 1 received number %d from process 0n", received);
}
MPI_Finalize();
我期待着输出中出现这样的东西:
Process 0 will be sending number 7.9
Process 0 sent number 7.9
Process 1 received number 7.9 from process 0
但奇怪的是收到了这个:
Process 0 will be sending number 1112261192
Process 0 sent number -32766
Process 1 received number -32766 from process 0
我不太擅长MPI的东西,但在我看来,double类型出了问题。因为如果我把"double"改为"int",我会得到预期的输出:
Process 0 will be sending number 7
Process 0 sent number 7
Process 1 received number 7 from process 0
有什么建议吗?
您使用了错误的格式说明符,%d
代表int
。对于double
,应使用%f
、%e
、%a
或%g
,请参阅此处的示例文档。
由于这个问题被标记为c++,所以您最好只使用iostreams进行输出。
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 模板元程序查找相似的连续类型名称
- 是否可以从int转换为enum类类型
- 构造函数正在调用一个使用当前类类型的函数
- 我应该使用什么来代替void作为变体中的替代类型之一
- 类中的字符串不命名类型