MPI send struct with a vector property in C++

前端 未结 3 1010
南笙
南笙 2021-01-06 03:08

I want to send a struct that has a vector property.

typedef struct {
    int id;
    vector neighbors;
} Node;

I know i have to

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 04:12

    If you want to stay high-level and send around objects, then Boost.MPI is a good choice. With Boost.MPI you specify high level serialization for your structs.

    You cannot (correctly) statically determine the offset of the data member of a vector. It is certainly possible to piece together a type, that works. But that is also a great way to shoot yourself in the foot. You would introduce assumptions in the code (e.g. vector size does not change) that once violated will create subtle bugs. So in that case it seems cleaner and less bug-prone to me to simply send id and neighbours::data() separately in MPI_Send - instead of using MPI types that don't fit to this use case.

提交回复
热议问题