发送一个c ++ std :: vector< bool>通过MPI [英] Send a c++ std::vector<bool> via mpi
问题描述
我知道std::vector<bool>
的存储不一定是布尔.
如果我要发送存储在std::vector<int>
中的接收int数据,则可以使用MPI_Send(vect.data(),num_of_ints,MPI_INT,dest_rk,tag,comm)
.
If I want to send receive int data stored in a std::vector<int>
, I would use MPI_Send(vect.data(),num_of_ints,MPI_INT,dest_rk,tag,comm)
.
我应该如何使用MPI_Send
发送std::vector<bool>
?特别是:
How should I use MPI_Send
to send a std::vector<bool>
? In particular :
- 我可以/应该使用
vect.data()
作为缓冲区的指针吗? - 我应该提供哪种MPI类型?不知何故,我觉得
MPI_CXX_BOOL
不适用(请参阅此 question ) - 我应该给多少个元素? (与上一点有关)
- Can / should I use
vect.data()
as the pointer to buffer ? - What MPI type should I give ? Somehow, I feel like
MPI_CXX_BOOL
does not apply (see this question) - What number of elements should I give ? (related to the previous point)
推荐答案
std::vector<bool>
专业化没有data()
成员函数.标准未指定基础存储方案 :
std::vector<bool>
specialization does not have the data()
member function. The underlying storage scheme is not specified by the standard:
不要求将数据存储为
bool
值的连续分配.建议改用空间优化的位表示形式.
There is no requirement that the data be stored as a contiguous allocation of
bool
values. A space-optimized representation of bits is recommended instead.
发送std::vector<bool>
的唯一合理选择是将其复制到char
(或类似std::int8_t
的类似类型)的向量中,然后发送该向量.更好的选择可能是从一开始就避免在代码中使用std::vector<bool>
.
The only reasonable option to send std::vector<bool>
is to copy it into a vector of char
(or some similar type like std::int8_t
), and then send that vector. A better option might be to avoid std::vector<bool>
in your code from the very beginning.
这篇关于发送一个c ++ std :: vector< bool>通过MPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!