【发布时间】:2011-08-03 07:47:15
【问题描述】:
我正在尝试在 C 中使用 MPI 转置矩阵。每个进程都有一个方形子矩阵,我想将其发送到正确的进程(网格上的“相反”进程),将其作为交流。
我正在使用MPI_Type_create_subarray,它有一个订单参数,MPI_ORDER_C 或MPI_ORDER_FORTRAN 分别用于行优先和列优先。我认为如果我作为其中之一发送,作为另一个接收,那么我的矩阵将作为通信的一部分被转置。然而,这似乎并没有发生 - 它只是保持不转置。
代码的重要部分如下,整个代码文件可在this gist 获得。有谁知道为什么这不起作用?这种转置方法应该起作用吗?读过MPI_ORDER_C 和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);
【问题讨论】:
标签: c mpi parallel-processing hpc openmpi