TABLE OF CONTENTS


ABINIT/m_xomp [ Modules ]

[ Top ] [ Modules ]

NAME

 m_xomp

FUNCTION

  Thin wrappers and tools for OpenMP parallelization.

COPYRIGHT

  Copyright (C) 2008-2018 ABINIT group (MG)
  This file is distributed under the terms of the
  GNU General Public License, see ~abinit/COPYING
  or http://www.gnu.org/copyleft/gpl.txt .

PARENTS

CHILDREN

SOURCE

21 #if defined HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include "abi_common.h"
26 
27 MODULE m_xomp
28 
29  use defs_basis,    only : std_out
30 #ifdef HAVE_OPENMP
31  use omp_lib
32 #endif
33 
34  implicit none
35 
36  private
37 
38  public :: xomp_show_info
39  public :: xomp_get_max_threads
40  public :: xomp_get_thread_num
41  public :: xomp_get_num_threads
42  public :: xomp_set_num_threads
43  public :: xomp_in_parallel
44  public :: xomp_get_num_cores_node
45 
46 !----------------------------------------------------------------------
47 
48 CONTAINS  !=========================================================================================================================

m_xomp/xomp_get_max_threads [ Functions ]

[ Top ] [ m_xomp ] [ Functions ]

NAME

  xomp_get_max_threads

FUNCTION

  Wrapper for omp_get_max_threads.

OUTPUT

  Return the maximum number of threads used for the current parallel region that
  does not use the clause num_threads. Return 1 if OMP is disabled.

PARENTS

CHILDREN

SOURCE

133 function xomp_get_max_threads()
134 
135 
136 !This section has been created automatically by the script Abilint (TD).
137 !Do not modify the following lines by hand.
138 #undef ABI_FUNC
139 #define ABI_FUNC 'xomp_get_max_threads'
140 !End of the abilint section
141 
142  implicit none
143 
144 !Arguments ------------------------------------
145 !scalars
146  integer :: xomp_get_max_threads
147 
148 ! *************************************************************************
149 
150 #ifdef HAVE_OPENMP
151  xomp_get_max_threads = omp_get_max_threads()
152 #else
153  xomp_get_max_threads = 1
154 #endif
155 
156 end function xomp_get_max_threads

m_xomp/xomp_get_num_cores_node [ Functions ]

[ Top ] [ m_xomp ] [ Functions ]

NAME

  xomp_get_num_cores_node

FUNCTION

  Wrapper for omp_get_num_procs

OUTPUT

  Return the maximum number of cores in one shared memory system
  Return 0 if OMP is disabled.

PARENTS

  m_abi_linalg

CHILDREN

SOURCE

381 function xomp_get_num_cores_node()
382 
383 
384 !This section has been created automatically by the script Abilint (TD).
385 !Do not modify the following lines by hand.
386 #undef ABI_FUNC
387 #define ABI_FUNC 'xomp_get_num_cores_node'
388 !End of the abilint section
389 
390  implicit none
391 
392 !Arguments ------------------------------------
393 !scalars
394  integer :: xomp_get_num_cores_node
395 
396 ! *************************************************************************
397 
398 #ifdef HAVE_OPENMP
399  xomp_get_num_cores_node=omp_get_thread_limit()
400  !We test if thread_limit has been set (if not it should be a large value)
401  ! In 2012, 4096 cores is the biggest known shared memory system
402  if(xomp_get_num_cores_node > 4096) then
403     !so if not set, we used system 'num procs' values which should be the default case
404     xomp_get_num_cores_node=omp_get_num_procs()
405  end if
406 #else
407  xomp_get_num_cores_node=0
408 #endif
409 
410 end function xomp_get_num_cores_node
411 
412 !----------------------------------------------------------------------
413 
414 END MODULE m_xomp

m_xomp/xomp_get_num_threads [ Functions ]

[ Top ] [ m_xomp ] [ Functions ]

NAME

  xomp_get_num_threads

FUNCTION

  Wrapper for omp_get_num_threads.
  The omp_get_num_threads function returns the number of threads in the team currently executing
  the parallel region from which it is called. The function binds to the closest enclosing PARALLEL directive.
  The omp_set_num_threads subroutine and the OMP_NUM_THREADS environment variable control the number of threads in a team.
  If you do not explicitly set the number of threads, the run-time environment will use the number of online processors
  on the machine by default. If you call omp_get_num_threads from a serial portion of your program or from a
  nested parallel region that is serialized, the function returns 1.

INPUTS

  [open_parallel]= If .TRUE., a temporary OMP parallel region will be open and omp_get_num_threads
                   will be called inside this region.
                   Default to .FALSE. so that we have consistent with the OMP API.

PARENTS

CHILDREN

SOURCE

230 function xomp_get_num_threads(open_parallel) result(nthreads)
231 
232 
233 !This section has been created automatically by the script Abilint (TD).
234 !Do not modify the following lines by hand.
235 #undef ABI_FUNC
236 #define ABI_FUNC 'xomp_get_num_threads'
237 !End of the abilint section
238 
239  implicit none
240 
241 !Arguments ------------------------------------
242 !scalars
243  logical,optional,intent(in) :: open_parallel
244  integer :: nthreads
245 
246 !Local variables-------------------------------
247 !scalars
248  logical :: do_open
249 
250 ! *************************************************************************
251 
252  do_open = .FALSE.; if (PRESENT(open_parallel)) do_open = open_parallel
253 #ifdef HAVE_OPENMP
254 
255  if (do_open .and. .not.xomp_in_parallel()) then
256 !$OMP PARALLEL
257 !$OMP SINGLE
258   nthreads = omp_get_num_threads()
259 !$OMP END SINGLE
260 !$OMP END PARALLEL
261  else
262    nthreads = omp_get_num_threads()
263  end if
264 
265 #else
266  nthreads = 1
267 #endif
268 
269 end function xomp_get_num_threads

