diff --git a/docs/man/crest.adoc b/docs/man/crest.adoc index b59a4d1b..0e7a4ddb 100644 --- a/docs/man/crest.adoc +++ b/docs/man/crest.adoc @@ -89,6 +89,10 @@ If no such file is present as the first argument **crest** will automatically se Parallel settings are then determined automatically for each step. If not set by "`**-T**`", this number is read from the **OMP_NUM_THREADS** global variable. +*-TMD* _int_:: + Override the total number of CPUs (threads) to be used for MD/MTD sampling. + Other workflow steps continue to use the global **-T** thread budget. + === Calculation options *-g* _string_:: diff --git a/src/algos/parallel.f90 b/src/algos/parallel.f90 index 9d0e79ae..2b80ccc5 100644 --- a/src/algos/parallel.f90 +++ b/src/algos/parallel.f90 @@ -436,10 +436,11 @@ subroutine crest_search_multimd(env,mol,mddats,nsim) type(coord),allocatable :: moltmps(:) integer :: i,j,io,ich logical :: pr,ex,nested - integer :: T,Tn + integer :: T,Tn,Trestore,Tnrestore,thread_save real(wp) :: percent character(len=80) :: atmp character(len=*),parameter :: mdir = 'MDFILES' + logical :: use_tmd_threads type(calcdata),allocatable :: calculations(:) integer :: vz,job,thread_id @@ -463,6 +464,9 @@ subroutine crest_search_multimd(env,mol,mddats,nsim) end if !>--- prepare calculation containers for parallelization (one per thread) + use_tmd_threads = env%threadsmdsetmanual.and.env%ThreadsMD > 0 + thread_save = env%Threads + if (use_tmd_threads) env%Threads = env%ThreadsMD call new_ompautoset(env,'auto_nested',nsim,T,Tn) nested = env%omp_allow_nested @@ -538,6 +542,10 @@ subroutine crest_search_multimd(env,mol,mddats,nsim) call profiler%clear() deallocate (calculations) if (allocated(moltmps)) deallocate (moltmps) + if (use_tmd_threads) then + env%Threads = thread_save + call new_ompautoset(env,'max',0,Trestore,Tnrestore) + end if return contains subroutine collect(n,mddats) @@ -744,10 +752,11 @@ subroutine crest_search_multimd2(env,mols,mddats,nsim) type(coord),allocatable :: moltmps(:) integer :: i,j,io,ich logical :: pr,ex,nested - integer :: T,Tn + integer :: T,Tn,Trestore,Tnrestore,thread_save real(wp) :: percent character(len=80) :: atmp character(len=*),parameter :: mdir = 'MDFILES' + logical :: use_tmd_threads type(calcdata),allocatable :: calculations(:) integer :: vz,job,thread_id @@ -769,6 +778,9 @@ subroutine crest_search_multimd2(env,mols,mddats,nsim) end if !>--- prepare calculation objects for parallelization (one per thread) + use_tmd_threads = env%threadsmdsetmanual.and.env%ThreadsMD > 0 + thread_save = env%Threads + if (use_tmd_threads) env%Threads = env%ThreadsMD call new_ompautoset(env,'auto_nested',nsim,T,Tn) nested = env%omp_allow_nested @@ -837,6 +849,10 @@ subroutine crest_search_multimd2(env,mols,mddats,nsim) call profiler%clear() deallocate (calculations) if (allocated(moltmps)) deallocate (moltmps) + if (use_tmd_threads) then + env%Threads = thread_save + call new_ompautoset(env,'max',0,Trestore,Tnrestore) + end if return contains subroutine collect(n,mddats) diff --git a/src/algos/search_conformers.f90 b/src/algos/search_conformers.f90 index 9dc00042..9874f837 100644 --- a/src/algos/search_conformers.f90 +++ b/src/algos/search_conformers.f90 @@ -109,6 +109,7 @@ subroutine crest_search_imtdgc(env,tim) write(stdout,'(1x,a,i0)') 'Meta-Dynamics Iteration ',i write(stdout,'(1x,a)') '------------------------------' + call env%ref%to(mol) nsim = -1 !>--- enambles automatic MTD setup in init routines call crest_search_multimd_init(env,mol,mddat,nsim) allocate (mddats(nsim), source=mddat) @@ -620,4 +621,3 @@ subroutine crest_newcross3(env) end do end subroutine crest_newcross3 - diff --git a/src/algos/search_entropy.f90 b/src/algos/search_entropy.f90 index 028b81bc..2e1853f9 100644 --- a/src/algos/search_entropy.f90 +++ b/src/algos/search_entropy.f90 @@ -116,6 +116,7 @@ subroutine crest_search_entropy(env,tim) write (stdout,'(1x,a,i0)') 'Meta-Dynamics Iteration ',i write (stdout,'(1x,a)') '------------------------------' + call env%ref%to(mol) nsim = -1 !>--- enambles automatic MTD setup in init routines call crest_search_multimd_init(env,mol,mddat,nsim) allocate (mddats(nsim),source=mddat) @@ -478,4 +479,3 @@ subroutine crest_init_multimd_smtd(env,mddats,nsim,biasfile) deallocate (eread,at,xyz) return end subroutine crest_init_multimd_smtd - diff --git a/src/classes.f90 b/src/classes.f90 index 337fcb43..68311a61 100644 --- a/src/classes.f90 +++ b/src/classes.f90 @@ -340,6 +340,7 @@ module crest_data integer :: MAXRUN = 1 !> number of cores per job integer :: omp = 1 !> OMP/MKL_NUM_THREADS integer :: Threads = 1 !> Total number of threads (=omp*MAXRUN) + integer :: ThreadsMD = 0 !> Optional total thread budget for MD/MTD only logical :: omp_allow_nested = .true. !> allow nested OpenMP threadding !>--- various names and flags @@ -569,6 +570,7 @@ module crest_data logical :: subRMSD !> include only the selected substructure into the CREGEN RMSD logical :: superquick !> very crude quick-run option logical :: threadssetmanual !> are #CPUs set with the '-T' flag ? + logical :: threadsmdsetmanual !> are #CPUs for MD/MTD set with '-TMD'? logical :: trackorigin !> track the origin of a conformation? logical :: testnumgrad = .false. !> test numerical gradient in singlepoint logical :: use_xtbiff = .false. !> use xtbiff for QCG? diff --git a/src/confparse.f90 b/src/confparse.f90 index 92d9a9d0..e84ae62a 100644 --- a/src/confparse.f90 +++ b/src/confparse.f90 @@ -126,8 +126,10 @@ subroutine parseflags(env,arg,nra) env%Threads = 1 !> total number of threads env%MAXRUN = 1 !> number of parallel xtb jobs env%omp = 1 !> # of OMP_NUM_THREADS and MKL_NUMTHREADS to be used + env%ThreadsMD = 0 !> optional total number of threads for MD/MTD env%autothreads = .true. !> automatically determine optimal parameters omp and MAXRUN env%threadssetmanual = .false. !> did the user set the #threads manually? + env%threadsmdsetmanual = .false. !> did the user set the #threads for MD/MTD manually? env%scratch = .false. !> use scratch directory? call getcwd(env%homedir) !> original directory @@ -1447,6 +1449,13 @@ subroutine parseflags(env,arg,nra) env%threadssetmanual = .true. write (*,'(2x,a,1x,i0,1x,a)') trim(arg(i)),nint(xx(1)), & & '(CPUs/Threads selected)' + case ('-TMD','-tmd') !> set total number of OMP threads for MD/MTD only + call readl(arg(i+1),xx,j) + if (index(arg(i+1),'-') .ne. 0) xx = 0d0 + env%ThreadsMD = nint(xx(1)) + env%threadsmdsetmanual = env%ThreadsMD > 0 + write (*,'(2x,a,1x,i0,1x,a)') trim(arg(i)),nint(xx(1)), & + & '(CPUs/Threads selected for MD/MTD)' case ('-inplace') !> activate "in-place" mode for optimizations (ON by default) env%inplaceMode = .true. !========================================================================================! diff --git a/src/legacy_algos/confscript2_misc.f90 b/src/legacy_algos/confscript2_misc.f90 index 3a8bffc0..a8bbec6f 100644 --- a/src/legacy_algos/confscript2_misc.f90 +++ b/src/legacy_algos/confscript2_misc.f90 @@ -303,14 +303,17 @@ subroutine MetaMD_para_OMP(env) type(systemdata) :: env - integer :: i,vz,T,Tn + integer :: i,vz,T,Tn,Trestore,Tnrestore,thread_save real(wp) :: time character(len=512) :: thispath,tmppath character(len=512) :: jobcall character(len=80) :: fname,pipe,atmp,btmp integer :: dum,io - logical :: ex + logical :: ex,use_tmd_threads + use_tmd_threads = env%threadsmdsetmanual.and.env%ThreadsMD > 0 + thread_save = env%Threads + if (use_tmd_threads) env%Threads = env%ThreadsMD call new_ompautoset(env,'auto',env%nmetadyn,T,Tn) time = env%mdtime !for some reason this is necessary @@ -382,6 +385,10 @@ subroutine MetaMD_para_OMP(env) if (.not.env%keepModef) then call cleanMTD end if + if (use_tmd_threads) then + env%Threads = thread_save + call new_ompautoset(env,'max',0,Trestore,Tnrestore) + end if end subroutine MetaMD_para_OMP diff --git a/src/printouts.f90 b/src/printouts.f90 index 7fce00bf..f7dc355d 100644 --- a/src/printouts.f90 +++ b/src/printouts.f90 @@ -151,6 +151,8 @@ subroutine confscript_morehelp(flag) write (*,'(5x,'' determined automatically for each step.'')') write (*,'(5x,'' If not set by "-T", this number is read'')') write (*,'(5x,'' from the OMP_NUM_THREADS global variable.'')') + write (*,'(5x,''-TMD : Override total CPUs(threads) for MD/MTD only'')') + write (*,'(5x,'' while keeping "-T" for other workflow steps.'')') write (*,'(5x,''-g : use GBSA implicit solvent'')') write (*,'(5x,'' for solvent '')') write (*,'(5x,''-alpb : use ALPB implicit solvent'')') @@ -929,6 +931,9 @@ subroutine crest_dry(env) write (*,'(/,1x,a)') 'Technical settings' write (*,'(2x,a,a)') 'working directory : ',trim(dumstr) write (*,'(2x,a,i0)') 'CPUs (threads) (-T) : ',env%threads + if (env%threadsmdsetmanual) then + write (*,'(2x,a,i0)') 'CPUs for MD/MTD (-TMD) : ',env%ThreadsMD + end if end if