Hi,
The idea you exposed here is the right one. Actually, this is the very one I usually use to present MPI_Barrier with a non-trivial real-life use case.
the code becomes:
do i=0,np-1
if (myrank == i)
open(fd, .....) ! open the output file in append mode
write(fd, ....) ! write whatever you need to there
close(fd) ! close the file (forces its flush to disk)
endif
MPI_Barrier(comm, ierr)
enddo
you end up with a sequentialised writing in your file, from rank 0 up to rank np-1.
Cheers.
Gilles