nixos/local/pkgs/vasp/intel/default.nix

117 lines
3.8 KiB
Nix
Raw Normal View History

2024-02-25 17:40:43 +08:00
{
2024-03-23 13:27:10 +08:00
buildFHSEnv, writeScript, stdenvNoCC, requireFile, substituteAll, symlinkJoin, writeTextDir,
2024-03-16 14:47:52 +08:00
config, oneapiArch ? config.oneapiArch or "SSE3", additionalCommands ? "",
2024-03-23 13:27:10 +08:00
oneapi, gcc, glibc, lmod, rsync, which, wannier90, binutils, hdf5, coreutils, slurm, zlib
2024-02-25 17:40:43 +08:00
}:
let
2024-03-12 15:16:54 +08:00
sources = import ../source.nix { inherit requireFile; };
2024-02-25 17:40:43 +08:00
buildEnv = buildFHSEnv
{
name = "buildEnv";
# make "module load mpi" success
2024-03-23 13:27:10 +08:00
targetPkgs = _: [ zlib (writeTextDir "etc/release" "") gccFull ];
2024-02-25 17:40:43 +08:00
};
buildScript = writeScript "build"
''
. ${lmod}/share/lmod/lmod/init/bash
module use ${oneapi}/share/intel/modulefiles
module load tbb compiler-rt oclfpga # dependencies
module load mpi mkl compiler
mkdir -p bin
2024-03-12 15:16:54 +08:00
make DEPS=1 -j$NIX_BUILD_CORES
2024-02-25 17:40:43 +08:00
'';
include = version: substituteAll
{
src = ./makefile.include-${version};
inherit oneapiArch;
};
2024-03-12 15:16:54 +08:00
gccFull = symlinkJoin { name = "gcc"; paths = [ gcc gcc.cc gcc.cc.lib glibc.dev binutils.bintools ]; };
2024-02-25 17:40:43 +08:00
vasp = version: stdenvNoCC.mkDerivation rec
{
2024-03-12 18:44:22 +08:00
pname = "vasp-intel";
2024-02-25 17:40:43 +08:00
inherit version;
2024-03-12 15:16:54 +08:00
src = sources.${version};
2024-02-25 17:40:43 +08:00
configurePhase =
''
cp ${include version} makefile.include
cp ${../constr_cell_relax.F} src/constr_cell_relax.F
'';
2024-03-12 15:16:54 +08:00
nativeBuildInputs = [ rsync which ];
2024-03-12 18:44:22 +08:00
HDF5_ROOT = hdf5;
2024-02-25 17:40:43 +08:00
WANNIER90_ROOT = wannier90;
buildPhase = "${buildEnv}/bin/buildEnv ${buildScript}";
installPhase =
''
mkdir -p $out/bin
for i in std gam ncl; do cp bin/vasp_$i $out/bin/vasp-$i; done
'';
2024-03-13 12:05:00 +08:00
dontFixup = true;
2024-03-12 18:44:22 +08:00
requiredSystemFeatures = [ "gccarch-exact-${stdenvNoCC.hostPlatform.gcc.arch}" "big-parallel" ];
2024-02-25 17:40:43 +08:00
};
startScript = version: writeScript "vasp-intel-${version}"
''
. ${lmod}/share/lmod/lmod/init/bash
module use ${oneapi}/share/intel/modulefiles
module load tbb compiler-rt oclfpga # dependencies
module load mpi mkl compiler
2024-03-12 23:57:59 +08:00
2024-03-23 13:27:10 +08:00
# if OMP_NUM_THREADS is not set, set it according to SLURM_CPUS_PER_TASK or to 1
if [ -z "''${OMP_NUM_THREADS-}" ]; then
if [ -n "''${SLURM_CPUS_PER_TASK-}" ]; then
OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
else
OMP_NUM_THREADS=1
fi
2024-03-12 23:57:59 +08:00
fi
2024-03-23 13:27:10 +08:00
export OMP_NUM_THREADS
# if I_MPI_PIN_PROCESSOR_LIST is not set and SLURM_JOB_ID is not set, set it to allcores
if [ -z "''${I_MPI_PIN_PROCESSOR_LIST-}" ] && [ -z "''${SLURM_JOB_ID-}" ]; then
I_MPI_PIN_PROCESSOR_LIST=allcores
fi
export I_MPI_PIN_PROCESSOR_LIST
# if I_MPI_PMI_LIBRARY is not set and SLURM_JOB_ID is set, set it to libpmi2.so
if [ -z "''${I_MPI_PMI_LIBRARY-}" ] && [ -n "''${SLURM_JOB_ID-}" ]; then
I_MPI_PMI_LIBRARY=${slurm}/lib/libpmi2.so
fi
export I_MPI_PMI_LIBRARY
# set I_MPI_PIN I_MPI_PIN_DOMAIN I_MPI_DEBUG if not set
export I_MPI_PIN=''${I_MPI_PIN-yes}
export I_MPI_PIN_DOMAIN=''${I_MPI_PIN_DOMAIN-omp}
export I_MPI_DEBUG=''${I_MPI_DEBUG-4}
2024-03-13 12:05:00 +08:00
2024-03-16 14:47:52 +08:00
${additionalCommands}
2024-03-23 13:27:10 +08:00
# guess command we want to run
variant=$(${coreutils}/bin/basename $0 | ${coreutils}/bin/cut -d- -f4)
if [ -z "$variant" ]; then
variant=std
fi
if [ "$variant" = "env" ]; then
exec "$@"
else if [ -n "''${SLURM_JOB_ID-}" ]; then
# srun should be in PATH
exec srun --mpi=pmi2 ${vasp version}/bin/vasp-$variant
else
exec mpirun -n 1 ${vasp version}/bin/vasp-$variant
fi
2024-02-26 19:34:40 +08:00
exec "$@"
2024-02-25 17:40:43 +08:00
'';
2024-03-23 13:27:10 +08:00
runEnv = version: let shortVersion = builtins.replaceStrings ["."] [""] version; in buildFHSEnv
2024-02-25 17:40:43 +08:00
{
2024-03-23 13:27:10 +08:00
name = "vasp-intel-${shortVersion}";
targetPkgs = _: [ zlib (vasp version) (writeTextDir "etc/release" "") gccFull ];
2024-02-25 17:40:43 +08:00
runScript = startScript version;
2024-03-13 15:58:20 +08:00
extraInstallCommands =
2024-03-23 13:27:10 +08:00
''
pushd $out/bin
for i in std gam ncl env; do ln -s vasp-intel-${shortVersion} vasp-intel-${shortVersion}-$i; done
popd
'';
2024-02-25 17:40:43 +08:00
};
2024-03-12 15:16:54 +08:00
in builtins.mapAttrs (version: _: runEnv version) sources