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

爷,独闯天下 提交于 2020-03-01 04:32:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!