diff --git a/docs/_static/data/metrics.json b/docs/_static/data/metrics.json index b17f994..c83816a 100644 --- a/docs/_static/data/metrics.json +++ b/docs/_static/data/metrics.json @@ -54,5 +54,12 @@ "family": "solver", "image": "ghcr.io/converged-computing/metric-nekbone:latest", "url": "https://github.com/Nek5000/Nekbone" + }, + { + "name": "app-pennant", + "description": "Unstructured mesh hydrodynamics for advanced architectures ", + "family": "simulation", + "image": "ghcr.io/converged-computing/metric-pennant:latest", + "url": "https://github.com/LLNL/pennant" } ] \ No newline at end of file diff --git a/pkg/metrics/app/pennant.go b/pkg/metrics/app/pennant.go new file mode 100644 index 0000000..1df7bb7 --- /dev/null +++ b/pkg/metrics/app/pennant.go @@ -0,0 +1,133 @@ +/* +Copyright 2023 Lawrence Livermore National Security, LLC + (c.f. AUTHORS, NOTICE.LLNS, COPYING) + +SPDX-License-Identifier: MIT +*/ + +package application + +import ( + "fmt" + + api "github.com/converged-computing/metrics-operator/api/v1alpha1" + "k8s.io/apimachinery/pkg/util/intstr" + + "github.com/converged-computing/metrics-operator/pkg/metadata" + metrics "github.com/converged-computing/metrics-operator/pkg/metrics" + "github.com/converged-computing/metrics-operator/pkg/specs" +) + +type Pennant struct { + metrics.LauncherWorker + + // Custom Options + command string + prefix string +} + +// I think this is a simulation? +func (m Pennant) Family() string { + return metrics.SimulationFamily +} + +func (m Pennant) Url() string { + return "https://github.com/LLNL/pennant" +} + +// Set custom options / attributes for the metric +func (m *Pennant) SetOptions(metric *api.Metric) { + m.ResourceSpec = &metric.Resources + m.AttributeSpec = &metric.Attributes + + // Set user defined values or fall back to defaults + m.prefix = "mpirun --hostfile ./hostlist.txt" + m.command = "pennant /opt/pennant/test/sedovsmall/sedovsmall.pnt" + m.Workdir = "/opt/pennant/test" + + // This could be improved :) + command, ok := metric.Options["command"] + if ok { + m.command = command.StrVal + } + workdir, ok := metric.Options["workdir"] + if ok { + m.Workdir = workdir.StrVal + } + mpirun, ok := metric.Options["mpirun"] + if ok { + m.prefix = mpirun.StrVal + } +} + +// Exported options and list options +func (m Pennant) Options() map[string]intstr.IntOrString { + return map[string]intstr.IntOrString{ + "command": intstr.FromString(m.command), + "mpirun": intstr.FromString(m.prefix), + "workdir": intstr.FromString(m.Workdir), + } +} +func (n Pennant) ListOptions() map[string][]intstr.IntOrString { + return map[string][]intstr.IntOrString{} +} + +func (m Pennant) PrepareContainers( + spec *api.MetricSet, + metric *metrics.Metric, +) []*specs.ContainerSpec { + + // Metadata to add to beginning of run + meta := metrics.Metadata(spec, metric) + hosts := m.GetHostlist(spec) + prefix := m.GetCommonPrefix(meta, m.command, hosts) + + preBlock := ` +echo "%s" +` + + postBlock := ` +echo "%s" +%s +` + command := fmt.Sprintf("%s ./problem.sh", m.prefix) + interactive := metadata.Interactive(spec.Spec.Logging.Interactive) + preBlock = prefix + fmt.Sprintf(preBlock, metadata.Separator) + postBlock = fmt.Sprintf(postBlock, metadata.CollectionEnd, interactive) + + // Entrypoint for the launcher + launcherEntrypoint := specs.EntrypointScript{ + Name: specs.DeriveScriptKey(m.LauncherScript), + Path: m.LauncherScript, + Pre: preBlock, + Command: command, + Post: postBlock, + } + + // Entrypoint for the worker + workerEntrypoint := specs.EntrypointScript{ + Name: specs.DeriveScriptKey(m.WorkerScript), + Path: m.WorkerScript, + Pre: prefix, + Command: "sleep infinity", + } + + // Container spec for the launcher + launcherContainer := m.GetLauncherContainerSpec(launcherEntrypoint) + workerContainer := m.GetWorkerContainerSpec(workerEntrypoint) + + // Return the script templates for each of launcher and worker + return []*specs.ContainerSpec{&launcherContainer, &workerContainer} +} + +func init() { + launcher := metrics.LauncherWorker{ + Identifier: "app-pennant", + Summary: "Unstructured mesh hydrodynamics for advanced architectures ", + Container: "ghcr.io/converged-computing/metric-pennant:latest", + WorkerScript: "/metrics_operator/pennant-worker.sh", + LauncherScript: "/metrics_operator/pennant-launcher.sh", + } + Pennant := Pennant{LauncherWorker: launcher} + metrics.Register(&Pennant) +}