TABLE OF CONTENTS
- ABINIT/m_xomp
- m_xomp/xomp_get_max_threads
- m_xomp/xomp_get_num_cores_node
- m_xomp/xomp_get_num_threads
- m_xomp/xomp_get_thread_num
- m_xomp/xomp_in_parallel
- m_xomp/xomp_set_num_threads
- m_xomp/xomp_show_info
ABINIT/m_xomp [ Modules ]
NAME
m_xomp
FUNCTION
Thin wrappers and tools for OpenMP parallelization.
COPYRIGHT
Copyright (C) 2008-2022 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 .
SOURCE
16 #if defined HAVE_CONFIG_H 17 #include "config.h" 18 #endif 19 20 #include "abi_common.h" 21 22 MODULE m_xomp 23 24 use defs_basis, only : std_out 25 #ifdef HAVE_OPENMP 26 use omp_lib 27 #endif 28 29 implicit none 30 31 private 32 33 public :: xomp_show_info 34 public :: xomp_get_max_threads 35 public :: xomp_get_thread_num 36 public :: xomp_get_num_threads 37 public :: xomp_set_num_threads 38 public :: xomp_in_parallel 39 public :: xomp_get_num_cores_node 40 41 !---------------------------------------------------------------------- 42 43 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.
SOURCE
109 function xomp_get_max_threads() 110 111 !Arguments ------------------------------------ 112 integer :: xomp_get_max_threads 113 114 ! ************************************************************************* 115 116 #ifdef HAVE_OPENMP 117 xomp_get_max_threads = omp_get_max_threads() 118 #else 119 xomp_get_max_threads = 1 120 #endif 121 122 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.
SOURCE
289 function xomp_get_num_cores_node() 290 291 !Arguments ------------------------------------ 292 !scalars 293 integer :: xomp_get_num_cores_node 294 295 ! ************************************************************************* 296 297 #ifdef HAVE_OPENMP 298 xomp_get_num_cores_node=omp_get_thread_limit() 299 !We test if thread_limit has been set (if not it should be a large value) 300 ! In 2012, 4096 cores is the biggest known shared memory system 301 if(xomp_get_num_cores_node > 4096) then 302 !so if not set, we used system 'num procs' values which should be the default case 303 xomp_get_num_cores_node=omp_get_num_procs() 304 end if 305 #else 306 xomp_get_num_cores_node=0 307 #endif 308 309 end function xomp_get_num_cores_node 310 311 !---------------------------------------------------------------------- 312 313 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.
SOURCE
179 function xomp_get_num_threads(open_parallel) result(nthreads) 180 181 !Arguments ------------------------------------ 182 !scalars 183 logical,optional,intent(in) :: open_parallel 184 integer :: nthreads 185 186 !Local variables------------------------------- 187 !scalars 188 logical :: do_open 189 190 ! ************************************************************************* 191 192 do_open = .FALSE.; if (PRESENT(open_parallel)) do_open = open_parallel 193 194 #ifdef HAVE_OPENMP 195 if (do_open .and. .not.xomp_in_parallel()) then 196 !$OMP PARALLEL 197 !$OMP SINGLE 198 nthreads = omp_get_num_threads() 199 !$OMP END SINGLE 200 !$OMP END PARALLEL 201 else 202 nthreads = omp_get_num_threads() 203 end if 204 205 #else 206 nthreads = 1 207 #endif 208 209 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.
SOURCE
140 function xomp_get_thread_num() 141 142 !Arguments ------------------------------------ 143 !scalars 144 integer :: xomp_get_thread_num 145 146 ! ************************************************************************* 147 148 #ifdef HAVE_OPENMP 149 xomp_get_thread_num = omp_get_thread_num() 150 #else 151 xomp_get_thread_num = 0 152 #endif 153 154 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
SOURCE
258 function xomp_in_parallel() result(ans) 259 260 !Arguments------------------------- 261 logical :: ans 262 263 ! ************************************************************************* 264 265 #ifdef HAVE_OPENMP 266 ans = omp_in_parallel() 267 #else 268 ans = .FALSE. 269 #endif 270 271 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.
SOURCE
230 subroutine xomp_set_num_threads(nthreads) 231 232 !Arguments ------------------------------------ 233 !scalars 234 integer,intent(in) :: nthreads 235 236 ! ************************************************************************* 237 238 #ifdef HAVE_OPENMP 239 call omp_set_num_threads(nthreads) 240 #else 241 if (.FALSE.) write(std_out,*) nthreads 242 #endif 243 244 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)
SOURCE
64 subroutine xomp_show_info(unit) 65 66 !Arguments------------------------- 67 integer,optional,intent(in) :: unit 68 69 !Local variables------------------- 70 integer :: my_unt 71 72 ! ************************************************************************* 73 74 my_unt = std_out; if (PRESENT(unit)) my_unt=unit 75 76 #ifdef HAVE_OPENMP 77 write(my_unt,'(/,a)') " ==== OpenMP parallelism is ON ====" 78 write(my_unt,'(a,i0)') "- Max_threads: ",xomp_get_max_threads() 79 write(my_unt,'(a,i0)') "- Num_threads: ",xomp_get_num_threads(open_parallel=.True.) 80 write(my_unt,'(a,i0)') "- Num_procs: ",omp_get_num_procs() 81 write(my_unt,'(a,l1)') "- Dynamic: ",omp_get_dynamic() 82 !write(my_unt,'(a,l1)') "- Nested: ",omp_get_nested() 83 !write(my_unt,'(a,i0)')"- Thread_limit: ",omp_get_thread_limit() 84 !write(my_unt,'(a,i0)')"- Max_active_levels: ",omp_get_max_active_levels() 85 #else 86 write(my_unt,'(/,a)') " ==== OpenMP parallelism is OFF ====" 87 #endif 88 89 write(my_unt,*)"" 90 91 end subroutine xomp_show_info