Skip to content

Commit af9e436

Browse files
committed
Clean up intelfftw.py logic
Instead of adding and then removing interface_lib/cluster_interface_lib, only add them if needed, so they don't need removing later. Also check for existence of mt libraries (longer list) to be more thorough.
1 parent 2d51b1c commit af9e436

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

easybuild/toolchains/fft/intelfftw.py

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def _set_fftw_variables(self):
4949
if not hasattr(self, 'BLAS_LIB_DIR'):
5050
raise EasyBuildError("_set_fftw_variables: IntelFFT based on IntelMKL (no BLAS_LIB_DIR found)")
5151

52+
imklroot = get_software_root(self.FFT_MODULE_NAME[0])
5253
imklver = get_software_version(self.FFT_MODULE_NAME[0])
54+
self.FFT_LIB_DIR = self.BLAS_LIB_DIR
55+
self.FFT_INCLUDE_DIR = [os.path.join(d, 'fftw') for d in self.BLAS_INCLUDE_DIR]
5356

5457
picsuff = ''
5558
if self.options.get('pic', None):
@@ -69,56 +72,47 @@ def _set_fftw_variables(self):
6972
raise EasyBuildError(error_msg)
7073

7174
interface_lib = "fftw3xc%s%s" % (compsuff, picsuff)
72-
fftw_libs = [interface_lib]
73-
cluster_interface_lib = None
75+
fft_lib_dirs = [os.path.join(imklroot, d) for d in self.FFT_LIB_DIR]
76+
77+
def fftw_lib_exists(libname):
78+
"""Helper function to check whether FFTW library with specified name exists."""
79+
return any(os.path.exists(os.path.join(d, "lib%s.a" % libname)) for d in fft_lib_dirs)
80+
81+
# interface libs can be optional:
82+
# MKL >= 10.2 include fftw3xc and fftw3xf interfaces in LIBBLAS=libmkl_gf/libmkl_intel
83+
# See https://software.intel.com/en-us/articles/intel-mkl-main-libraries-contain-fftw3-interfaces
84+
# The cluster interface libs (libfftw3x_cdft*) can be omitted if the toolchain does not provide MPI-FFTW
85+
# interfaces.
86+
fftw_libs = []
87+
if fftw_lib_exists(interface_lib) or LooseVersion(imklver) < LooseVersion("10.2"):
88+
fftw_libs = [interface_lib]
89+
7490
if self.options.get('usempi', False):
7591
# add cluster interface for recent imkl versions
76-
if LooseVersion(imklver) >= LooseVersion('10.3'):
92+
# only get cluster_interface_lib from seperate module imkl-FFTW, rest via libmkl_gf/libmkl_intel
93+
imklfftwroot = get_software_root('imkl-FFTW')
94+
if LooseVersion(imklver) >= LooseVersion('10.3') and (fftw_libs or imklfftwroot):
7795
suff = picsuff
7896
if LooseVersion(imklver) >= LooseVersion('11.0.2'):
7997
suff = bitsuff + suff
8098
cluster_interface_lib = 'fftw3x_cdft%s' % suff
8199
fftw_libs.append(cluster_interface_lib)
82100
fftw_libs.append("mkl_cdft_core") # add cluster dft
83101
fftw_libs.extend(self.variables['LIBBLACS'].flatten()) # add BLACS; use flatten because ListOfList
84-
85-
fftw_mt_libs = fftw_libs + [x % self.BLAS_LIB_MAP for x in self.BLAS_LIB_MT]
102+
if imklfftwroot:
103+
fft_lib_dirs += [os.path.join(imklfftwroot, 'lib')]
104+
self.FFT_LIB_DIR = [os.path.join(imklfftwroot, 'lib')]
86105

87106
self.log.debug('fftw_libs %s' % fftw_libs.__repr__())
88107
fftw_libs.extend(self.variables['LIBBLAS'].flatten()) # add BLAS libs (contains dft)
89108
self.log.debug('fftw_libs %s' % fftw_libs.__repr__())
90109

91-
self.FFT_LIB_DIR = self.BLAS_LIB_DIR
92-
self.FFT_INCLUDE_DIR = [os.path.join(d, 'fftw') for d in self.BLAS_INCLUDE_DIR]
93-
94110
# building the FFTW interfaces is optional,
95111
# so make sure libraries are there before FFT_LIB is set
96-
imklroot = get_software_root(self.FFT_MODULE_NAME[0])
97-
fft_lib_dirs = [os.path.join(imklroot, d) for d in self.FFT_LIB_DIR]
98-
imklfftwroot = get_software_root('imkl-FFTW')
99-
if imklfftwroot:
100-
# only get cluster_interface_lib from seperate module imkl-FFTW, rest via libmkl_gf/libmkl_intel
101-
if self.options.get('usempi', False):
102-
fft_lib_dirs += [os.path.join(imklfftwroot, 'lib')]
103-
self.FFT_LIB_DIR = [os.path.join(imklfftwroot, 'lib')]
104-
fftw_libs.remove(interface_lib)
105-
fftw_mt_libs.remove(interface_lib)
106-
107-
def fftw_lib_exists(libname):
108-
"""Helper function to check whether FFTW library with specified name exists."""
109-
return any(os.path.exists(os.path.join(d, "lib%s.a" % libname)) for d in fft_lib_dirs)
110-
111-
if not fftw_lib_exists(interface_lib) and LooseVersion(imklver) >= LooseVersion("10.2"):
112-
# interface libs can be optional:
113-
# MKL >= 10.2 include fftw3xc and fftw3xf interfaces in LIBBLAS=libmkl_gf/libmkl_intel
114-
# See https://software.intel.com/en-us/articles/intel-mkl-main-libraries-contain-fftw3-interfaces
115-
# The cluster interface libs (libfftw3x_cdft*) can be omitted if the toolchain does not provide MPI-FFTW
116-
# interfaces.
117-
fftw_libs = [lib for lib in fftw_libs if lib not in [interface_lib, cluster_interface_lib]]
118-
fftw_mt_libs = [lib for lib in fftw_mt_libs if lib not in [interface_lib, cluster_interface_lib]]
112+
fftw_mt_libs = fftw_libs + [x % self.BLAS_LIB_MAP for x in self.BLAS_LIB_MT]
119113

120114
# filter out libraries from list of FFTW libraries to check for if they are not provided by Intel MKL
121-
check_fftw_libs = [lib for lib in fftw_libs if lib not in ['dl', 'gfortran']]
115+
check_fftw_libs = [lib for lib in fftw_mt_libs if lib not in ['dl', 'gfortran']]
122116

123117
missing_fftw_libs = [lib for lib in check_fftw_libs if not fftw_lib_exists(lib)]
124118
if missing_fftw_libs:
@@ -129,6 +123,6 @@ def fftw_lib_exists(libname):
129123
else:
130124
raise EasyBuildError(msg)
131125
else:
132-
self.FFT_LIB = fftw_libs
126+
self.FFT_LIB_MT = fftw_mt_libs
133127

134-
self.FFT_LIB_MT = fftw_mt_libs
128+
self.FFT_LIB = fftw_libs

0 commit comments

Comments
 (0)