From 93cd0215bd28e20df3c044db4036780839528b4e Mon Sep 17 00:00:00 2001 From: edoapra Date: Tue, 3 Mar 2026 16:33:47 -0800 Subject: [PATCH] use hwloc to get no. hw cores to set max threads --- src/util/util_maxthreads.F | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/util/util_maxthreads.F b/src/util/util_maxthreads.F index da3bd90d56..79fa804084 100644 --- a/src/util/util_maxthreads.F +++ b/src/util/util_maxthreads.F @@ -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