几个小时我试图通过 MPI 将 2D 数组发送到不同的线程。代码看起来像这样(我会留下评论以展示我已经尝试过的技巧):
类型定义:
// Define datatype
//MPI_Type_contiguous(N, MPI_INT, &mpi_vector);
//MPI_Type_vector(N, N, N, mpi_vector, &mpi_matrix);
//MPI_Type_vector(N, N, N, MPI_INT, &mpi_matrix);
//MPI_Type_contiguous(N, MPI_INTEGER, &mpi_vector);
//MPI_Type_contiguous(N, mpi_vector, &mpi_matrix);
MPI_Type_vector(N, N, 0, MPI_INTEGER, &mpi_matrix);
//MPI_Type_commit(&mpi_vector);
MPI_Type_commit(&mpi_matrix);
发送和接收:
int** tmp = new int*[N];
switch(r) {
case T1:
inputMatrix(tmp, 2);
MPI_Send(tmp, 1, mpi_matrix, T2, 0, MPI_COMM_WORLD);
//task_T1();
break;
case T2:
//task_T2();
inputMatrix(tmp, -1);
MPI_Recv(tmp, 1, mpi_matrix, T1, 0, MPI_COMM_WORLD, &s);
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++) {
cout << " " << tmp[i][j];
}
cout << endl;
}
break;
}
我需要完成这件事直到早上(7 小时内),我希望 smb 能够帮助我。