[英]Send a c++ std::vector<bool> via mpi
I know that the storage of a std::vector<bool>
is not necessarily an array of bools .我知道
std::vector<bool>
的存储不一定是 bools 数组。
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)
.如果我想发送存储在
std::vector<int>
中的接收 int 数据,我会使用MPI_Send(vect.data(),num_of_ints,MPI_INT,dest_rk,tag,comm)
。
How should I use MPI_Send
to send a std::vector<bool>
?我应该如何使用
MPI_Send
发送std::vector<bool>
? In particular :特别是 :
vect.data()
as the pointer to buffer ?vect.data()
作为指向缓冲区的指针吗?MPI_CXX_BOOL
does not apply (see this question )MPI_CXX_BOOL
不适用(见这个问题)std::vector<bool>
specialization does not have the data()
member function. std::vector<bool>
专业化不具有data()
成员函数。 The underlying storage scheme is not specified by the standard:标准没有规定底层存储方案:
There is no requirement that the data be stored as a contiguous allocation of
bool
values.不要求将数据存储为
bool
值的连续分配。 A space-optimized representation of bits is recommended instead.推荐使用位的空间优化表示。
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.发送
std::vector<bool>
的唯一合理选择是将其复制到char
向量(或类似std::int8_t
一些类似类型)中,然后发送该向量。 A better option might be to avoid std::vector<bool>
in your code from the very beginning.更好的选择可能是从一开始就避免在代码中使用
std::vector<bool>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.