I am trying to send a user-defined structure called ABC using the boost :: mpi :: send () call.
This structure contains vector "data" whose size is determined at runtime. Struct ABC objects are sent by the master to the subordinates. But the slaves must know the size of the vector "data" so that a sufficient buffer is available on the slave server to receive this data. I can get around it by first sending the size and initializing a sufficient buffer on the slave before receiving struct ABC objects. But this is detrimental to the entire purpose of using STL containers.
Does anyone know how best to deal with this? Any suggestions are welcome.
Here is a sample code that describes the intent of my program. This code fails due to the above reason.
struct ABC { double cur_stock_price; double strike_price; double risk_free_rate; double option_price; std::vector <char> data; }; namespace boost { namespace serialization { template<class Archive> void serialize (Archive &ar, struct ABC &abc, unsigned int version) { ar & abc.cur_stock_price; ar & abc.strike_price; ar & abc.risk_free_rate; ar & abc.option_price; ar & bopr.data; } } } BOOST_IS_MPI_DATATYPE (ABC); int main(int argc, char* argv[]) { mpi::environment env (argc, argv); mpi::communicator world; if (world.rank () == 0) { ABC abc_obj; abc.cur_stock_price = 1.0; abc.strike_price = 5.0; abc.risk_free_rate = 2.5; abc.option_price = 3.0; abc_obj.data.push_back ('a'); abc_obj.data.push_back ('b'); world.send ( 1, ANY_TAG, abc_obj;); std::cout << "Rank 0 OK!" << std::endl; } else if (world.rank () == 1) { ABC abc_obj;
source share