I have a tiny Fortran test program which opens an existing (unformatted) file
for reading. The file is opened read-only with ACTION=READ.
When compiled with pgfortran 16.1, strace shows the file being opened with
the O_RDWR flag.
(The ifort compiler produces a file open with O_RDONLY and gfortran produces
a file open with O_RDONLY|O_CLOEXEC.)
I did verify that you cannot write to the file that was opened with ACTION=READ,
Why does the PGI compiler use O_RDWR? This might have some implications for
a parallel file system such as Lustre where the programmer has been careful to
indicate that the file will not be written to, but the PGI compiler seems to negate
the programmer’s effort. For example, if many MPI ranks on a Lustre filesystem
nearly simultaneously open the same file with O_RDWR but each rank only reads
the file, then performance will be bad on a Lustre filesystem.
If you are interested in testing this, I have a little program which writes a file and
a little program which read the file.
PROGRAM WRITEONE C C Write a little unformatted data file for another program to read. C IMPLICIT NONE INTEGER :: I C C I = 2 OPEN(UNIT=1,FILE='writeone.dat',FORM='UNFORMATTED', & STATUS='UNKNOWN') WRITE(1) I CLOSE(1) END PROGRAM WRITEONE PROGRAM READONE C C Read a little unformatted data file written by "writeone". C IMPLICIT NONE INTEGER :: I C C OPEN(UNIT=1,FILE='writeone.dat',FORM='UNFORMATTED', & STATUS='OLD',ACTION='READ') READ(1) I CLOSE(1) WRITE(*,"('I=',I4)") I END PROGRAM READONE
Compile and run writeone, then compile and run readone under strace.