问题
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 :
- 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)
回答1:
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.
来源:https://stackoverflow.com/questions/59860967/send-a-c-stdvectorbool-via-mpi