如何MPI_Gatherv在发送端的位移?

我正在尝试使用MPI_Gatherv重新组合没有深灰色行的子arrays。 图片胜过千言万语:

鬼/晕暗灰色细胞的图形概述http://img535.imageshack.us/img535/9118/ghostcells.jpg

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

谢谢。

更新(或更准确地说)

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

那么构建一个数据类型会让你只发送白色(内部)单元格呢?

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

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

对于Interior + Boundary,您可以构造单个“line”的数据类型

 MPI_Datatype LineType; MPI_Type_vector (1, row_number, 0 , MPI_DOUBLE, &LineType) MPI_Type_commit ( &LineType); 

然后(对于ARRAY大小[I] [J]为stripecount条纹分割)

 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);