So I am a complete novice at MPI but I've inherited code that uses it. The script contains a section that processes a data file and uses the MPI_COMM_RANK routine:
/* 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;
However, Comm rank returns the error:
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
Again, as I'm totally new to this I have no idea why COMM_WORLD would be an invalid communicator here. Any ideas?