LMDZ
yomoml.F90
Go to the documentation of this file.
1 MODULE yomoml
2 
3 !-- the following system specific omp_lib-module is not always available (e.g. pgf90)
4 !! use omp_lib
5 
6 USE parkind1 ,ONLY : jpim, jpib
7 
8 !**SS/18-Feb-2005
9 !--Dr.Hook references removed, because these locks may also be
10 ! called from within drhook.c itself !!
11 !--Also, there could be considerable & unjustified overhead
12 ! when using Dr.Hook in such a low level
13 
14 !**SS/15-Dec-2005
15 !--The size of lock-variables are now OMP_LOCK_KIND as of in OMP_LIB,
16 ! and OMP_LOCK_KIND is aliased to OML_LOCK_KIND
17 ! OMP_LOCK_KIND is usually 4 in 32-bit addressing mode
18 ! 8 in 64-bit addressing mode
19 !--M_OML_LOCK changed to M_EVENT and kept as 32-bit int
20 !--OML_FUNCT changed to OML_TEST_EVENT
21 !--M_LOCK initialized to -1
22 !--M_EVENT initialized to 0
23 !--Added intent(s)
24 !--Support for omp_lib (but not always available)
25 !--Locks can now also be set/unset OUTSIDE the parallel regions
26 !--Added routine OML_TEST_LOCK (attempts to set lock, but if *un*successful, does NOT block)
27 !--Buffer-zone for M_LOCK; now a vector of 2 elements in case problems/inconsistencies with OMP_LOCK_KIND 4/8
28 
29 !**SS/22-Feb-2006
30 !--Locking routines are doing nothing unless OMP_GET_MAX_THREADS() > 1
31 ! This is to avoid unacceptable deadlocks/timeouts with signal handlers when
32 ! the only thread receives signal while inside locked region
33 !--Affected routines: OML_TEST_LOCK() --> always receives .TRUE.
34 ! OML_SET_LOCK() --> sets nothing
35 ! OML_UNSET_LOCK() --> unsets nothing
36 ! OML_INIT_LOCK() --> inits nothing
37 
38 !**SS/11-Sep-2006
39 !--Added OML_DEBUG feature
40 
41 IMPLICIT NONE
42 
43 SAVE
44 
45 PRIVATE
46 
47 LOGICAL :: oml_debug = .false.
48 !$OMP THREADPRIVATE(OML_DEBUG)
49 
55 
56 !-- The following should normally be 4 in 32-bit addressing mode
57 ! 8 in 64-bit addressing mode
58 ! Since system specific omp_lib-module is not always available (e.g. pgf90)
59 ! we hardcode OML_LOCK_KIND to JPIB (usually 8) for now
60 !!INTEGER(KIND=JPIM), PARAMETER :: OML_LOCK_KIND = OMP_LOCK_KIND
61 INTEGER(KIND=JPIM), PARAMETER :: oml_lock_kind = jpib
62 
63 !-- Note: Still JPIM !!
64 INTEGER(KIND=JPIM) :: m_event = 0
65 !$OMP THREADPRIVATE(M_EVENT)
66 
67 !-- Note: OML_LOCK_KIND, not JPIM !!
68 INTEGER(KIND=OML_LOCK_KIND) :: m_lock(2) = (/-1, -1/)
69 !$OMP THREADPRIVATE(M_LOCK)
70 
71 CONTAINS
72 
73 FUNCTION oml_omp()
74 LOGICAL :: OML_OMP
75 oml_omp=.false.
76 !$ OML_OMP=.TRUE.
77 END FUNCTION oml_omp
78 
79 FUNCTION oml_in_parallel()
80 LOGICAL :: OML_IN_PARALLEL
81 !$ LOGICAL :: OMP_IN_PARALLEL
82 !$ INTEGER(KIND=JPIM) OMP_GET_MAX_THREADS
83 oml_in_parallel=.false.
84 !$ OML_IN_PARALLEL=((OMP_GET_MAX_THREADS() > 1).AND.OMP_IN_PARALLEL())
85 END FUNCTION oml_in_parallel
86 
87 FUNCTION oml_test_lock(MYLOCK)
88 INTEGER(KIND=OML_LOCK_KIND),intent(inout),optional :: MYLOCK
89 LOGICAL :: OML_TEST_LOCK
90 !$ LOGICAL :: OMP_TEST_LOCK
91 !$ INTEGER(KIND=JPIM) OMP_GET_MAX_THREADS
92 oml_test_lock = .true.
93 !$ IF(OMP_GET_MAX_THREADS() > 1) THEN
94 !$ IF(PRESENT(MYLOCK))THEN
95 !$ OML_TEST_LOCK = OMP_TEST_LOCK(MYLOCK)
96 !$ ELSE
97 !$ OML_TEST_LOCK = OMP_TEST_LOCK(M_LOCK(1))
98 !$ ENDIF
99 !$ ENDIF
100 END FUNCTION oml_test_lock
101 
102 SUBROUTINE oml_unset_lock(MYLOCK)
103 INTEGER(KIND=OML_LOCK_KIND),intent(inout),optional :: MYLOCK
104 !$ INTEGER(KIND=JPIM) OMP_GET_MAX_THREADS
105 !$ IF(OMP_GET_MAX_THREADS() > 1) THEN
106 !$ IF(PRESENT(MYLOCK))THEN
107 !$ CALL OMP_UNSET_LOCK(MYLOCK)
108 !$ ELSE
109 !$ CALL OMP_UNSET_LOCK(M_LOCK(1))
110 !$ ENDIF
111 !$ ENDIF
112 END SUBROUTINE oml_unset_lock
113 
114 SUBROUTINE oml_set_lock(MYLOCK)
115 INTEGER(KIND=OML_LOCK_KIND),intent(inout),optional :: MYLOCK
116 !$ INTEGER(KIND=JPIM) OMP_GET_MAX_THREADS
117 !$ IF(OMP_GET_MAX_THREADS() > 1) THEN
118 !$ IF(PRESENT(MYLOCK))THEN
119 !$ CALL OMP_SET_LOCK(MYLOCK)
120 !$ ELSE
121 !$ CALL OMP_SET_LOCK(M_LOCK(1))
122 !$ ENDIF
123 !$ ENDIF
124 END SUBROUTINE oml_set_lock
125 
126 SUBROUTINE oml_init_lock(MYLOCK)
127 INTEGER(KIND=OML_LOCK_KIND),intent(inout),optional :: MYLOCK
128 !$ INTEGER(KIND=JPIM) OMP_GET_MAX_THREADS
129 !$ IF(OMP_GET_MAX_THREADS() > 1) THEN
130 !$ IF(PRESENT(MYLOCK))THEN
131 !$ CALL OMP_INIT_LOCK(MYLOCK)
132 !$ ELSE
133 !$ CALL OMP_INIT_LOCK(M_LOCK(1))
134 !$ ENDIF
135 !$ ENDIF
136 END SUBROUTINE oml_init_lock
137 
138 SUBROUTINE oml_destroy_lock(MYLOCK)
139 INTEGER(KIND=OML_LOCK_KIND),intent(inout),optional :: MYLOCK
140 !$ IF(PRESENT(MYLOCK))THEN
141 !$ CALL OMP_DESTROY_LOCK(MYLOCK)
142 !$ ELSE
143 !$ CALL OMP_DESTROY_LOCK(M_LOCK(1))
144 !$ ENDIF
145 END SUBROUTINE oml_destroy_lock
146 
147 FUNCTION oml_test_event(K,MYEVENT)
148 LOGICAL :: OML_TEST_EVENT
149 INTEGER(KIND=JPIM),intent(in) :: K,MYEVENT
150 IF(k.EQ.myevent) THEN
151  oml_test_event =.true.
152 ELSE
153  oml_test_event=.false.
154 ENDIF
155 END FUNCTION oml_test_event
156 
157 SUBROUTINE oml_wait_event(K,MYEVENT)
158 INTEGER(KIND=JPIM),intent(in) :: K
159 INTEGER(KIND=JPIM),intent(in),OPTIONAL :: MYEVENT
160 IF(PRESENT(myevent))THEN
161  DO
162  IF(oml_test_event(k,myevent)) EXIT
163  ENDDO
164 ELSE
165  DO
166  IF(oml_test_event(k,m_event)) EXIT
167  ENDDO
168 ENDIF
169 END SUBROUTINE oml_wait_event
170 
171 SUBROUTINE oml_set_event(K,MYEVENT)
172 INTEGER(KIND=JPIM),intent(in) :: K
173 INTEGER(KIND=JPIM),intent(out),OPTIONAL :: MYEVENT
174 IF(PRESENT(myevent))THEN
175  myevent=k
176 ELSE
177  m_event=k
178 ENDIF
179 END SUBROUTINE oml_set_event
180 
181 SUBROUTINE oml_incr_event(K,MYEVENT)
182 INTEGER(KIND=JPIM) :: K
183 INTEGER(KIND=JPIM),intent(inout),OPTIONAL :: MYEVENT
184 IF(PRESENT(myevent))THEN
185  myevent=myevent+k
186 ELSE
187  m_event=m_event+k
188 ENDIF
189 END SUBROUTINE oml_incr_event
190 
191 FUNCTION oml_my_thread()
192 INTEGER(KIND=JPIM) :: OML_MY_THREAD
193 !$ INTEGER(KIND=JPIM) OMP_GET_THREAD_NUM
194 oml_my_thread = 1
195 !$ OML_MY_THREAD = OMP_GET_THREAD_NUM() + 1
196 END FUNCTION oml_my_thread
197 
198 FUNCTION oml_max_threads()
199 INTEGER(KIND=JPIM) :: OML_MAX_THREADS
200 !$ INTEGER(KIND=JPIM) OMP_GET_MAX_THREADS
201 oml_max_threads = 1
202 !$ OML_MAX_THREADS = OMP_GET_MAX_THREADS()
203 END FUNCTION oml_max_threads
204 
205 END MODULE yomoml
integer, parameter jpib
Definition: parkind1.F90:14
logical function, public oml_omp()
Definition: yomoml.F90:74
integer(kind=oml_lock_kind), dimension(2) m_lock
Definition: yomoml.F90:68
integer(kind=jpim) function, public oml_max_threads()
Definition: yomoml.F90:199
integer(kind=jpim), parameter, public oml_lock_kind
Definition: yomoml.F90:61
subroutine, public oml_incr_event(K, MYEVENT)
Definition: yomoml.F90:182
subroutine, public oml_unset_lock(MYLOCK)
Definition: yomoml.F90:103
logical, public oml_debug
Definition: yomoml.F90:47
!$Id itapm1 ENDIF!IM on interpole les champs sur les niveaux STD de pression!IM a chaque pas de temps de la physique c!positionnement de l argument logique a false c!pour ne pas recalculer deux fois la meme chose!c!a cet effet un appel a plevel_new a ete deplace c!a la fin de la serie d appels c!la boucle DO nlevSTD a ete internalisee c!dans d ou la creation de cette routine c c!CALL false
Definition: calcul_STDlev.h:26
subroutine, public oml_init_lock(MYLOCK)
Definition: yomoml.F90:127
subroutine, public oml_wait_event(K, MYEVENT)
Definition: yomoml.F90:158
subroutine, public oml_destroy_lock(MYLOCK)
Definition: yomoml.F90:139
subroutine, public oml_set_lock(MYLOCK)
Definition: yomoml.F90:115
!$Id itapm1 ENDIF!IM on interpole les champs sur les niveaux STD de pression!IM a chaque pas de temps de la physique c!positionnement de l argument logique a false c!pour ne pas recalculer deux fois la meme chose!c!a cet effet un appel a plevel_new a ete deplace c!a la fin de la serie d appels c!la boucle DO nlevSTD a ete internalisee c!dans d ou la creation de cette routine c c!CALL ulevSTD CALL &zphi philevSTD CALL &zx_rh rhlevSTD!DO klev DO klon klev DO klon klev DO klon klev DO klon klev DO klon klev DO klon klev DO klon klev DO klon klev DO klon klev DO klon du jour ou toutes les read_climoz CALL true
subroutine, public oml_set_event(K, MYEVENT)
Definition: yomoml.F90:172
logical function, public oml_in_parallel()
Definition: yomoml.F90:80
Definition: yomoml.F90:1
integer, parameter jpim
Definition: parkind1.F90:13
integer(kind=jpim) function, public oml_my_thread()
Definition: yomoml.F90:192
logical function, public oml_test_event(K, MYEVENT)
Definition: yomoml.F90:148
logical function, public oml_test_lock(MYLOCK)
Definition: yomoml.F90:88
integer(kind=jpim) m_event
Definition: yomoml.F90:64