
! $Id: mod_synchro_omp.F90 5099 2024-07-22 19:29:09Z abarral $

MODULE mod_synchro_omp

    INTEGER,SAVE :: exit_omp  

CONTAINS

  SUBROUTINE Init_synchro_omp
  USE mod_phys_lmdz_para 
  IMPLICIT NONE

!$OMP BARRIER
!$OMP MASTER
  exit_omp=0
!$OMP END MASTER    
!$OMP BARRIER

  END SUBROUTINE Init_Synchro_omp
  
  SUBROUTINE Synchro_omp  
  USE mod_phys_lmdz_para
  IMPLICIT NONE
  LOGICAL :: out
  CHARACTER (LEN=20) :: modname='synchro_omp'
  CHARACTER (LEN=80) :: abort_message
  
    out=.FALSE.
!$OMP BARRIER
!$OMP ATOMIC
    exit_omp=exit_omp+1
!$OMP BARRIER
    IF (exit_omp==omp_size) THEN
      out=.TRUE.
    ENDIF
    
    DO WHILE (.NOT. out)
!$OMP BARRIER
      IF (exit_omp==omp_size) out=.TRUE.
!$OMP BARRIER
    ENDDO

!$OMP BARRIER
!$OMP MASTER
    exit_omp=0
!$OMP END MASTER
!$OMP BARRIER

    IF (exit_omp/=0) THEN
       abort_message='synchro_omp'
       CALL abort_physic(modname,abort_message,1)
    ENDIF

  END SUBROUTINE Synchro_omp


END MODULE mod_synchro_omp
