Skip to content

Commit af140b3

Browse files
authored
Merge pull request #4011 from ComputeCanada/fftw-mpi
set $FFT(W)_LIB_DIR to imkl-FFTW's lib path in build environment if usempi toolchain option is enabled
2 parents 17cb1d4 + 6ebf8f6 commit af140b3

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

easybuild/toolchains/fft/intelfftw.py

Lines changed: 26 additions & 31 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,54 +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
102+
if imklfftwroot:
103+
fft_lib_dirs += [os.path.join(imklfftwroot, 'lib')]
104+
self.FFT_LIB_DIR = [os.path.join(imklfftwroot, 'lib')]
84105

85106
fftw_mt_libs = fftw_libs + [x % self.BLAS_LIB_MAP for x in self.BLAS_LIB_MT]
86107

87108
self.log.debug('fftw_libs %s' % fftw_libs.__repr__())
88109
fftw_libs.extend(self.variables['LIBBLAS'].flatten()) # add BLAS libs (contains dft)
89110
self.log.debug('fftw_libs %s' % fftw_libs.__repr__())
90111

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-
94112
# building the FFTW interfaces is optional,
95113
# 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-
fft_lib_dirs += [os.path.join(imklfftwroot, 'lib')]
102-
fftw_libs.remove(interface_lib)
103-
fftw_mt_libs.remove(interface_lib)
104-
105-
def fftw_lib_exists(libname):
106-
"""Helper function to check whether FFTW library with specified name exists."""
107-
return any(os.path.exists(os.path.join(d, "lib%s.a" % libname)) for d in fft_lib_dirs)
108-
109-
if not fftw_lib_exists(interface_lib) and LooseVersion(imklver) >= LooseVersion("10.2"):
110-
# interface libs can be optional:
111-
# MKL >= 10.2 include fftw3xc and fftw3xf interfaces in LIBBLAS=libmkl_gf/libmkl_intel
112-
# See https://software.intel.com/en-us/articles/intel-mkl-main-libraries-contain-fftw3-interfaces
113-
# The cluster interface libs (libfftw3x_cdft*) can be omitted if the toolchain does not provide MPI-FFTW
114-
# interfaces.
115-
fftw_libs = [lib for lib in fftw_libs if lib not in [interface_lib, cluster_interface_lib]]
116-
fftw_mt_libs = [lib for lib in fftw_mt_libs if lib not in [interface_lib, cluster_interface_lib]]
117-
118114
# filter out libraries from list of FFTW libraries to check for if they are not provided by Intel MKL
119-
check_fftw_libs = [lib for lib in fftw_libs if lib not in ['dl', 'gfortran']]
115+
check_fftw_libs = [lib for lib in fftw_libs + fftw_mt_libs if lib not in ['dl', 'gfortran']]
120116

121117
missing_fftw_libs = [lib for lib in check_fftw_libs if not fftw_lib_exists(lib)]
122118
if missing_fftw_libs:
@@ -128,5 +124,4 @@ def fftw_lib_exists(libname):
128124
raise EasyBuildError(msg)
129125
else:
130126
self.FFT_LIB = fftw_libs
131-
132-
self.FFT_LIB_MT = fftw_mt_libs
127+
self.FFT_LIB_MT = fftw_mt_libs

test/framework/toolchain.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,9 @@ def test_fft_env_vars_intel(self):
11151115
self.assertEqual(tc.get_variable('LIBFFT'), libfft)
11161116
self.assertEqual(tc.get_variable('LIBFFT_MT'), libfft_mt)
11171117

1118+
fft_lib_dir = os.path.join(modules.get_software_root('imkl'), 'mkl/2021.4.0/lib/intel64')
1119+
self.assertEqual(tc.get_variable('FFT_LIB_DIR'), fft_lib_dir)
1120+
11181121
tc = self.get_toolchain('intel', version='2021b')
11191122
tc.set_options({'usempi': True})
11201123
tc.prepare()
@@ -1138,6 +1141,9 @@ def test_fft_env_vars_intel(self):
11381141
libfft_mt += '-Wl,-Bdynamic -liomp5 -lpthread'
11391142
self.assertEqual(tc.get_variable('LIBFFT_MT'), libfft_mt)
11401143

1144+
fft_lib_dir = os.path.join(modules.get_software_root('imkl-FFTW'), 'lib')
1145+
self.assertEqual(tc.get_variable('FFT_LIB_DIR'), fft_lib_dir)
1146+
11411147
def test_fosscuda(self):
11421148
"""Test whether fosscuda is handled properly."""
11431149
tc = self.get_toolchain("fosscuda", version="2018a")
@@ -1185,6 +1191,7 @@ def setup_sandbox_for_intel_fftw(self, moddir, imklver='2018.1.163'):
11851191

11861192
mkl_libs = ['mkl_cdft_core', 'mkl_blacs_intelmpi_lp64']
11871193
mkl_libs += ['mkl_intel_lp64', 'mkl_sequential', 'mkl_core', 'mkl_intel_ilp64']
1194+
mkl_libs += ['mkl_intel_thread', 'mkl_pgi_thread']
11881195
fftw_libs = ['fftw3xc_intel', 'fftw3xc_pgi']
11891196
if LooseVersion(imklver) >= LooseVersion('11'):
11901197
fftw_libs.extend(['fftw3x_cdft_ilp64', 'fftw3x_cdft_lp64'])

0 commit comments

Comments
 (0)