1

假设您有一个 3d 数组 A[I][J][K],但您想将其置换为 B[J][K][I]。

这个问题与此处讨论的二维数组转置问题相似但不同: Can you transpose array when sent using MPI_Type_create_subarray? .

MPI 标准提供了具有用户定义数据类型的多维数组操作示例,但没有提供这种特殊情况:http ://www.mpi-forum.org/docs/mpi-11-html/node61.html

4

1 回答 1

1

做到这一点的方法是使用MPI_TYPE_VECTORand MPI_TYPE_CREATE_HVECTOR,但魔鬼在细节中。

/* data[I][J][K] is I by J by K (stored in array 'dim_sizes[] = {I, J, K}'
   and we want permuted[J][K][I] */

/* new innermost dimension is I items, strided across the old JK face*/
MPI_Type_vector(dim_sizes[0], 1, dim_sizes[1]*dim_sizes[2], 
    MPI_DOUBLE, &one_d);
MPI_Type_commit(&one_d);

/* new middle dimenson is K items, strided over the K row, which isn't
 * actually a stride in this case.  We use hvector here because we 
 * operate directly in terms of array items */
MPI_Type_create_hvector(dim_sizes[2], 1, sizeof(double), one_d, &two_d);
MPI_Type_commit(&two_d);

/* new outermost dimension is J items, strided over the old J row */
MPI_Type_create_hvector(dim_sizes[1], 1, dim_sizes[2]*sizeof(double), two_d,
    &transposed_type);
MPI_Type_commit(&transposed_type);

现在,您可以提供transposed_type给您的发送/接收呼叫或使其成为您的 MPI 文件视图。

于 2012-10-26T19:36:55.257 回答