The subroutine parallel_open assigns the next available
logical unit number in the range highest_unit_number
to maximum_unit_number . A unique eight-character
file name is generated by concatenating the letters "tmp" with the
logical unit number and the peer number. A new file with this name
is opened in the current directory and the logical unit number is
returned as an OUT parameter.
Assume the example is compiled for four peers. The first
time parallel_open is called, it opens four
files, tmp90000 , tmp90001 ,
tmp90002 , and tmp90003 , one on each
peer. It returns the single scalar value 90 as the value of
unit_number and .true. as the value of
ok .
EXTRINSIC(hpf_local) SUBROUTINE parallel_open(unit_number, ok)
INTEGER, INTENT(OUT) :: unit_number
LOGICAL, INTENT(OUT) :: ok
CHARACTER*8 :: file_name
IF (highest_unit_number <= maximum_unit_number) THEN
unit_number = highest_unit_number
highest_unit_number = highest_unit_number + 1
WRITE(unit=file_name, fmt='(a3,i2.2,i3.3)') &
'tmp', unit_number, my_processor()
ELSE ! Too many temporary files
ok = .false.
RETURN
END IF
OPEN(UNIT=unit_number, STATUS='new', &
FORM='unformatted', FILE=file_name, &
IOSTAT=jj, ERR=100)
ok = .true.
RETURN
100 ok = .false.
END SUBROUTINE parallel_open