bscpkgs/bsc/garlic/sbatch.nix

85 lines
1.8 KiB
Nix
Raw Normal View History

2020-08-01 00:47:33 +08:00
{
stdenv
2020-08-04 17:51:09 +08:00
, numactl
2020-08-01 00:47:33 +08:00
}:
{
app
2020-08-25 00:06:47 +08:00
, chdirPrefix ? "."
, nixPrefix ? ""
2020-08-01 00:47:33 +08:00
, argv ? ""
, binary ? "/bin/run"
, ntasks ? null
2020-08-19 00:28:30 +08:00
, ntasksPerNode ? null
2020-08-18 00:50:18 +08:00
, nodes ? null
2020-08-01 00:47:33 +08:00
, exclusive ? true # By default we run in exclusive mode
, qos ? null
2020-08-25 00:07:09 +08:00
, reservation ? null
2020-08-01 00:47:33 +08:00
, time ? null
, output ? "job_%j.out"
, error ? "job_%j.err"
, contiguous ? null
, extra ? null
}:
with stdenv.lib;
let
sbatchOpt = name: value: optionalString (value!=null)
"#SBATCH --${name}=${value}\n";
sbatchEnable = name: value: optionalString (value!=null)
"#SBATCH --${name}\n";
in
stdenv.mkDerivation rec {
name = "${app.name}-job";
preferLocalBuild = true;
src = ./.;
buildInputs = [ app ];
#SBATCH --tasks-per-node=48
#SBATCH --ntasks-per-socket=24
#SBATCH --cpus-per-task=1
dontBuild = true;
dontPatchShebangs = true;
2020-08-01 00:47:33 +08:00
installPhase = ''
2020-08-05 00:38:33 +08:00
mkdir -p $out
cat > $out/job <<EOF
#!/bin/sh
2020-08-01 00:47:33 +08:00
#SBATCH --job-name="${name}"
''
+ sbatchOpt "ntasks" ntasks
2020-08-19 00:28:30 +08:00
+ sbatchOpt "ntasks-per-node" ntasksPerNode
2020-08-18 00:50:18 +08:00
+ sbatchOpt "nodes" nodes
+ sbatchOpt "chdir" "${chdirPrefix}/$(basename $out)"
2020-08-01 00:47:33 +08:00
+ sbatchOpt "output" output
+ sbatchOpt "error" error
+ sbatchEnable "exclusive" exclusive
+ sbatchOpt "time" time
+ sbatchOpt "qos" qos
2020-08-25 00:07:09 +08:00
+ sbatchOpt "reservation" reservation
2020-08-01 00:47:33 +08:00
+ optionalString (extra!=null) extra
+
''
2020-08-18 00:50:18 +08:00
exec ${nixPrefix}${app}${binary} ${argv}
2020-08-01 00:47:33 +08:00
EOF
mkdir -p $out/bin
cat > $out/bin/run <<EOF
#!/bin/sh
if [ -e "${chdirPrefix}/$(basename $out)" ]; then
>&2 echo "Execution aborted: '${chdirPrefix}/$(basename $out)' already exists"
exit 1
fi
mkdir -p "${chdirPrefix}/$(basename $out)"
echo sbatch ${nixPrefix}$out/job
sbatch ${nixPrefix}$out/job
EOF
chmod +x $out/bin/run
2020-08-01 00:47:33 +08:00
'';
}