29 module fms_affinity_mod
31 use,
intrinsic :: iso_c_binding, only: c_int, c_bool
55 integer(KIND=c_int) function get_cpuset(fsz, output, pe, debug)
bind(c, name="get_cpuset")
57 integer(KIND=c_int),
value,
intent(in) :: fsz, pe
58 integer(KIND=c_int),
dimension(*),
intent(inout) :: output
59 logical(KIND=c_bool),
value :: debug
67 integer(KIND=c_int),
value,
intent(in) :: cpu
72 logical:: affinity = .true.
73 logical:: strict = .true.
74 logical:: debug_affinity = .false.
75 logical(c_bool):: debug_cpuset = .false.
76 namelist /fms_affinity_nml/ affinity, strict, debug_affinity, debug_cpuset
82 #include <file_version.h>
84 logical :: module_is_initialized = .false.
96 if (module_is_initialized)
return
102 read(input_nml_file, fms_affinity_nml, iostat=io_stat)
108 write(iunit,nml=fms_affinity_nml)
110 module_is_initialized = .true.
118 character(len=*),
intent(in):: component
119 logical,
intent(in):: use_hyper_thread
120 integer,
intent(in):: nthreads
123 integer(c_int):: cpuset_sz
124 integer(c_int),
dimension(:),
allocatable:: cpu_set
125 integer(c_int):: retcode
128 character(len=32):: h_name
134 if (.not. affinity)
return
145 if (use_hyper_thread)
then
148 cpuset_sz = nthreads * 2
150 allocate (cpu_set(0:cpuset_sz-1))
154 if (retcode == -1)
then
155 call error_mesg(
'fms_affinity_set',trim(component)//
' cpu_set size > allocated storage',fatal)
156 elseif ( (retcode == cpuset_sz/2) .and. (retcode == nthreads) )
then
157 call error_mesg(
'fms_affinity_set',trim(component)//
' affinity assumes hyper-threading hardware disabled',note)
158 elseif (retcode < cpuset_sz)
then
159 call error_mesg(
'fms_affinity_set',trim(component)//
' cpu_set size smaller than expected',msg_type)
164 if (retcode == -1)
then
165 call error_mesg(
'fms_affinity_set',trim(component)//
': issue setting cpu affinity', fatal)
196 end module fms_affinity_mod
subroutine, public fms_affinity_init()
Initialization routine for affinity handling.
subroutine, public fms_affinity_set(component, use_hyper_thread, nthreads)
Routine to set affinity for a component.
Private interface to retrieve this groups CPU set and it's size.
Private interface to set CPU afinity to a given core.
integer function, public check_nml_error(IOSTAT, NML_NAME)
Checks the iostat argument that is returned after reading a namelist and determines if the error code...
subroutine, public write_version_number(version, tag, unit)
Prints to the log file (or a specified unit) the version id string and tag name.
subroutine, public fms_init(localcomm, alt_input_nml_path)
Initializes the FMS module and also calls the initialization routines for all modules in the MPP pack...
subroutine, public error_mesg(routine, message, level)
Print notes, warnings and error messages; terminates program for warning and error messages....
integer function stdlog()
This function returns the current standard fortran unit numbers for log messages. Log messages,...
integer function mpp_pe()
Returns processor ID.
Interface to get affinity from the current component.