版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。版权
注意下面有一个小技巧 string长度要加1,否则 \0 传不过去。Pack
| 13 int str1_size = strlen(name)+1;
| 15 int size = str1_size+str2_size+(2+4)*INT_SIZE_MPI;
| 16 char buffer[size];
| 17 int position = 0;
| 18 MPI_Pack(&str1_size, 1, MPI_INT, buffer, size, &position, MPI_COMM_WORLD);
| 19 MPI_Pack(name, str1_size, MPI_CHAR, buffer, size, &position, MPI_COMM_WORLD);
Unpack
| 47 int strsize1;
| 48 MPI_Unpack(buffer, maxsize, &position, &strsize1, 1, MPI_INT, MPI_COMM_WORLD);
| 49 char name[strsize1];
| 50 MPI_Unpack(buffer, maxsize, &position, &name, strsize1, MPI_CHAR, MPI_COMM_WORLD);