所以我是MPI的新手,但我继承了使用它的代码。该脚本包含一个处理数据文件并使用MPI_COMM_RANK例程的部分:
/* Load Data */
std::cout << "Loading data..." << std::endl;
ThisTask=0;
All.ICFormat=1;
RestartFlag=1;
/* This is actually an MPI routine, so we will need to set up MPI */
NTask=1; /* Gadget2 global */
All.PartAllocFactor=1.0; /* The factor for allocating memory for particle data. */
All.BufferSize = 1024.0; /* The size (in MByte per processor) of a communication buffer. */
if(!(CommBuffer = malloc(All.BufferSize * 1024 * 1024))) {
printf("failed to allocate memory for `CommBuffer' (%i MB).\n", All.BufferSize);
return EXIT_FAILURE;
}
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
MPI_Comm_size(MPI_COMM_WORLD, &NTask);
read_file(fname, readTask, lastTask);
free(CommBuffer);
MPI_Finalize(); /* clean up & finalize MPI */
std::cout << "...done" << std::endl;
但是,Comm rank会返回错误:
Fatal error in PMPI_Comm_rank: Invalid communicator, error stack:
PMPI_Comm_rank(122): MPI_Comm_rank(comm=0x629300, rank=0x631eec) failed
PMPI_Comm_rank(75).: Invalid communicator
同样,由于我对此完全陌生,我不知道为什么COMM_WORLD会成为无效的沟通者。有什么想法吗?