This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
FORTRAN rewind on NFS filesystems
- To: gcc-bugs at gcc dot gnu dot org
- Subject: FORTRAN rewind on NFS filesystems
- From: Mathias Puetz <mpuetz at unm dot edu>
- Date: Wed, 2 Feb 2000 13:16:52 -0700
- Organization: Advanced Materials Lab / University of New Mexico
Hello,
we are running a Linux cluster with diskless slave nodes
at our site and have a strange problem related to NFS.
The problem is more likely to be with Fortran g77 than
a real NFS problem. However, I'm not sure, the bug might
as well be some 'feature' of the Linux NFS2 implementation.
I have tested this using the following
egcs 1.1.2
kernel 2.2.13
knfsd-clients-1.4.7
knfsd-1.4.7
The NFS options of the file system are as follows
server /etc/exports options :
/home clu-*(rw)
client /etc/fstab mount options :
server:/home /home nfs rw,rsize=8192,wsize=8192 0 0
The problem manifests itself when I write to a
file, then rewind to the beginning and write again.
The problem only occurs when running on NFS
Also only FORTRAN (g77, also Absoft F77 6.0 for Linux) code
seems to be affected, the equlivalent C code behaves as I
would have expected. The problem seems to be that FORTRAN
tries to truncate the file at the position after the last
write statement, whereas C just overwrites the initial part
and leaves the remainder of the first write in place
when the file is closed. The FORTRAN version works
when the second write is larger than the first.
Many of our scientific FORTRAN codes don't run on
our cluster because of this problem.
------- C Version ------------
#include <stdio.h>
int main(int argc,char *argv[])
{
FILE *f = fopen("testfile","w");
if (f) {
fprintf(f,"Totally wrong!\n");
rewind(f);
fprintf(f,"Right!\n");
fclose(f);
}
else {
fprintf(stderr,"couldn't open file\n");
return 1;
}
return 0;
}
-------- FORTRAN Version ----------------
PROGRAM rew
CHARACTER(80) iwrote
OPEN(FILE='testfile',UNIT=10,STATUS='new')
WRITE(10,*) 'Totally Wrong!'
REWIND(10)
WRITE(10,*) 'Right!'
c
c comment the above line, and uncomment below and
c it works on NFS
c
c WRITE(10,*) 'Absolutely Right!'
CLOSE(10)
END
-------------------------------------------
no compiler options in both cases.
the contents of 'testfile' of the C version is
Right!
wrong!
the contents of 'testfile' of the F77 version is
Right!
if run on an ext2 filesystem
and I get the error message
endfile: truncation failed in endfile
apparent state: unit 10 named testfile
last format: list io
lately writing direct formatted external IO
Aborted (core dumped)
if run on a NFS2 filesystem.
Bug fixes or workarounds are most welcome,
Mathias
______________
/ \
| Mathias Puetz \__________________________________
| \
| Advanced Materials Lab (University of New Mexico) \
| 1001 University SE, Albuquerque, NM 87106 |
| \|/ |
| phone: (505)272-7132 -O- fax: (505)272-7336 |
| /|\ |
| \|/ email: mpuetz@unm.edu \|/ |
\___/o\________or puetz@mpip-mainz.mpg.de____/o\____/