##
# This file is an EasyBuild reciPY as per https://github.com/easybuilders/easybuild
#
# Authors::   Inge Gutheil <i.gutheil@fz-juelich.de>, Alan O'Cais <a.ocais@fz-juelich.de>
# License::   MIT/GPL
#
##

name = 'ELPA'
version = '2023.11.001'

homepage = 'https://elpa.mpcdf.mpg.de/'
description = """Eigenvalue SoLvers for Petaflop-Applications."""

toolchain = {'name': 'intel', 'version': '2023b'}
import os
if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
   toolchainopts = {'usempi': True, 'openmp': True,  'optarch': 'march=core-avx2'}
else:
   toolchainopts = {'usempi': True, 'openmp': True}


source_urls = ['https://gitlab.mpcdf.mpg.de/elpa/elpa/-/archive/new_release_%(version)s/']
sources = ['elpa-new_release_%(version)s.tar.gz']
patches = [
    '%(name)s-2023.05.001_fix_hardcoded_perl_path.patch',
    '%(name)s-2023.05.001_fix_AVX512_support.patch',
]
checksums = [
    {'%(namelower)s-new_release_%(version)s.tar.gz':
     'b8dd04e238dac23c1e910e8862370b1779b239eae4b871c9966bee578d40c750'},
    {'%(name)s-2023.05.001_fix_hardcoded_perl_path.patch':
     '0548105065777a2ed07dde306636251c4f96e555a801647564de37d1ddd7b0b5'},
    {'%(name)s-2023.05.001_fix_AVX512_support.patch':
     'ecf08b64fe1da432a218040fa45d4ecfbb3269d58cb018b12da5a2d854bf96be'},
]

builddependencies = [
    ('Autotools', '20220317'),
    # remove_xcompiler script requires 'python' command,
    ('Python', '3.11.5'),
    ('Perl', '5.38.0'),
]

preconfigopts = './autogen.sh && '
preconfigopts += 'export LDFLAGS="-lm $LDFLAGS" && '
preconfigopts += 'autoreconf && '
# If the build is running in a batch job, make sure Intel libmpi does
# not try to use Slurm to run the MPI_THREAD test code that ELPA's
# configure is running without "mpirun".
preconfigopts += 'unset SLURM_JOBID && unset SLURM_NODELIST && unset I_MPI_PMI_LIBRARY && '

configopts = '--without-threading-support-check-during-build '

# When building in parallel, the file test_setup_mpi.mod is sometimes
# used before it is built, leading to an error.  This must be a bug in
# the makefile affecting parallel builds.
maxparallel = 1

moduleclass = 'math'
