您可以注意到代碼在MPI_COMM_WORLD中實例化,但在函數send_code中使用!如何聲明MPI_COMM_WORLD以便我可以在任何地方使用它?
我的代碼是:
int send_code(char *code)
{
//produce the codes for adding the code into the table
printf("%s\n",code);
MPI_Send(code, 8, MPI_CHAR,0, 0,MPI_COMM_WORLD);
}
int main(int argc, char *argv[])
{
MPI_Status status;
int outbuf, inbuf;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank==0)
{
MPI_Recv(code, 8, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);
printf("%s by master\n",code);
}
else
{
........
}
MPI_Finalize();
}
它的類型是什麼? – tchap 2012-03-25 14:38:08