I know that the storage of a std::vector<bool>
is not necessarily an array of 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)
.
How should I use MPI_Send
to send a std::vector<bool>
? In particular :
vect.data()
as the pointer to buffer ?MPI_CXX_BOOL
does not apply (see this question )std::vector<bool>
specialization does not have the data()
member function. 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. 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. A better option might be to avoid std::vector<bool>
in your code from the very beginning.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.