2018-10-04 17:33:03 +02:00
|
|
|
|
use benchmark_repository::BenchmarkRepository;
|
2018-09-28 16:19:14 +02:00
|
|
|
|
|
2018-10-12 17:49:30 +02:00
|
|
|
|
use std::fs;
|
2018-09-28 16:19:14 +02:00
|
|
|
|
use std::path::Path;
|
2018-10-12 17:37:08 +02:00
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
2018-10-04 17:33:03 +02:00
|
|
|
|
use yaml_rust::YamlLoader;
|
2018-09-28 16:19:14 +02:00
|
|
|
|
|
|
|
|
|
fn main()
|
|
|
|
|
{
|
|
|
|
|
pretty_env_logger::init();
|
|
|
|
|
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// Initialize a new benchmark repository
|
2019-03-02 02:26:16 +01:00
|
|
|
|
let mut benchmark_repository = BenchmarkRepository::new("gitea@git.luehne.de:patrick/benchmark-template.git", Path::new("cache").to_path_buf(), "gitea");
|
2018-09-28 16:19:14 +02:00
|
|
|
|
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// Load the instances.yml file from the config branch
|
2018-09-28 16:53:20 +02:00
|
|
|
|
let content = benchmark_repository.read_file(Path::new("instances.yml"), "config").unwrap();
|
2018-09-28 16:19:14 +02:00
|
|
|
|
let instances = &YamlLoader::load_from_str(&content).unwrap()[0];
|
|
|
|
|
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// Iterate over all instances
|
2019-03-02 02:26:16 +01:00
|
|
|
|
for instance in instances.as_vec().unwrap()
|
2018-09-28 16:19:14 +02:00
|
|
|
|
{
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// Each instance has a fruit and a time needed to collect it
|
2019-03-02 02:26:16 +01:00
|
|
|
|
let fruit = instance["fruit"].as_str().unwrap();
|
|
|
|
|
let time = instance["time"].as_i64().unwrap();
|
|
|
|
|
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// The key defines in which directory the results will be stored. It must be unique for
|
|
|
|
|
// every job
|
2019-03-02 02:26:16 +01:00
|
|
|
|
let job_key = format!("{}/{}", fruit, time);
|
2019-03-02 03:51:10 +01:00
|
|
|
|
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// Skip jobs that have already been completed
|
2019-03-02 03:51:10 +01:00
|
|
|
|
if benchmark_repository.is_job_done(&job_key)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// Request a new job. This will create the infrastructure necessary to automatically
|
|
|
|
|
// retrieve the results from each computation node
|
2019-03-02 02:26:16 +01:00
|
|
|
|
let job = benchmark_repository.create_job(job_key);
|
|
|
|
|
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// Run the script that we use to benchmark this job. In this example, all configuration
|
|
|
|
|
// options are passed to the script as environment variable. The script then passes them to
|
|
|
|
|
// the actual command we want to benchmark
|
2019-03-02 02:26:16 +01:00
|
|
|
|
Command::new("sbatch")
|
|
|
|
|
.args(&["/home/pluehne/test-job.sh", "--nodes", "1", "--ntasks-per-node", "1", "-p", "kr"])
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// This is the URL the computation node needs to write the results to. All it needs to
|
|
|
|
|
// do is clone this repository, and create and push a commit to the “master” branch once
|
|
|
|
|
// it’s done with the benchmark job
|
2019-03-02 02:26:16 +01:00
|
|
|
|
.env("JOB_RESULT_REPOSITORY_URL", &format!("file://{}", fs::canonicalize(&job.result_repository_path).unwrap().display()))
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// The job ID provides a quick way to create temporary files without conflicts between
|
|
|
|
|
// the jobs
|
2019-03-02 02:26:16 +01:00
|
|
|
|
.env("JOB_ID", format!("{}", job.id))
|
|
|
|
|
.env("JOB_KEY", &job.key)
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// Here come the two options that we use to configure the command we want to benchmark
|
2019-03-02 02:26:16 +01:00
|
|
|
|
.env("FRUIT", fruit)
|
|
|
|
|
.env("TIME", format!("{}", time))
|
|
|
|
|
.output()
|
2019-03-02 04:20:41 +01:00
|
|
|
|
.expect("could not execute command");
|
2018-09-28 16:19:14 +02:00
|
|
|
|
}
|
2018-10-12 17:37:08 +02:00
|
|
|
|
|
2019-03-02 04:20:41 +01:00
|
|
|
|
// Finally, we instruct the benchmark runner to wait for all jobs to finish and to join all the
|
|
|
|
|
// results from all jobs into the “results” branch
|
2018-10-12 17:37:08 +02:00
|
|
|
|
benchmark_repository.join();
|
2018-09-28 16:19:14 +02:00
|
|
|
|
}
|