From f921bcbe0b01f63acfc692f9b6cc6751ffc1fbd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiziano=20M=C3=BCller?= Date: Mon, 26 Oct 2020 16:32:15 +0100 Subject: [PATCH] cp2k, libxc, libint: fix builds with %intel, resp. intel-parallel-studio+mkl (#19522) * cp2k: locate correct include dir when using intel-parallel-studio+mkl for fftw-api * libxc: drop arch-specific intel opt. flags fixes #17794 * libint: drop arch-specific intel opt. flags, always build Fortran example with FC fixes #17509 --- .../repos/builtin/packages/cp2k/package.py | 7 +++- .../repos/builtin/packages/libint/package.py | 20 +++++------ .../repos/builtin/packages/libxc/package.py | 35 +++++-------------- 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/var/spack/repos/builtin/packages/cp2k/package.py b/var/spack/repos/builtin/packages/cp2k/package.py index 9b0e3b69d7..1b248506da 100644 --- a/var/spack/repos/builtin/packages/cp2k/package.py +++ b/var/spack/repos/builtin/packages/cp2k/package.py @@ -193,7 +193,12 @@ def edit(self, spec, prefix): fftw_header_dir = fftw.headers.directories[0] + '/fftw' elif '^intel-parallel-studio+mkl' in spec: fftw = spec['intel-parallel-studio'] - fftw_header_dir = fftw.headers.directories[0] + '/fftw' + fftw_header_dir = '' + for incdir in [join_path(f, 'fftw') + for f in fftw.headers.directories]: + if os.path.exists(incdir): + fftw_header_dir = incdir + break optimization_flags = { 'gcc': [ diff --git a/var/spack/repos/builtin/packages/libint/package.py b/var/spack/repos/builtin/packages/libint/package.py index f7248f61ab..a3b39495f9 100644 --- a/var/spack/repos/builtin/packages/libint/package.py +++ b/var/spack/repos/builtin/packages/libint/package.py @@ -78,10 +78,10 @@ def autoreconf(self, spec, prefix): @property def optflags(self): flags = '-O2' - # Optimizations for the Intel compiler, suggested by CP2K - # See ../libxc/package.py for rationale and doc. - if '%intel' in self.spec: - flags += ' -xSSE4.2 -axAVX,CORE-AVX2 -ipo' + + # microarchitecture-specific optimization flags should be controlled + # by Spack, otherwise we may end up with contradictory or invalid flags + # see https://github.com/spack/spack/issues/17794 return flags @@ -99,18 +99,16 @@ def configure_args(self): config_args = ['--enable-shared'] - optflags = self.optflags - # Optimization flag names have changed in libint 2 if self.version < Version('2.0.0'): config_args.extend([ - '--with-cc-optflags={0}'.format(optflags), - '--with-cxx-optflags={0}'.format(optflags) + '--with-cc-optflags={0}'.format(self.optflags), + '--with-cxx-optflags={0}'.format(self.optflags) ]) else: config_args.extend([ - '--with-cxx-optflags={0}'.format(optflags), - '--with-cxxgen-optflags={0}'.format(optflags) + '--with-cxx-optflags={0}'.format(self.optflags), + '--with-cxxgen-optflags={0}'.format(self.optflags) ]) # Options required by CP2K, removed in libint 2 @@ -199,6 +197,6 @@ def install(self, spec, prefix): def patch(self): # Use Fortran compiler to link the Fortran example, not the C++ # compiler - if '+fortran' in self.spec and self.spec.satisfies('%nvhpc'): + if '+fortran' in self.spec: filter_file('$(CXX) $(CXXFLAGS)', '$(FC) $(FCFLAGS)', 'export/fortran/Makefile', string=True) diff --git a/var/spack/repos/builtin/packages/libxc/package.py b/var/spack/repos/builtin/packages/libxc/package.py index 178b6cbcde..f054bfa72c 100644 --- a/var/spack/repos/builtin/packages/libxc/package.py +++ b/var/spack/repos/builtin/packages/libxc/package.py @@ -64,37 +64,18 @@ def libs(self): ) def setup_build_environment(self, env): - optflags = '-O2' - if self.compiler.name == 'intel': - # Optimizations for the Intel compiler, suggested by CP2K - # - # Note that not every lowly login node has advanced CPUs: - # - # $ icc -xAVX -axCORE-AVX2 -ipo hello.c - # $ ./a.out - # Please verify that both the operating system and the \ - # processor support Intel(R) AVX instructions. - # - # NB: The same flags are applied in: - # - ../libint/package.py - # - # Related: - # - ../fftw/package.py variants: simd, fma - # - ../c-blosc/package.py variant: avx2 - # - ../r-rcppblaze/package.py AVX* in "info" but not in code? - # - ../openblas/package.py variants: cpu_target!?! - # - ../cp2k/package.py - # - # Documentation at: - # https://software.intel.com/en-us/cpp-compiler-18.0-developer-guide-and-reference-ax-qax - # - optflags += ' -xSSE4.2 -axAVX,CORE-AVX2 -ipo' - if which('xiar'): - env.set('AR', 'xiar') + # microarchitecture-specific optimization flags should be controlled + # by Spack, otherwise we may end up with contradictory or invalid flags + # see https://github.com/spack/spack/issues/17794 + # libxc on the other hand only sets the generic -O2 when it detects GCC + optflags = '-O2' env.append_flags('CFLAGS', optflags) env.append_flags('FCFLAGS', optflags) + if '%intel' in self.spec and which('xiar'): + env.set('AR', 'xiar') + if '+cuda' in self.spec: nvcc = self.spec['cuda'].prefix.bin.nvcc env.set('CCLD', '{0} -ccbin {1}'.format(nvcc, spack_cc))