From fe7a5ba5d258e3fc2ef48f150915a2d79ecfae97 Mon Sep 17 00:00:00 2001 From: "Igor S. Gerasimov" <> Date: Mon, 16 May 2022 15:33:10 +0900 Subject: [PATCH] OpenMP and MKL initialization --- Makefile | 4 ++-- Multiwfn.f90 | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 33b2243..daaa8b3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SIMD = -msse3 -OPT = -O2 -qopenmp -qopenmp-link=static -threads -qopt-matmul $(SIMD) -diag-disable 8290,8291,6371,10316 -fpp -mkl -static-intel -OPT1 = -O1 -qopenmp -qopenmp-link=static -threads $(SIMD) -diag-disable 8290,8291,6371,10316 -fpp -mkl -static-intel +OPT = -O2 -qopenmp -qopenmp-link=static -threads -qopt-matmul $(SIMD) -diag-disable 8290,8291,6371,10316 -fpp -mkl -DINTEL_MKL -static-intel +OPT1 = -O1 -qopenmp -qopenmp-link=static -threads $(SIMD) -diag-disable 8290,8291,6371,10316 -fpp -mkl -DINTEL_MKL -static-intel #Options in the next line is for debugging purpose #OPTDBG = -O0 -qopenmp -diag-disable 8290,8291,6371 -threads -qopenmp-link=static -debug all -g -traceback -check all -fstack-protector -fpp -mkl -static-intel diff --git a/Multiwfn.f90 b/Multiwfn.f90 index b1737fc..5d77558 100644 --- a/Multiwfn.f90 +++ b/Multiwfn.f90 @@ -10,7 +10,9 @@ real*8,allocatable :: tmparr(:),tmparr2(:),tmpmat(:,:),tmpmat2(:,:),tmpmat3D(:,: integer,allocatable :: tmparri(:),tmparr2i(:),tmpmati(:,:),tmpmat2i(:,:) real*8 tmpv1(3),tmpv2(3) +#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER) call kmp_set_warnings_off() !In rare case, "Cannot open message catalog "1041\libiomp5ui.dll"" may occurs, this calling avoid this problem, or user should set KMP_WARNINGS environment variable to 0 +#endif !Try to get input file name from argument, which should be the first argument filename=" " @@ -40,15 +42,25 @@ call date_and_time(nowdate,nowtime) write(*,"(/,' ( Number of parallel threads:',i4,' Current date: ',a,'-',a,'-',a,' Time: ',a,':',a,':',a,' )')") & nthreads,nowdate(1:4),nowdate(5:6),nowdate(7:8),nowtime(1:2),nowtime(3:4),nowtime(5:6) -!For Linux/MacOS version, it seems the only way to set stacksize of each thread is to define KMP_STACKSIZE environment variable -if (isys==1) then !Set via ompstacksize in settings.ini +!For general non-compiler spicified Windows/Linux/MacOS version, it seems the only way to set stacksize of each thread is to define OMP_STACKSIZE environment variable +if (isys==1) then +#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER) + ! Intel OpenMP runtime can re-set OpenMP stacksize via internal call before running any OpenMP sections. + !Set via ompstacksize in settings.ini call KMP_SET_STACKSIZE_S(ompstacksize) -else if (isys==2) then !The size should have been defined by KMP_STACKSIZE - CALL getenv('KMP_STACKSIZE',c200tmp) - if (c200tmp==" ") write(*,"(/,a)") " Warning: You should set ""KMP_STACKSIZE"" environment variable as mentioned in Section 2.1.2 of Multiwfn manual!" +#else + ! Other compilers may use Intel OpenMP runtime somehow, but I (Igor S. Gerasimov) do not know how to link it, so use the way, similar to Linux + CALL get_environment_variable('OMP_STACKSIZE',c200tmp) + if (c200tmp==" ") write(*,"(/,a)") " Warning: You should set ""OMP_STACKSIZE"" environment variable as mentioned in Section 2.1.2 of Multiwfn manual!" +#endif +else if (isys==2) then !The size should have been defined by OMP_STACKSIZE + CALL get_environment_variable('OMP_STACKSIZE',c200tmp) + if (c200tmp==" ") write(*,"(/,a)") " Warning: You should set ""OMP_STACKSIZE"" environment variable as mentioned in Section 2.1.2 of Multiwfn manual!" end if !write(*,"(' OpenMP stacksize for each thread: ',f10.2,' MB')") dfloat(KMP_GET_STACKSIZE_S())/1024/1024 +#if defined(INTEL_MKL) call mkl_set_num_threads(nthreads) !Use this to set number of cores used in MKL library (e.g. function matmul_blas) +#endif !!-------- Load input file write(*,*) -- 2.25.1