diff --git a/bsc/garlic/default.nix b/bsc/garlic/default.nix index c22f3b0..aa5ff95 100644 --- a/bsc/garlic/default.nix +++ b/bsc/garlic/default.nix @@ -6,9 +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/default.nix { }; - ppong = callPackage ./ppong/default.nix { }; + + mpptest = callPackage ./mpptest { }; + + ppong = callPackage ./ppong { }; + + exp = { + mpiImpl = callPackage ./experiments { + apps = genApps [ ppong ] ( + genConfigs { + mpi = [ bsc.intel-mpi pkgs.mpich pkgs.openmpi ]; + } + ); + }; + }; }; + in garlic diff --git a/bsc/garlic/experiments/config.nix b/bsc/garlic/experiments/config.nix new file mode 100644 index 0000000..7681a8c --- /dev/null +++ b/bsc/garlic/experiments/config.nix @@ -0,0 +1,61 @@ +let + lib = import ; + + inputParams = { + # MPI implementation + mpi = [ + "impi" + "mpich" + ]; + + # Gcc compiler + gcc = [ + "gcc9" + "gcc7" + ]; + + # Additional cflags + cflags = [ + ["-O3" "-fnobugs"] + ["-Ofast"] + ]; + + # Which git branches +# branches = [ +# "mpi+seq" +# "seq" +# ]; + }; + + apps = [ + "dummy" + ]; + + # 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)); + + + # Generates all configs from inputParams + allConfigs = (genConfigs inputParams); + +in + { + inherit allConfigs; + } diff --git a/bsc/garlic/experiments/default.nix b/bsc/garlic/experiments/default.nix new file mode 100644 index 0000000..64754e1 --- /dev/null +++ b/bsc/garlic/experiments/default.nix @@ -0,0 +1,39 @@ +{ + stdenv +, mpi +, fetchurl +, apps +}: + +stdenv.mkDerivation { + name = "garlic-experiments"; + + src = ./.; + + buildInputs = [] ++ apps; + apps = apps; + + buildPhase = '' + for app in $apps; do + test -e $app/bin/run || (echo $app/bin/run not found; exit 1) + done + ''; + + installPhase = '' + mkdir -p $out/apps + for app in $apps; do + ln -s $app $out/apps/$(basename $app) + done + + mkdir -p $out/bin + cat > $out/bin/run <; + + 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 diff --git a/bsc/garlic/ppong/default.nix b/bsc/garlic/ppong/default.nix index 89cdcdc..2a4c399 100644 --- a/bsc/garlic/ppong/default.nix +++ b/bsc/garlic/ppong/default.nix @@ -12,12 +12,22 @@ stdenv.mkDerivation { sha256 = "0d1w72gq9627448cb7ykknhgp2wszwd117dlbalbrpf7d0la8yc0"; }; - dontUnpack = true; + unpackCmd = '' + mkdir src + cp $src src/ppong.c + ''; + + dontConfigure = true; buildPhase = '' - pwd - ls -la - mpicc PPong.c -o ppong + echo mpicc -include stdlib.h ppong.c -o ppong + mpicc -include stdlib.h ppong.c -o ppong + ''; + + installPhase = '' + mkdir -p $out/bin + cp ppong $out/bin/ppong + ln -s $out/bin/ppong $out/bin/run ''; buildInputs = [ mpi ];