2020-07-31 18:47:33 +02:00
|
|
|
{
|
|
|
|
stdenv
|
2020-08-04 11:51:09 +02:00
|
|
|
, numactl
|
2020-07-31 18:47:33 +02:00
|
|
|
}:
|
|
|
|
|
|
|
|
{
|
2020-09-02 17:07:09 +02:00
|
|
|
program
|
|
|
|
, jobName
|
2020-08-24 18:06:47 +02:00
|
|
|
, chdirPrefix ? "."
|
2020-08-10 18:25:53 +02:00
|
|
|
, nixPrefix ? ""
|
2020-07-31 18:47:33 +02:00
|
|
|
, binary ? "/bin/run"
|
|
|
|
, ntasks ? null
|
2020-08-18 18:28:30 +02:00
|
|
|
, ntasksPerNode ? null
|
2020-08-17 18:50:18 +02:00
|
|
|
, nodes ? null
|
2020-07-31 18:47:33 +02:00
|
|
|
, exclusive ? true # By default we run in exclusive mode
|
|
|
|
, qos ? null
|
2020-08-24 18:07:09 +02:00
|
|
|
, reservation ? null
|
2020-07-31 18:47:33 +02:00
|
|
|
, time ? null
|
|
|
|
, output ? "job_%j.out"
|
|
|
|
, error ? "job_%j.err"
|
|
|
|
, contiguous ? null
|
|
|
|
, extra ? null
|
2020-09-03 16:19:19 +02:00
|
|
|
, acctgFreq ? null
|
2020-07-31 18:47:33 +02:00
|
|
|
}:
|
|
|
|
|
|
|
|
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 {
|
2020-09-02 17:07:09 +02:00
|
|
|
name = "sbatch";
|
2020-07-31 18:47:33 +02:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2020-09-02 10:44:13 +02:00
|
|
|
phases = [ "installPhase" ];
|
2020-07-31 18:47:33 +02:00
|
|
|
|
|
|
|
#SBATCH --tasks-per-node=48
|
|
|
|
#SBATCH --ntasks-per-socket=24
|
|
|
|
#SBATCH --cpus-per-task=1
|
|
|
|
dontBuild = true;
|
2020-08-10 18:25:53 +02:00
|
|
|
dontPatchShebangs = true;
|
2020-09-02 17:07:09 +02:00
|
|
|
programPath = "/${name}";
|
2020-07-31 18:47:33 +02:00
|
|
|
|
|
|
|
installPhase = ''
|
2020-08-04 18:38:33 +02:00
|
|
|
mkdir -p $out
|
|
|
|
cat > $out/job <<EOF
|
2020-08-10 18:25:53 +02:00
|
|
|
#!/bin/sh
|
2020-09-02 17:07:09 +02:00
|
|
|
#SBATCH --job-name="${jobName}"
|
2020-07-31 18:47:33 +02:00
|
|
|
''
|
|
|
|
+ sbatchOpt "ntasks" ntasks
|
2020-08-18 18:28:30 +02:00
|
|
|
+ sbatchOpt "ntasks-per-node" ntasksPerNode
|
2020-08-17 18:50:18 +02:00
|
|
|
+ sbatchOpt "nodes" nodes
|
2020-08-10 18:25:53 +02:00
|
|
|
+ sbatchOpt "chdir" "${chdirPrefix}/$(basename $out)"
|
2020-07-31 18:47:33 +02:00
|
|
|
+ sbatchOpt "output" output
|
|
|
|
+ sbatchOpt "error" error
|
|
|
|
+ sbatchEnable "exclusive" exclusive
|
|
|
|
+ sbatchOpt "time" time
|
|
|
|
+ sbatchOpt "qos" qos
|
2020-08-24 18:07:09 +02:00
|
|
|
+ sbatchOpt "reservation" reservation
|
2020-09-03 16:19:19 +02:00
|
|
|
+ sbatchOpt "acctg-freq" acctgFreq
|
2020-07-31 18:47:33 +02:00
|
|
|
+ optionalString (extra!=null) extra
|
2020-08-10 14:13:28 +02:00
|
|
|
+
|
|
|
|
''
|
2020-09-02 17:07:09 +02:00
|
|
|
exec ${nixPrefix}${program}
|
2020-07-31 18:47:33 +02:00
|
|
|
EOF
|
2020-08-10 18:25:53 +02:00
|
|
|
|
2020-09-02 17:07:09 +02:00
|
|
|
cat > $out/${name} <<EOF
|
2020-08-10 18:25:53 +02:00
|
|
|
#!/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
|
2020-09-02 17:07:09 +02:00
|
|
|
chmod +x $out/${name}
|
2020-07-31 18:47:33 +02:00
|
|
|
'';
|
|
|
|
}
|