m_xomp/xomp_get_thread_num [ Functions ]

[ Top ] [ m_xomp ] [ Functions ]

NAME

  xomp_get_thread_num

FUNCTION

  Wrapper for omp_get_thread_num
  Returns a unique thread identification number within the current team.
  In a sequential parts of the program, omp_get_thread_num always returns 0.
  In parallel regions the return value varies from 0 to omp_get_num_threads-1 inclusive.
  The return value of the master thread of a team is always 0.

PARENTS

CHILDREN

SOURCE

178 function xomp_get_thread_num()
179 
180 
181 !This section has been created automatically by the script Abilint (TD).
182 !Do not modify the following lines by hand.
183 #undef ABI_FUNC
184 #define ABI_FUNC 'xomp_get_thread_num'
185 !End of the abilint section
186 
187  implicit none
188 
189 !Arguments ------------------------------------
190 !scalars
191  integer :: xomp_get_thread_num
192 
193 ! *************************************************************************
194 
195 #ifdef HAVE_OPENMP
196  xomp_get_thread_num = omp_get_thread_num()
197 #else
198  xomp_get_thread_num = 0
199 #endif
200 
201 end function xomp_get_thread_num

m_xomp/xomp_in_parallel [ Functions ]

[ Top ] [ m_xomp ] [ Functions ]

NAME

  xomp_in_parallel

FUNCTION

  This function returns true if are currently running in parallel, false otherwise

CHILDREN

      omp_in_parallel

SOURCE

336 function xomp_in_parallel() result(ans)
337 
338 
339 !This section has been created automatically by the script Abilint (TD).
340 !Do not modify the following lines by hand.
341 #undef ABI_FUNC
342 #define ABI_FUNC 'xomp_in_parallel'
343 !End of the abilint section
344 
345  implicit none
346 
347 !Arguments-------------------------
348  logical :: ans
349 
350 ! *************************************************************************
351 
352 #ifdef HAVE_OPENMP
353  ans = omp_in_parallel()
354 #else
355  ans = .FALSE.
356 #endif
357 
358 end function xomp_in_parallel

m_xomp/xomp_set_num_threads [ Functions ]

[ Top ] [ m_xomp ] [ Functions ]

NAME

  xomp_set_num_threads

FUNCTION

  Specifies the number of threads used by default in subsequent parallel sections,
  if those do not specify a num_threads clause. The argument of xomp_set_num_threads shall be a positive integer.

INPUTS

  nthreads = number of threads

SIDE EFFECTS

  See description.

PARENTS

      lapackprof,m_argparse,m_fft,m_fft_prof

CHILDREN

      omp_set_num_threads

SOURCE

296 subroutine xomp_set_num_threads(nthreads)
297 
298 
299 !This section has been created automatically by the script Abilint (TD).
300 !Do not modify the following lines by hand.
301 #undef ABI_FUNC
302 #define ABI_FUNC 'xomp_set_num_threads'
303 !End of the abilint section
304 
305  implicit none
306 
307 !Arguments ------------------------------------
308 !scalars
309  integer,intent(in) :: nthreads
310 
311 ! *************************************************************************
312 
313 #ifdef HAVE_OPENMP
314  call omp_set_num_threads(nthreads)
315 #else
316  if (.FALSE.) write(std_out,*) nthreads
317 #endif
318 
319 end subroutine xomp_set_num_threads

m_xomp/xomp_show_info [ Functions ]

[ Top ] [ m_xomp ] [ Functions ]

NAME

  xomp_show_info

FUNCTION

  Printout of the most important OMP environment variables.

INPUTS

  unit=unit number for writing. The named constant dev_null defined in defs_basis can be used to avoid any printing.

OUTPUT

  (only writing)

PARENTS

      abinit,fftprof,lapackprof

CHILDREN

      omp_set_num_threads

SOURCE

 75 subroutine xomp_show_info(unit)
 76 
 77 
 78 !This section has been created automatically by the script Abilint (TD).
 79 !Do not modify the following lines by hand.
 80 #undef ABI_FUNC
 81 #define ABI_FUNC 'xomp_show_info'
 82 !End of the abilint section
 83 
 84  implicit none
 85 
 86 !Arguments-------------------------
 87  integer,optional,intent(in) :: unit
 88 
 89 !Local variables-------------------
 90  integer :: my_unt
 91 
 92 ! *************************************************************************
 93 
 94  my_unt = std_out; if (PRESENT(unit)) my_unt=unit
 95 
 96 #ifdef HAVE_OPENMP
 97  write(my_unt,'(/,a)')  "  ==== OpenMP parallelism is ON ===="
 98  write(my_unt,'(a,i0)') "- Max_threads:       ",xomp_get_max_threads()
 99  write(my_unt,'(a,i0)') "- Num_threads:       ",xomp_get_num_threads(open_parallel=.True.)
100  write(my_unt,'(a,i0)') "- Num_procs:         ",omp_get_num_procs()
101  write(my_unt,'(a,l1)') "- Dynamic:           ",omp_get_dynamic()
102  write(my_unt,'(a,l1)') "- Nested:            ",omp_get_nested()
103  !write(my_unt,'(a,i0)')"- Thread_limit:      ",omp_get_thread_limit()
104  !write(my_unt,'(a,i0)')"- Max_active_levels: ",omp_get_max_active_levels()
105 #else
106  write(my_unt,'(/,a)')  "  ==== OpenMP parallelism is OFF ===="
107 #endif
108 
109  write(my_unt,*)""
110 
111 end subroutine xomp_show_info