Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

Coarray and SYNC MEMORY statement

$
0
0

Beyond the "Coarrays in the next Fortran Standard" document by Reid et al, is there a thorough treatment of the subject/documentation available anywhere? I am trying to graps some of the subtle(r) aspects of coarray.

For instance, I am puzzled by the behavior of the simple code below. When the SYNC MEMORY statement is commented out, the code runs until completion; but I will note that all tasks do no start in parallel - tasks assigned to images other than 1 do not start until image 1 has completed its task. When the SYNC MEMORY statement in not commented out, the code behavior is the desired one (all images start doing their tasks in parallel), but then the code hangs after the last task complete.

I am sure the reason for this must be obvious to those more versed in coarray but it still escapes me :) .

Thanks in advance for your help,
Olivier

 

PROGRAM
MAIN
USE
, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: LOCK_TYPE
IMPLICIT NONE
INTEGER
:: I,J,TASK
INTEGER
:: STACK_SIZE[*]
INTEGER
,ALLOCATABLE:: TASK_STACK(:)[:]
LOGICAL
:: KEEP_WORKING
REAL(8)
:: R
TYPE
(LOCK_TYPE) :: STACK_LOCK[*]
ALLOCATE
(TASK_STACK(10)[*])
IF
(THIS_IMAGE()==1)
THEN

DOI=1,SIZE(TASK_STACK)
TASK_STACK(I) = I

END DO
STACK_SIZE =
SIZE(TASK_STACK)

WRITE(*,*) 'There will be', NUM_IMAGES(), ' images executing the tasks.'
END IF
SYNC ALL
KEEP_WORKING = .TRUE.
DO
WHILE(KEEP_WORKING)
LOCK(STACK_LOCK[1])

IF (STACK_SIZE[1]>0) THEN
TASK = TASK_STACK(STACK_SIZE[1])[1]
STACK_SIZE[1] = STACK_SIZE[1]-1
KEEP_WORKING = .TRUE.

ELSE
KEEP_WORKING = .FALSE.

END IF

UNLOCK(STACK_LOCK[1])

!SYNC MEMORY

IF (KEEP_WORKING) THEN

WRITE(*,*)'I am image ',THIS_IMAGE(),' and I am doing task ',TASK,'.'
R = 0.0D+0

DOI=1,8000

DOJ=1,8000
R = R+
COS(REAL(I,KIND=8))+SIN(REAL(J,KIND=8)+R)

END DO

END DO

WRITE(*,*)'I am image ',THIS_IMAGE(),' and I am done: ',R

END IF
END DO
SYNC ALL
END
PROGRAM MAIN

Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>