From d1196cec78b12c77daf04d48c074eb603f30e6fc Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Tue, 21 Dec 2021 17:21:03 +0100 Subject: [PATCH] new example of dag with I/Os --- examples/cpp/CMakeLists.txt | 2 +- examples/cpp/dag-io/s4u-dag-io.cpp | 59 +++++++++++++++++++++++++++++ examples/cpp/dag-io/s4u-dag-io.tesh | 16 ++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 examples/cpp/dag-io/s4u-dag-io.cpp create mode 100644 examples/cpp/dag-io/s4u-dag-io.tesh diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 07c5b578e8..4e11a9c962 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -66,7 +66,7 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill comm-pingpong comm-ready comm-serialize comm-suspend comm-wait comm-waitany comm-waitall comm-waituntil comm-dependent comm-host2host comm-failure comm-throttling cloud-capping cloud-migration cloud-simple - dag-failure dag-simple + dag-failure dag-io dag-simple dht-chord dht-kademlia energy-exec energy-boot energy-link energy-vm energy-exec-ptask energy-wifi engine-filtering engine-run-partial diff --git a/examples/cpp/dag-io/s4u-dag-io.cpp b/examples/cpp/dag-io/s4u-dag-io.cpp new file mode 100644 index 0000000000..74f3d353d3 --- /dev/null +++ b/examples/cpp/dag-io/s4u-dag-io.cpp @@ -0,0 +1,59 @@ +/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include +#include +#include + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine e(&argc, argv); + sg_storage_file_system_init(); + e.load_platform(argv[1]); + + auto bob = e.host_by_name("bob"); + auto carl = e.host_by_name("carl"); + + // Display the details on vetoed activities + simgrid::s4u::Activity::on_veto.connect([](simgrid::s4u::Activity& a) { + XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", a.get_cname(), + (a.dependencies_solved() ? "solved" : "NOT solved"), (a.is_assigned() ? "assigned" : "NOT assigned")); + }); + + simgrid::s4u::Exec::on_completion.connect([](simgrid::s4u::Exec const& exec) { + XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec.get_cname(), exec.get_start_time(), + exec.get_finish_time()); + }); + + // Create a small DAG: parent->write_output->read_input->child + simgrid::s4u::ExecPtr parent = simgrid::s4u::Exec::init(); + simgrid::s4u::IoPtr write_output = simgrid::s4u::Io::init(); + simgrid::s4u::IoPtr read_input = simgrid::s4u::Io::init(); + simgrid::s4u::ExecPtr child = simgrid::s4u::Exec::init(); + parent->add_successor(write_output); + write_output->add_successor(read_input); + read_input->add_successor(child); + + // Set the parameters (the name is for logging purposes only) + // + parent and chile end after 1 second + parent->set_name("parent")->set_flops_amount(bob->get_speed()); + write_output->set_name("write")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::WRITE); + read_input->set_name("read")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::READ); + child->set_name("child")->set_flops_amount(carl->get_speed()); + + // Schedule and try to start the different activities + parent->set_host(bob)->vetoable_start(); + write_output->set_disk(bob->get_disks().front())->vetoable_start(); + read_input->set_disk(carl->get_disks().front())->vetoable_start(); + child->set_host(carl)->vetoable_start(); + + e.run(); + + XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); + + return 0; +} diff --git a/examples/cpp/dag-io/s4u-dag-io.tesh b/examples/cpp/dag-io/s4u-dag-io.tesh new file mode 100644 index 0000000000..2dcac17518 --- /dev/null +++ b/examples/cpp/dag-io/s4u-dag-io.tesh @@ -0,0 +1,16 @@ +#!/usr/bin/env tesh + +$ ${bindir:=.}/s4u-dag-io ${platfdir}/hosts_with_disks.xml --log=s4u_activity.t:verbose "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +> [ 0.000000] (0:maestro@) 'parent' is assigned to a resource and all dependencies are solved. Let's start +> [ 0.000000] (0:maestro@) Activity 'write' vetoed. Dependencies: NOT solved; Ressources: assigned +> [ 0.000000] (0:maestro@) Activity 'read' vetoed. Dependencies: NOT solved; Ressources: assigned +> [ 0.000000] (0:maestro@) Activity 'child' vetoed. Dependencies: NOT solved; Ressources: assigned +> [ 1.000000] (0:maestro@) Remove a dependency from 'parent' on 'write' +> [ 1.000000] (0:maestro@) 'write' is assigned to a resource and all dependencies are solved. Let's start +> [ 1.000000] (0:maestro@) Activity 'parent' is complete (start time: 0.000000, finish time: 1.000000) +> [ 26.000000] (0:maestro@) Remove a dependency from 'write' on 'read' +> [ 26.000000] (0:maestro@) 'read' is assigned to a resource and all dependencies are solved. Let's start +> [ 36.000000] (0:maestro@) Remove a dependency from 'read' on 'child' +> [ 36.000000] (0:maestro@) 'child' is assigned to a resource and all dependencies are solved. Let's start +> [ 37.000000] (0:maestro@) Activity 'child' is complete (start time: 36.000000, finish time: 37.000000) +> [ 37.000000] (0:maestro@) Simulation time 37 -- 2.20.1