通过 mpi 发送 c++ std::vector<bool>

Send a c++ std::vector<bool> via mpi

我知道存储一个 std::vector<bool> is not necessarily an array of bools .

如果我想发送存储在 std::vector<int> 中的接收 int 数据,我会使用 MPI_Send(vect.data(),num_of_ints,MPI_INT,dest_rk,tag,comm).

我应该如何使用 MPI_Send 发送 std::vector<bool> ?特别是:

std::vector<bool>specialization does not have the data() member function. The underlying storage scheme is not specified按标准:

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>