MPI_FILE_OPEN
is a collective operation. It is intended to be called by all MPI ranks with the same file name and the name should also point to a location on a shared filesystem. Otherwise it makes no sense. mkstemp(3)
would generate different names if called in different ranks. Also it creates the file and returns its file descriptor. Probably not what you want if you'd like to use MPI parallel IO.
If you'd really want to create a unique file, then you could probably do something like this:
int rank;
char name[PATH_MAX] = "/path/to/shared/directory/prefixXXXXXX";
MPI_File fh;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// Create the temporary file in rank 0 only
if (rank == 0)
{
int fd = mkstemp(name);
// Close the handle - we don't need it
close(fd);
// <----- Decorate name here
}
// Broadcast the file name to all other ranks
MPI_Bcast(name, PATH_MAX, MPI_CHAR, 0, MPI_COMM_WORLD);
// Now open the file for MPI parallel IO
MPI_File_open(MPI_COMM_WORLD, name, MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
Once you've got the name from mkstemp(3)
, at the point marked as Decorate name here
you can perform additional decorations of the name, e.g. append /PASSWORD=SECRET
to it or prefix it with fstype:
. You could also do it after the broadcast, if you need to put some process-specific decorations.