简体   繁体   中英

how to send a vector of string in mpi?

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?

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 .

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