1 /* simple test trying to load a DOT file. */
3 /* Copyright (c) 2010-2021. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "simgrid/s4u.hpp"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(dag_from_dot, "Logging specific to this example");
14 int main(int argc, char** argv)
16 simgrid::s4u::Engine e(&argc, argv);
17 e.load_platform(argv[1]);
19 std::vector<simgrid::s4u::ActivityPtr> dag = simgrid::s4u::create_DAG_from_dot(argv[2]);
21 XBT_INFO("--------- Display all activities of the loaded DAG -----------");
22 for (const auto& a : dag) {
23 std::string type = "an Exec";
24 std::string task = "flops to execute";
25 if (dynamic_cast<simgrid::s4u::Comm*>(a.get()) != nullptr) {
27 task = "bytes to transfer";
29 XBT_INFO("'%s' is %s: %.0f %s. Dependencies: %s; Ressources: %s", a->get_cname(), type.c_str(), a->get_remaining(),
30 task.c_str(), (a->dependencies_solved() ? "solved" : "NOT solved"),
31 (a->is_assigned() ? "assigned" : "NOT assigned"));
34 XBT_INFO("------------------- Schedule tasks ---------------------------");
35 auto hosts = e.get_all_hosts();
36 auto count = e.get_host_count();
39 static_cast<simgrid::s4u::Exec*>(dag.back().get())->set_host(hosts[0]);
41 for (const auto& a : dag) {
42 auto* exec = dynamic_cast<simgrid::s4u::Exec*>(a.get());
43 if (exec != nullptr && exec->get_name() != "end") {
44 exec->set_host(hosts[cursor % count]);
47 auto* comm = dynamic_cast<simgrid::s4u::Comm*>(a.get());
48 if (comm != nullptr) {
49 auto pred = dynamic_cast<simgrid::s4u::Exec*>(comm->get_parent().get());
50 auto succ = dynamic_cast<simgrid::s4u::Exec*>(comm->get_child().get());
51 comm->set_from(pred->get_host())->set_to(succ->get_host());
55 XBT_INFO("------------------- Run the schedule -------------------------");
58 XBT_INFO("-------------- Summary of executed schedule ------------------");
59 for (const auto& a : dag) {
60 auto* exec = dynamic_cast<simgrid::s4u::Exec*>(a.get());
61 if (exec != nullptr) {
62 XBT_INFO("[%f->%f] '%s' executed on %s", exec->get_start_time(), exec->get_finish_time(), exec->get_cname(),
63 exec->get_host()->get_cname());
65 auto* comm = dynamic_cast<simgrid::s4u::Comm*>(a.get());
66 if (comm != nullptr) {
67 XBT_INFO("%s", comm->get_cname());