简体   繁体   中英

Boost.MPI recv into slice of existing vector

vector<int> master(100);
vector<reference_wrapper<int>> sub = master(&master[10], &master[20]);
boost::mpi::irecv(source, tag, sub);

Is the above valid and functional to recv and update a subset of the vector?

If not, is there an equivalent alternative other than recv and copy?

Your code is not valid , as your compiler will happily tell you. There is no such constructor for a std::vector<std::reference_wrapper<int>> . Also reference_wrapper does not magically work this way.

One might think, that boost::iterator_range would be a good idea to use in this case, but it does not support serialization. So aside from building you own range adapter that supports serialization, you have to do it manually. This is fortunately very simple by using the array overload:

comm.irecv(source, tag, &master[10], 10);

This works because std::vector is guaranteed to use contiguous storage . Note, you must also send the data in the array form . Do not just send a smaller 10-element vector.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM