From 8110bc2976437fa80f5a54a6e4d5a947204f5c71 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 2 Sep 2020 17:07:09 +0200 Subject: [PATCH] New stage design --- bsc/garlic/argv.nix | 13 +-- bsc/garlic/control.nix | 14 +-- bsc/garlic/default.nix | 19 ++-- bsc/garlic/exp/nbody/bs.nix | 172 +++++++++++++++++++---------------- bsc/garlic/extrae.nix | 25 +++-- bsc/garlic/nbody/default.nix | 4 +- bsc/garlic/nix-setup.nix | 14 +-- bsc/garlic/perf.nix | 12 +-- bsc/garlic/sbatch.nix | 19 ++-- bsc/garlic/srun.nix | 12 +-- bsc/garlic/stagen.nix | 55 +++++++++++ bsc/garlic/statspy.nix | 12 +-- 12 files changed, 221 insertions(+), 150 deletions(-) create mode 100644 bsc/garlic/stagen.nix diff --git a/bsc/garlic/argv.nix b/bsc/garlic/argv.nix index 73adc16..071bfd5 100644 --- a/bsc/garlic/argv.nix +++ b/bsc/garlic/argv.nix @@ -4,28 +4,25 @@ }: { - app + program , env ? "" , argv # bash array as string, example: argv=''(-f "file with spaces" -t 10)'' -, program ? "bin/run" }: stdenv.mkDerivation { - inherit argv; - name = "${app.name}-argv"; + name = "argv"; preferLocalBuild = true; phases = [ "installPhase" ]; installPhase = '' - mkdir -p $out/bin - cat > $out/bin/run < $out < $out/bin/run < $out < libtracempi.so + configFile = ./extrae.xml; + }; - nbodyFn = conf: - with conf; - nbody.override { inherit cc mpi blocksize gitBranch; }; + argv = {stage, conf, ...}: w.argv { + program = stageProgram stage; + env = '' + set -e + export I_MPI_THREAD_SPLIT=1 + ''; + argv = ''( -t ${toString conf.timesteps} + -p ${toString conf.particles} )''; + }; - pipeline = conf: -# sbatch conf ( -# nixsetupWrapper ( -# controlWrapper ( - srun ( - nixsetupWrapper ( -# extrae ( -# perf ( - argv conf ( - nbodyFn conf - ) -# ) -# ) - ) - ) -# ) -# ) -# ) - ; + nbodyFn = {stage, conf, ...}: with conf; nbody.override { + inherit cc blocksize mpi gitBranch; + }; - # Ideally it should look like this: - #pipeline = sbatch nixsetup control argv nbodyFn; + stages = with common; [] + # Use sbatch to request resources first + ++ optional enableSbatch sbatch - jobs = map pipeline configs; + # Repeats the next stages N times + ++ optionals enableControl [ nixsetup control ] + + # Executes srun to launch the program in the requested nodes, and + # immediately after enters the nix environment again, as slurmstepd launches + # the next stages from outside the namespace. + ++ [ srun nixsetup ] + + # Intrumentation with extrae + ++ optional enableExtrae extrae + + # Optionally profile the next stages with perf + ++ optional enablePerf perf + + # Execute the nbody app with the argv and env vars + ++ [ argv nbodyFn ]; + + # List of actual programs to be executed + jobs = map (conf: w.stagen { inherit conf stages; }) configs; in - launchWrapper jobs + # We simply run each program one after another + w.launch jobs diff --git a/bsc/garlic/extrae.nix b/bsc/garlic/extrae.nix index 174636f..4c38bd3 100644 --- a/bsc/garlic/extrae.nix +++ b/bsc/garlic/extrae.nix @@ -2,29 +2,36 @@ stdenv , bash , extrae +#, writeShellScriptBin }: { - app -, traceLib ? "mpi" + program , configFile -, program ? "bin/run" +, traceLib }: +#writeShellScriptBin "extraeWrapper" '' +# export EXTRAE_HOME=${extrae} +# export LD_PRELOAD=${extrae}/lib/lib${traceLib}trace.so:$LD_PRELOAD +# export EXTRAE_CONFIG_FILE=${configFile} +# exec ${program} +#'' + stdenv.mkDerivation { - name = "${app.name}-extrae"; + name = "extrae"; preferLocalBuild = true; phases = [ "installPhase" ]; installPhase = '' - mkdir -p $out/bin - cat > $out/bin/run < $out < $out/bin/run < $out < $out/bin/run < $out < $out/job < $out/bin/run < $out/${name} <&2 echo "Execution aborted: '${chdirPrefix}/$(basename $out)' already exists" @@ -80,6 +77,6 @@ stdenv.mkDerivation rec { echo sbatch ${nixPrefix}$out/job sbatch ${nixPrefix}$out/job EOF - chmod +x $out/bin/run + chmod +x $out/${name} ''; } diff --git a/bsc/garlic/srun.nix b/bsc/garlic/srun.nix index e304fc7..48558b9 100644 --- a/bsc/garlic/srun.nix +++ b/bsc/garlic/srun.nix @@ -2,23 +2,21 @@ stdenv }: { - app + program , nixPrefix ? "" , srunOptions ? "" }: stdenv.mkDerivation rec { - name = "${app.name}-srun"; + name = "srun"; preferLocalBuild = true; phases = [ "installPhase" ]; - buildInputs = [ app ]; dontPatchShebangs = true; installPhase = '' - mkdir -p $out/bin - cat > $out/bin/run < $out < $out/config.raw << EOF + ${builtins.toJSON conf} + EOF + jq . $out/config.raw > $out/config.json + rm $out/config.raw + ''; +} diff --git a/bsc/garlic/statspy.nix b/bsc/garlic/statspy.nix index d039353..06e75e9 100644 --- a/bsc/garlic/statspy.nix +++ b/bsc/garlic/statspy.nix @@ -4,26 +4,26 @@ }: { - app + program , outputDir ? "." -, program ? "bin/run" }: stdenv.mkDerivation { - name = "${app.name}-statspy"; + name = "statspy"; preferLocalBuild = true; phases = [ "installPhase" ]; + programPath = "/bin/${name}"; installPhase = '' mkdir -p $out/bin - cat > $out/bin/run < $out/bin/${name} < ${outputDir}/statspy.\$(date +%s.%3N).begin - ${app}/${program} + ${program} cat /proc/[0-9]*/stat | sort -n > ${outputDir}/statspy.\$(date +%s.%3N).end EOF - chmod +x $out/bin/run + chmod +x $out/bin/${name} ''; }