how to send a vector of string in mpi?

2019-06-07 01:49发布

问题:

I want to send a vector of string in MPI,but I don't know how should I use the MPI_Send and MPI_receiev. for example if I want to send a vector of long I will use this code:

vector<double> local_data(n);

 MPI_Send(&local_data[0], n, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);

but if I want to send a vector of string like this

vector<std::string> local_data(n);

I don't know what should I use as the size of buffer and the type of variable in MPI_send, or MPI_recive. is there any solution for that?

回答1:

When you want to send strings in MPI, you have to convert them to C style char arrays first. There isn't an MPI_STRING type (unless you're using some non-standard extensions). When you convert to the c_str, you should be able to get the size of the string and use that as the size input for the MPI_SEND or MPI_RECV.



标签: c++ vector mpi