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