From 979888eede1d53c1c31eed7380a8d5c1fe5737d1 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Mon, 27 Jul 2020 11:14:33 +0200 Subject: [PATCH] Add generators for experiments --- bsc/garlic/default.nix | 19 +++++++++++++------ bsc/garlic/gen.nix | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 bsc/garlic/gen.nix diff --git a/bsc/garlic/default.nix b/bsc/garlic/default.nix index e2c6475..aa5ff95 100644 --- a/bsc/garlic/default.nix +++ b/bsc/garlic/default.nix @@ -6,19 +6,26 @@ let callPackage = pkgs.lib.callPackageWith (pkgs // bsc // garlic); callPackages = pkgs.lib.callPackagesWith (pkgs // bsc // garlic); + + # Load some helper functions to generate app variants + inherit (import ./gen.nix) genApps genConfigs; + garlic = rec { mpptest = callPackage ./mpptest { }; ppong = callPackage ./ppong { }; - experiments = callPackage ./experiments { - apps = [ - (ppong.override { mpi=bsc.intel-mpi;}) - (ppong.override { mpi=pkgs.mpich;}) - ]; + exp = { + mpiImpl = callPackage ./experiments { + apps = genApps [ ppong ] ( + genConfigs { + mpi = [ bsc.intel-mpi pkgs.mpich pkgs.openmpi ]; + } + ); + }; }; - }; + in garlic diff --git a/bsc/garlic/gen.nix b/bsc/garlic/gen.nix new file mode 100644 index 0000000..adac866 --- /dev/null +++ b/bsc/garlic/gen.nix @@ -0,0 +1,34 @@ +let + lib = import ; + + gen = rec { + # genAttrSets "a" ["hello" "world"] + # [ { a = "hello"; } { a = "world"; } ] + genAttrSets = (name: arr: (map (x: {${name}=x; })) arr); + + # addAttrSets "a" [1 2] {e=4;} + # [ { a = 1; e = 4; } { a = 2; e = 4; } ] + addAttrSets = (name: arr: set: (map (x: set // {${name}=x; })) arr); + + # attrToList {a=1;} + # [ { name = "a"; value = 1; } ] + attrToList = (set: map (name: {name=name; value=set.${name};} ) (builtins.attrNames set)); + + # mergeConfig [{e=1;}] {name="a"; value=[1 2] + # [ { a = 1; e = 1; } { a = 2; e = 1; } ] + mergeConfig = (arr: new: lib.flatten ( map (x: addAttrSets new.name new.value x) arr)); + + # genConfigs {a=[1 2]; b=[3 4];} + # [ { a = 1; b = 3; } { a = 1; b = 4; } { a = 2; b = 3; } { a = 2; b = 4; } ] + genConfigs = (config: lib.foldl mergeConfig [{}] (attrToList config)); + + # Generate multiple app versions by override with each config + genApp = (app: configs: map (conf: app.override conf) configs); + + # Generate app version from an array of apps + genApps = (apps: configs: + lib.flatten (map (app: genApp app configs) apps)); + + }; +in + gen