我需要使用 MPI_Gatherv()
来收集一些整数/字符串对。假设每对键值对的格式如下:
struct Pair {
int x;
unsigned s_len;
char s[1]; // variable-length string of s_len chars
};
如何为Pair定义合适的MPI数据类型?
while (buffer is not empty)
{
read x;
read s_len;
allocate s_len characters;
move s_len characters from buffer to allocated space;
}
MPI实现不会检查或解释消息的实际内容。只要您知道数据结构的大小,就可以用一些char或int表示该大小。MPI实现将不知道或关心数据的实际内部细节。
有一些注意事项...发送方和接收方都需要就消息内容的解释达成一致,并且您在发送和接收端提供的缓冲区需要适合某些可定义的char或int数量。
char s[0];
来定义可变长度数组,而不是char s[1];
。 - kennytm