如何通过mpi C++发送布尔数据类型? [英] How to send Boolean datatype through mpi c++?
本文介绍了如何通过mpi C++发送布尔数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 C++ 新手,尝试通过 MPI 发送 bool 数据类型,但 C++ 不支持这种数据类型.
I am new with c++ and trying to send a bool datatype through MPI, but c++ does not support this data type.
我试图让它成为 MPI_BYTE
和 MPI_INT
但它什么也没打印.
I tried to make it MPI_BYTE
and MPI_INT
but it prints nothing.
#include <iostream>
#include "mpi.h"
using namespace std;
int main(int argc, char **argv)
{
int R,P;
MPI_Status status;
bool check = false;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &P);
MPI_Comm_rank(MPI_COMM_WORLD, &R);
if (R == 0)
{
check = true;
MPI_Send(&check,1,MPI_BYTE,1,1,MPI_COMM_WORLD);
}
else if (R == 1)
{
MPI_Recv(&check,1,MPI_BYTE,0,1,MPI_COMM_WORLD,&status);
cout << R <<"\t check is \t"<< check << endl;
}
MPI_Finalize();
return 0;
}
没有错误消息.
推荐答案
标准(MPI 3.1 table 3.4 page 27)定义了 MPI_CXX_BOOL
与 C++ bool
一起使用数据类型.
The standard (MPI 3.1 table 3.4 page 27) defines MPI_CXX_BOOL
to be used with the C++ bool
datatype.
这篇关于如何通过mpi C++发送布尔数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文