CでMPIを使用してマトリックスを転置しようとしています。各プロセスには正方形のサブマトリックスがあり、それを正しいプロセス(グリッド上の「反対側」のプロセス)に送信して、通信の一部として転置します。
私は、それぞれ行メジャーと列メジャーのいずれか、またはMPI_Type_create_subarray
順序の引数を持つwhichを使用しています。これらの1つとして送信し、もう1つとして受信した場合、私のマトリックスは通信の一部として転置されると思いました。ただし、これは発生しないようです。転置されないままです。MPI_ORDER_C
MPI_ORDER_FORTRAN
コードの重要な部分は以下のとおりです。コードファイル全体は、この要点で入手できます。なぜこれが機能しないのか誰かが何か考えを持っていますか?転置作業を行うためのこのアプローチは必要ですか?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);