Parallel I/O is a tricky subject. You can try to let all processors jointly write one file, or to write a file per process and combine them later. With the standard mechanisms of your programming language there are the following considerations:
Illustrating the last point:
// pseek.c FILE *pfile; pfile = fopen("pseek.dat","w"); fseek(pfile,procid*sizeof(int),SEEK_CUR); // fseek(pfile,procid*sizeof(char),SEEK_CUR); fprintf(pfile,"%d\n",procid); fclose(pfile);
MPI also has its own portable I/O: MPI I/O , for which see chapter~ MPI topic: File I/O .
Alternatively, one could use a library such as hdf5 ; see~\CARPref{tut:hdf5}.
For a great discussion see~ [Mendez:ParallelIOpage] , from which figures here are taken.
crumb trail: > io > Use sequential I/O
MPI processes can do anything a regular process can, including opening a file. This is the simplest form of parallel I/O: every MPI process opens its own file. To prevent write collisions,
For reading it is actually possible for all processes to open the same file, but for reading this is not really feasible. Hence the unique files.
In chapter~ MPI topic: File I/O we discussed MPI I/O. This is a way for all processes on a communicator to open a single file, and write to it in a coordinated fashion. This has the big advantage that the end result is an ordinary Unix file.
crumb trail: > io > Higher level libraries
Libraries such as NetCDF or HDF5 offer advantages over MPI I/O: