Implied-do read/write and MPI

The following code should write and read a file of 282830*8 + 8 bytes long, and indeed it does when compiled and run in serial mode (with the MPI bits commented out).

When compiled and run as below, it also works if the implied-do read/write statements are replaced by WRITE(2) TEMP etc.

However, as shown below, the code
(a) writes a binary file 4 bytes too long
(b) crashes when it tries to read it.

This problem is particularly frustrating as the implied-do read/write commands were in fact a workaround for a bug in the Intel fortran compiler, which produces segmentation faults when reading/writing large arrays with commands like write(2) TEMP(:,:,:)

Any thoughts on a viable workaround?

Phil


PROGRAM TRY

IMPLICIT NONE
INTEGER :: N1, N2, N3, IOS, MPIERR, MPIRANK, MPISIZE
REAL( KIND = 8), DIMENSION(28,28,30) :: TEMP
include ‘mpif.h’
CALL MPI_INIT(MPIERR)
CALL MPI_COMM_RANK(MPI_COMM_WORLD, MPIRANK, MPIERR)
CALL MPI_COMM_SIZE(MPI_COMM_WORLD, MPISIZE, MPIERR)

IF( MPIRANK .eq. 0) PRINT*, 'NUMBER OF COMPUTE PROCESSORS USED IS ', MPISIZE - 1



IF(MPIRANK .eq. 0) THEN


OPEN(2, FILE = ‘./temp.out’, STATUS = ‘REPLACE’, FORM = ‘UNFORMATTED’, IOSTAT = IOS)
IF( IOS .eq. 0) THEN
WRITE(2)(((TEMP(N1, N2, N3), N1 = 1, 28), N2 = 1, 28), N3 = 1,30)
CLOSE(2)
ELSE
PRINT*, ‘ERROR ON TRYING TO WRITE TO FILE TEMP.OUT’
ENDIF

PRINT*, ‘WRITE SUCCESSFUL’

OPEN(2, FILE = ‘./temp.out’, STATUS = ‘OLD’, FORM = ‘UNFORMATTED’, IOSTAT = IOS)
IF( IOS .eq. 0) THEN
READ(2) (((TEMP(N1, N2, N3), N1 = 1, 28), N2 = 1, 28), N3 = 1,30)
CLOSE(2)
ELSE
PRINT*, ‘ERROR ON TRYING TO READ FROM FILE TEMP.OUT’
ENDIF


ENDIF

! Parallel stuff:
CALL MPI_FINALIZE(MPIERR)



STOP

END PROGRAM TRY

Hi Phil,

I was able to run successfully the program here using the 6.0-4 and 5.2-4 compilers in both 32 and 64-bits.

% pgf90 try.f -I/opt/mpi/mpich/include -L/opt/mpi/mpich/lib -lmpich -Mextend -fastsse -V6.0-4
% mpirun -np 4 a.out
 NUMBER OF COMPUTE PROCESSORS USED IS             3
 WRITE SUCCESSFUL
 READ SUCCESSFUL
FORTRAN STOP
FORTRAN STOP
FORTRAN STOP
FORTRAN STOP
% ll temp.out
-rw-rw-r--  1 apps sw 188168 2005-06-14 09:01 temp.out

Which version of the compilers are you using? What flags do you use to compile with? What OS are you using? How was your MPICH library built (compiler, flags, etc.)?

Thanks,
Mat