30 module fms_affinity_mod
32 use,
intrinsic :: iso_c_binding, only: c_int, c_bool
56 integer(KIND=c_int) function get_cpuset(fsz, output, pe, debug)
bind(c, name="get_cpuset")
58 integer(KIND=c_int),
value,
intent(in) :: fsz, pe
59 integer(KIND=c_int),
dimension(*),
intent(inout) :: output
60 logical(KIND=c_bool),
value :: debug
68 integer(KIND=c_int),
value,
intent(in) :: cpu
73 logical:: affinity = .true.
74 logical:: strict = .true.
75 logical:: debug_affinity = .false.
76 logical(c_bool):: debug_cpuset = .false.
77 namelist /fms_affinity_nml/ affinity, strict, debug_affinity, debug_cpuset
83 #include <file_version.h>
85 logical :: module_is_initialized = .false.
97 if (module_is_initialized)
return
103 read(input_nml_file, fms_affinity_nml, iostat=io_stat)
109 write(iunit,nml=fms_affinity_nml)
111 module_is_initialized = .true.
119 character(len=*),
intent(in):: component
120 logical,
intent(in):: use_hyper_thread
121 integer,
intent(in):: nthreads
124 integer(c_int):: cpuset_sz
125 integer(c_int),
dimension(:),
allocatable:: cpu_set
126 integer(c_int):: retcode
129 character(len=32):: h_name
135 if (.not. affinity)
return
146 if (use_hyper_thread)
then
149 cpuset_sz = nthreads * 2
151 allocate (cpu_set(0:cpuset_sz-1))
155 if (retcode == -1)
then
156 call error_mesg(
'fms_affinity_set',trim(component)//
' cpu_set size > allocated storage',fatal)
157 elseif ( (retcode == cpuset_sz/2) .and. (retcode == nthreads) )
then
158 call error_mesg(
'fms_affinity_set',trim(component)//
' affinity assumes hyper-threading hardware disabled',note)
159 elseif (retcode < cpuset_sz)
then
160 call error_mesg(
'fms_affinity_set',trim(component)//
' cpu_set size smaller than expected',msg_type)
165 if (retcode == -1)
then
166 call error_mesg(
'fms_affinity_set',trim(component)//
': issue setting cpu affinity', fatal)
197 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.