2021-04-12 14:41:26 +02:00
|
|
|
{
|
|
|
|
stdenv
|
|
|
|
, stdexp
|
|
|
|
, bsc
|
|
|
|
, stages
|
|
|
|
}:
|
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
2021-04-12 15:01:25 +02:00
|
|
|
# Common definitions used by fwi experiments
|
2021-04-12 14:41:26 +02:00
|
|
|
rec {
|
|
|
|
|
2021-04-12 15:01:25 +02:00
|
|
|
branchesWithoutBlocksize = [
|
|
|
|
"garlic/mpi+send+omp+fork"
|
|
|
|
"garlic/mpi+send+seq"
|
|
|
|
];
|
2021-04-12 14:41:26 +02:00
|
|
|
|
|
|
|
# Returns true if the given config is in the forkJoinBranches list
|
2021-04-12 15:01:25 +02:00
|
|
|
needsBlocksize = c: ! any (e: c.gitBranch == e) branchesWithoutBlocksize;
|
2021-04-12 14:41:26 +02:00
|
|
|
|
|
|
|
# Set the blocksize to null for the fork join branch
|
2021-04-12 15:01:25 +02:00
|
|
|
fixBlocksize = c: if (needsBlocksize c) then c
|
|
|
|
else (c // { blocksize = null; });
|
|
|
|
|
|
|
|
# Generate the configs by filtering the unneded blocksizes
|
|
|
|
getConfigs = {varConf, genConf}:
|
|
|
|
let
|
|
|
|
allConfigs = stdexp.buildConfigs { inherit varConf genConf; };
|
|
|
|
in
|
|
|
|
# The unique function ensures that we only run one config for the fork
|
|
|
|
# join branch, even if we have multiple blocksizes.
|
|
|
|
unique (map fixBlocksize allConfigs);
|
2021-04-12 14:41:26 +02:00
|
|
|
|
2021-04-12 15:37:39 +02:00
|
|
|
getResources = {gitBranch, hw}:
|
|
|
|
if (gitBranch == "garlic/mpi+send+seq") then {
|
|
|
|
cpusPerTask = hw.cpusPerSocket;
|
|
|
|
ntasksPerNode = hw.socketsPerNode;
|
|
|
|
} else {
|
|
|
|
cpusPerTask = 1;
|
|
|
|
ntasksPerNode = hw.cpusPerNode;
|
|
|
|
};
|
|
|
|
|
2021-04-12 17:46:07 +02:00
|
|
|
srun = {nextStage, conf, ...}:
|
|
|
|
let
|
|
|
|
fwiParams = bsc.apps.fwi.params.override {
|
|
|
|
inherit (conf) nx ny nz;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
stdexp.stdStages.srun {
|
|
|
|
inherit nextStage conf;
|
|
|
|
# Now we add some commands to execute before calling srun. These will
|
|
|
|
# only run in one rank (the first in the list of allocated nodes)
|
|
|
|
preSrun = ''
|
|
|
|
export GARLIC_FWI_SRUNDIR=$(pwd)
|
|
|
|
export GARLIC_FWI_EXECDIR="${conf.tempDir}/out/$GARLIC_USER/$GARLIC_UNIT/$GARLIC_RUN"
|
|
|
|
mkdir -p "$GARLIC_FWI_EXECDIR"
|
|
|
|
|
|
|
|
export GARLIC_FWI_PARAMS="${fwiParams}/fwi_params.txt"
|
|
|
|
export GARLIC_FWI_FREQ="${fwiParams}/fwi_frequencies.txt"
|
|
|
|
|
|
|
|
# We cannot change the working directory of srun, so we use a
|
|
|
|
# subshell to ignore the cd
|
|
|
|
(
|
|
|
|
# Generate the input dataset
|
|
|
|
>&2 echo "generating the input dataset"
|
|
|
|
cd "$GARLIC_FWI_EXECDIR"
|
|
|
|
${fwiParams}/bin/ModelGenerator \
|
|
|
|
-m "$GARLIC_FWI_PARAMS" "$GARLIC_FWI_FREQ"
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
|
|
|
|
postSrun = optionalString (conf.enableCTF) ''
|
|
|
|
# Save the traces
|
|
|
|
mv "$GARLIC_FWI_EXECDIR"/trace_* .
|
|
|
|
'' + ''
|
|
|
|
# Remove everything else
|
|
|
|
rm -rf "$GARLIC_FWI_EXECDIR"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-04-12 14:41:26 +02:00
|
|
|
exec = {nextStage, conf, ...}: stages.exec {
|
|
|
|
inherit nextStage;
|
|
|
|
|
2021-04-12 17:46:07 +02:00
|
|
|
# FIXME: FWI should allow the I/O directory to be specified as a
|
|
|
|
# parameter
|
2021-04-12 14:41:26 +02:00
|
|
|
pre = ''
|
2021-04-12 17:46:07 +02:00
|
|
|
# Run fwi at the in a directory with fast local storage
|
|
|
|
cd "$GARLIC_FWI_EXECDIR"
|
|
|
|
|
|
|
|
echo >&2 "Current dir: $(pwd)"
|
|
|
|
echo >&2 "Using PARAMS=$GARLIC_FWI_PARAMS and FREQ=$GARLIC_FWI_FREQ"
|
2021-04-12 14:41:26 +02:00
|
|
|
'' + optionalString (conf.enableCTF) ''
|
|
|
|
export NANOS6_CONFIG_OVERRIDE="version.instrument=ctf"
|
|
|
|
'';
|
|
|
|
|
|
|
|
argv = [
|
2021-04-12 17:46:07 +02:00
|
|
|
''"$GARLIC_FWI_PARAMS"''
|
|
|
|
''"$GARLIC_FWI_FREQ"''
|
2021-04-12 15:01:25 +02:00
|
|
|
] ++ optional (needsBlocksize conf) conf.blocksize ++ [
|
2021-04-12 14:41:26 +02:00
|
|
|
"-1" # Fordward steps
|
|
|
|
"-1" # Backward steps
|
|
|
|
conf.ioFreq # Write/read frequency
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
apps = bsc.garlic.apps;
|
|
|
|
|
|
|
|
# FWI program
|
2021-04-12 17:46:07 +02:00
|
|
|
program = {nextStage, conf, ...}:
|
|
|
|
let
|
|
|
|
fwiParams = bsc.apps.fwi.params.override {
|
|
|
|
inherit (conf) nx ny nz;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
apps.fwi.solver.override {
|
|
|
|
inherit (conf) gitBranch;
|
|
|
|
inherit fwiParams;
|
|
|
|
};
|
2021-04-12 14:41:26 +02:00
|
|
|
|
2021-04-12 17:46:07 +02:00
|
|
|
pipeline = stdexp.stdPipelineOverride {
|
|
|
|
# Replace the stdandard srun stage with our own
|
|
|
|
overrides = { inherit srun; };
|
|
|
|
} ++ [ exec program ];
|
2021-04-12 14:41:26 +02:00
|
|
|
}
|