# JK 2022

easyblock = 'ConfigureMake'
name = 'QuantumESPRESSO'
version = '7.0'

homepage = 'https://www.quantum-espresso.org'
description = """Quantum ESPRESSO  is an integrated suite of computer codes
for electronic-structure calculations and materials modeling at the nanoscale.
It is based on density-functional theory, plane waves, and pseudopotentials
(both norm-conserving and ultrasoft).
"""

toolchain = {'name': 'NVHPC', 'version': '21.9'}

import os
if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
   toolchainopts = {'pic': True,  'optarch': 'march=core-avx2'}
else:
   toolchainopts = {'pic': True}

if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
   prebuildopts = "echo %(builddir)s && while read i; do echo $i; sed 's|-xHost|-march=core-avx2|g' -i $i; done < <(grep xHost %(builddir)s -R | cut -d ':' -f 1 | sort -u) && "

source_urls = ['https://github.com/QEF/q-e/releases/download/qe-%(version)s/']
sources = ['qe-%(version)s-ReleasePack.tgz']
checksums = ['268ec506f88c56ba4e9b691c1e81e33a6ad7949f857f1c6c32197f9c2af2a957']  # qe 7.0 release pack

dependencies = [
#    ('ELPA', '2021.05.001', '', ('intel', '2021a')),
#    ('libxc', '5.1.3', '', ('GCC', '10.2.0')),
#    ('HDF5', '1.10.7', '', ('iimpi', '2021a')),
    ('OpenMPI', '4.0.7', '-CUDA-11.4.1'),
]

preconfigopts = " export MPIF90=mpif90 && "
preconfigopts += " export MPIFC=mpif90 && "
preconfigopts += " export MPIF77=mpif90 && "
preconfigopts += " export MPICC=mpicc && "
preconfigopts += " export MPICXX=mpicxx && "

configopts = 'FC=pgfortran F77=pgfortran F90=pgfortran CC=pgcc CXX=pgc++ --with-cuda=$CUDA_HOME --with-cuda-cc=80 --with-cuda-runtime=11.4 --enable-openmp'

prebuildopts = "sed -i 's/-D__MPI\\b/& -D__GPU_MPI /' %(builddir)s/qe-%(version)s/make.inc && "

# only pw is available for GPU
buildopts = 'pw'

# parallel build tends to fail
parallel = 1

skipsteps = ['sanitycheck']

moduleclass = 'chem'
