c - 如何在发送端使用位移的 MPI_Gatherv?

标签 c mpi parallel-processing

我正在尝试用 MPI_Gatherv 重新组合子数组没有深灰色行。图片值一千字:

graphical overview of the ghost/halo dark-grey cells http://img535.imageshack.us/img535/9118/ghostcells.jpg

如何只将 *sendbuf 的一部分(MPI_Gatherv manual 中的第一个参数)发送到根进程(没有在另一个结构中浪费重写,这次没有深灰色行) ? *displacements(第4个参数)只与根进程的*recvbuf有关。

谢谢。

更新(或者更准确地说)

我还想发送“边界”(浅灰色)细胞……而不仅仅是“内部”(白色)细胞。正如 osgx 正确指出的那样:在这种情况下,MPI_Gatherv 就足够了……一些条件数组索引就可以做到这一点。

最佳答案

如何构造一个数据类型,它只允许您发送白色(内部)单元格?

组合(派生)数据类型可以是 MPI_Type_indexed .

唯一的问题是进程 P0 和 PN 中的第一行和最后一行,因为 P1 和 PN 应该发送比 P2....PN-1 更多的数据

对于 Interior+Boundary 你可以用

构造单个“线”的数据类型
MPI_Datatype LineType;
MPI_Type_vector (1, row_number, 0 , MPI_DOUBLE, &LineType)
MPI_Type_commit ( &LineType);

然后(对于 ARRAY 大小的 [I][J] 拆分为 stripecount stripes )

for (i=0; i< processes_number; ++i) { 
    displs[i] = i*(I/stripecount)+1; // point to second line in each stripe
    rcounts[i] = (I/stripecount) -2 ;
}
rcounts[0] ++; // first and last processes must send one line more
rcounts[processes_number-1] ++;
displs[0] -= 1; // first process should send first line of stripe
// lastprocess displacement is ok, because it should send last line  of stripe

source_ptr = ARRAY[displs[rank]];

lines_to_send = rcounts[rank];

MPI_Gatherv( source_ptr, lines_to_send, LineType, recv_buf, rcounts, displs, LineType, root, comm); 

关于c - 如何在发送端使用位移的 MPI_Gatherv?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6593760/

相关文章:

C++ 在 MPI 进程之间共享大型数组和数据结构

c++ - OS X 上的 OpenMP 汇编程序错误

c - 为什么浮点计算结果在 C 和我的计算器上不同?

c - 使用指针从多维数组中获取值 - C

c++ - 根进程的 MPI_Isend 永远不会到达

c++ - MPI_ERR_BUFFER : invalid buffer pointer

c - 以像素为单位的字符串宽度

c - C 中的 printf() 函数评估前后递减

java - 提高欧拉数并行计算的性能

linux - 并行进程: appending outputs to an array in a zsh script