Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Bug with DENYNONE specifier?

OP1
New Contributor II
243 Views

For the code below I am using Intel Fortran 14.0.5.239 (64-bit) on Windows 7. Multiple images attempt to write (in orderly fashion) to a file that has been created with the SHARE='DENYNONE' attribute; and yet only the last image writes to it.

I may be overlooking something here, but this behavior puzzles me.

PROGRAM COARRAY_FILE_WRITE
USE ISO_FORTRAN_ENV
IMPLICIT NONE
INTEGER :: I_IMAGE
LOGICAL :: LOCK_IS_ACQUIRED
TYPE(LOCK_TYPE) :: FILE_LOCK
  • ! Image 1 creates the shared file. IF (THIS_IMAGE()==1) THEN OPEN(UNIT=200,FORM='FORMATTED',FILE='Test.txt',STATUS='REPLACE',ACTION='READWRITE',SHARE='DENYNONE') END IF SYNC ALL ! Other images open the (same) shared file. IF (THIS_IMAGE()>1) THEN OPEN(UNIT=200,FORM='FORMATTED',FILE='Test.txt',STATUS='OLD',ACCESS='APPEND',ACTION='READWRITE',SHARE='DENYNONE') END IF SYNC ALL ! All images write something in the shared file, using a lock to prevent simultaneous writes. LOCK_IS_ACQUIRED = .FALSE. DO WHILE (.NOT.LOCK_IS_ACQUIRED) LOCK(FILE_LOCK[1],ACQUIRED_LOCK=LOCK_IS_ACQUIRED) IF (LOCK_IS_ACQUIRED) THEN WRITE(*,*) 'Hi from image ',THIS_IMAGE() WRITE(200,*) 'Hi from image ',THIS_IMAGE() FLUSH(200) UNLOCK(FILE_LOCK[1]) END IF END DO SYNC ALL END PROGRAM COARRAY_FILE_WRITE
  •  

    0 Kudos
    2 Replies
    Steven_L_Intel1
    Employee
    243 Views

    Each image keeps its own file position pointer - you're overwriting the same record in all the images. The type of shared file access you want doesn't really exist in Windows. You'd have to close and reopen the file each time to get the position consistent.

    0 Kudos
    OP1
    New Contributor II
    243 Views

    Ah, ok - thanks Steve, your explanation makes a lot of sense.

    0 Kudos
    Reply