首页 > 解决方案 > MPI_Gather 动态 2D 分配数组 - MPI C

问题描述

在每个处理器上,我都动态分配了二维数组

char** result = malloc(maxRows * sizeof(char*));
int i;
for(i = 0 ; i<maxRows; ++i) result[i] = malloc(maxCols * sizeof(char));

但是这些数组填充了存储在名为count wherecount < maxRows的变量中的不同大小。我想将这些数组收集到主机上的一个数组中。请问有什么想法吗?

数据示例:

Process 1 : count = 3 , result[0] = "hello" , result[1] = "MPI" , result[2] = "World".
Process 2 : count = 2 , result[0] = "hi" , result[1] = "stackoverflow".

我希望主进程返回:

Process 0 (master) : count = 5 , result[0] = "hello" , result[1] = "MPI" ,
result[2] = "World" , result[3] = "hi" , result[4] = "stackoverflow".

标签: cparallel-processingmpi

解决方案


推荐阅读