问题描述
我想在MPI中发送一个字符串向量,但是我不知道如何使用MPI_Send和MPI_receiev.例如,如果我要发送long
的向量,则将使用以下代码:
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);
我不知道应该在MPI_send中使用什么作为size of buffer
和variable
的类型,或MPI_recive.有什么解决办法吗?
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?
推荐答案
要在MPI中发送字符串,必须首先将其转换为C样式char数组.没有MPI_STRING
类型(除非您使用一些非标准扩展名).转换为c_str时,应该能够获取字符串的大小并将其用作MPI_SEND
或MPI_RECV
的大小输入.
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
.
这篇关于如何在mpi中发送字符串向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!