我正在尝试使用 C 中的 MPI 转置矩阵。每个进程都有一个方形子矩阵,我想将其发送到正确的进程(网格上的“相反”进程),并将其作为通信的一部分进行转置。
我正在使用MPI_Type_create_subarray
which 有一个订单参数,MPI_ORDER_C
或者MPI_ORDER_FORTRAN
分别是行优先和列优先。我认为如果我作为其中之一发送,作为另一个接收,那么我的矩阵将作为通信的一部分被转置。然而,这似乎并没有发生 - 它只是保持非转置。
代码的重要部分如下,整个代码文件可在此 gist中获得。有谁知道为什么这不起作用?这种转置方法应该起作用吗?MPI_ORDER_C
在阅读了and的描述后,我本以为会的MPI_ORDER_FORTRAN
,但也许不是。
/* ----------- DO TRANSPOSE ----------- */
/* Find the opposite co-ordinates (as we know it's a square) */
coords2[0] = coords[1];
coords2[1] = coords[0];
/* Get the rank for this process */
MPI_Cart_rank(cart_comm, coords2, &rank2);
/* Send to these new coordinates */
tag = (coords[0] + 1) * (coords[1] + 1);
/* Create new derived type to receive as */
/* MPI_Type_vector(rows_in_core, cols_in_core, cols_in_core, MPI_DOUBLE, &vector_type); */
sizes[0] = rows_in_core;
sizes[1] = cols_in_core;
subsizes[0] = rows_in_core;
subsizes[1] = cols_in_core;
starts[0] = 0;
starts[1] = 0;
MPI_Type_create_subarray(2, sizes, subsizes, starts, MPI_ORDER_FORTRAN, MPI_DOUBLE, &send_type);
MPI_Type_commit(&send_type);
MPI_Type_create_subarray(2, sizes, subsizes, starts, MPI_ORDER_C, MPI_DOUBLE, &recv_type);
MPI_Type_commit(&recv_type);
/* We're sending in row-major form, so it's just rows_in_core * cols_in_core lots of MPI_DOUBLE */
MPI_Send(&array[0][0], 1, send_type, rank2, tag ,cart_comm);
/* Receive from these new coordinates */
MPI_Recv(&new_array[0][0], 1, recv_type, rank2, tag, cart_comm, &status);