use hwloc to get no. hw cores to set max threads

This commit is contained in:
edoapra 2026-03-03 16:33:47 -08:00
parent 0d5a8afda6
commit 93cd0215bd
No known key found for this signature in database
GPG key ID: 33F48038CA2EB0AD

View file

@ -1,17 +1,30 @@
subroutine util_setmaxthreads()
c
c sets the number of openmp threads as
c number of hw cores / no. of process per node
c
implicit none
#include "global.fh"
#include "stdio.fh"
integer ncpus,util_getncpus,max_thr,ppn
external util_getncpus
character*255 env_out
integer err8
c
ncpus=util_getncpus()
if(ncpus.ne.0) then
call util_getppn(ppn)
max_thr=ncpus/ppn
if(ga_nodeid().eq.0)write(luout,*) ' ### ncpus max_thr',
N ncpus,max_thr
call omp_set_num_threads(max_thr)
c skip if OMP_NUM_THREADS is set
c
call get_environment_variable(
A "OMP_NUM_THREADS", value=env_out, status=err8)
if(err8.ne.0) then
ncpus=util_getncpus()
if(ncpus.ne.0) then
call util_getppn(ppn)
max_thr=ncpus/ppn
if(ga_nodeid().eq.0)write(luout,97)
N ncpus,max_thr
call omp_set_num_threads(max_thr)
endif
endif
97 format(2x,'NWChem w/ OpenMP: # of HW cores = ',i4,
F /2x,'NWChem w/ OpenMP: nprocs/node = ',i4)
return
end