File streams in distributed mem. environment

Hi everyone,

my question concerns the parallel I/O safeness of C file streams.

In a simple MPI program I do something like this in parallel:
int rank = MPI_Comm_rank(...);

FILE *fid = fopen("file", "rb");
// reposition file pointer to this process' start point:
fseek(fid, rank*chunksize, SEEK_SET);
// read a chunk of data
fread(data, 4, chunksize, fid);

The question is simple: is this in general safe?
I mean, is it possible that the different processes' file pointers could somehow interfere with each other? Or does this also depend on the underlying file system? I'd appreciate if someone could elaborate a little on the principles of I/O stream etc.

And going one step further: What about using that code for file *writing* instead of only reading?

Thanks in advance for your help!
FILE* uses buffered I/O. So there's always an issue when writing. However, multiple processes can read without locking. On some OS' (like Windows) the share-read option needs to be set.
Topic archived. No new replies allowed.