Browse Source

Added a fortran routine to determine if OpenMP has been enabled. Added a python wrapper, and updated the default omp.f90 and wrffortran.pyf.

lon0
Bill Ladwig 8 years ago
parent
commit
6a54d31c2e
  1. 13
      fortran/omp.f90
  2. 17
      fortran/ompgen.F90
  3. 8
      fortran/wrffortran.pyf
  4. 4
      src/wrf/api.py
  5. 16
      src/wrf/config.py
  6. 2
      src/wrf/constants.py

13
fortran/omp.f90

@ -10,6 +10,19 @@ MODULE omp_constants @@ -10,6 +10,19 @@ MODULE omp_constants
END MODULE omp_constants
FUNCTION fomp_enabled()
IMPLICIT NONE
!f2py threadsafe
LOGICAL :: fomp_enabled
fomp_enabled = .FALSE.
END FUNCTION fomp_enabled
SUBROUTINE fomp_set_num_threads(num_threads)
IMPLICIT NONE

17
fortran/ompgen.F90

@ -61,6 +61,23 @@ MODULE omp_constants @@ -61,6 +61,23 @@ MODULE omp_constants
END MODULE omp_constants
FUNCTION fomp_enabled()
IMPLICIT NONE
!f2py threadsafe
LOGICAL :: fomp_enabled
#ifdef _OPENMP
fomp_enabled = .TRUE.
#else
fomp_enabled = .FALSE.
#endif
END FUNCTION fomp_enabled
SUBROUTINE fomp_set_num_threads(num_threads)
#ifdef _OPENMP
USE omp_lib

8
fortran/wrffortran.pyf

@ -42,6 +42,10 @@ python module _wrffortran ! in @@ -42,6 +42,10 @@ python module _wrffortran ! in
integer, parameter,optional :: fomp_lock_kind=4
integer(kind=4), parameter,optional :: fomp_sched_auto=4
end module omp_constants
function fomp_enabled() ! in :_wrffortran:omp.f90
threadsafe
logical :: fomp_enabled
end function fomp_enabled
subroutine fomp_set_num_threads(num_threads) ! in :_wrffortran:omp.f90
threadsafe
integer intent(in) :: num_threads
@ -229,7 +233,7 @@ python module _wrffortran ! in @@ -229,7 +233,7 @@ python module _wrffortran ! in
end subroutine dpfcalc
subroutine dcapecalc3d(prs,tmk,qvp,ght,ter,sfp,cape,cin,cmsg,mix,mjy,mkzh,ter_follow,psafile,errstat,errmsg) ! in :_wrffortran:rip_cape.f90
threadsafe
use wrf_constants, only: tlclc2,gamma,tlclc1,rgasmd,tlclc4,g,tlclc3,thtecon3,eps,rd,cpmd,celkel,gammamd,eslcon2,eslcon1,cp,thtecon1,algerr,ezero,thtecon2
use wrf_constants, only: tlclc2,gamma,tlclc1,rgasmd,tlclc4,g,tlclc3,thtecon3,eps,rd,cpmd,celkel,gammamd,eslcon2,eslcon1,cp,thtecon1,ezero,thtecon2
real(kind=8) dimension(mix,mjy,mkzh),intent(in) :: prs
real(kind=8) dimension(mix,mjy,mkzh),intent(in),depend(mix,mjy,mkzh) :: tmk
real(kind=8) dimension(mix,mjy,mkzh),intent(in),depend(mix,mjy,mkzh) :: qvp
@ -249,7 +253,7 @@ python module _wrffortran ! in @@ -249,7 +253,7 @@ python module _wrffortran ! in
end subroutine dcapecalc3d
subroutine dcapecalc2d(prs,tmk,qvp,ght,ter,sfp,cape,cin,cmsg,mix,mjy,mkzh,ter_follow,psafile,errstat,errmsg) ! in :_wrffortran:rip_cape.f90
threadsafe
use wrf_constants, only: tlclc2,gamma,tlclc1,rgasmd,tlclc4,g,tlclc3,thtecon3,eps,rd,cpmd,celkel,gammamd,eslcon2,eslcon1,cp,thtecon1,algerr,ezero,thtecon2
use wrf_constants, only: tlclc2,gamma,tlclc1,rgasmd,tlclc4,g,tlclc3,thtecon3,eps,rd,cpmd,celkel,gammamd,eslcon2,eslcon1,cp,thtecon1,ezero,thtecon2
real(kind=8) dimension(mix,mjy,mkzh),intent(in) :: prs
real(kind=8) dimension(mix,mjy,mkzh),intent(in),depend(mix,mjy,mkzh) :: tmk
real(kind=8) dimension(mix,mjy,mkzh),intent(in),depend(mix,mjy,mkzh) :: qvp

4
src/wrf/api.py

@ -2,7 +2,7 @@ from .config import (xarray_enabled, disable_xarray, enable_xarray, @@ -2,7 +2,7 @@ from .config import (xarray_enabled, disable_xarray, enable_xarray,
cartopy_enabled, disable_cartopy, enable_cartopy,
basemap_enabled, disable_basemap, enable_basemap,
pyngl_enabled, enable_pyngl, disable_pyngl,
set_cache_size, get_cache_size)
set_cache_size, get_cache_size, omp_enabled)
from .constants import (ALL_TIMES, Constants, ConversionFactors,
ProjectionTypes, default_fill)
from .destag import destagger
@ -58,7 +58,7 @@ __all__ += ["xarray_enabled", "disable_xarray", "enable_xarray", @@ -58,7 +58,7 @@ __all__ += ["xarray_enabled", "disable_xarray", "enable_xarray",
"cartopy_enabled", "disable_cartopy", "enable_cartopy",
"basemap_enabled", "disable_basemap", "enable_basemap",
"pyngl_enabled", "enable_pyngl", "disable_pyngl",
"set_cache_size", "get_cache_size"]
"set_cache_size", "get_cache_size", "omp_enabled"]
__all__ += ["ALL_TIMES", "Constants", "ConversionFactors", "ProjectionTypes",
"default_fill"]
__all__ += ["destagger"]

16
src/wrf/config.py

@ -4,6 +4,8 @@ from __future__ import (absolute_import, division, print_function, @@ -4,6 +4,8 @@ from __future__ import (absolute_import, division, print_function,
from threading import local
import wrapt
from ._wrffortran import fomp_enabled
_local_config = local()
def _init_local():
@ -198,5 +200,17 @@ def get_cache_size(): @@ -198,5 +200,17 @@ def get_cache_size():
global _local_config
return int(_local_config.cache_size)
def omp_enabled():
"""Return True if OpenMP is enabled.
OpenMP is only enabled if compiled with OpenMP features.
Returns:
:obj:`bool`: True if OpenMP is enabled, otherwise False.
"""
return True if fomp_enabled() else False

2
src/wrf/constants.py

@ -6,7 +6,7 @@ import struct @@ -6,7 +6,7 @@ import struct
import numpy as np
from .py3compat import viewitems
from wrf._wrffortran import wrf_constants, omp_constants
from ._wrffortran import wrf_constants, omp_constants
#: Indicates that all times should be used in a diagnostic routine.
ALL_TIMES = None

Loading…
Cancel
Save