1 /* simple test trying to load a DAX file. */
3 /* Copyright (c) 2009-2022. 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"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(dag_from_dax, "Logging specific to this example");
16 int main(int argc, char** argv)
18 simgrid::s4u::Engine e(&argc, argv);
19 e.load_platform(argv[1]);
21 std::vector<simgrid::s4u::ActivityPtr> dag = simgrid::s4u::create_DAG_from_DAX(argv[2]);
24 XBT_ERROR("A problem occurred during DAX parsing (cycle or syntax). Do not continue this test");
28 XBT_INFO("--------- Display all activities of the loaded DAG -----------");
29 for (const auto& a : dag) {
30 std::string type = "an Exec";
31 std::string task = "flops to execute";
32 if (dynamic_cast<simgrid::s4u::Comm*>(a.get()) != nullptr) {
34 task = "bytes to transfer";
36 XBT_INFO("'%s' is %s: %.0f %s. Dependencies: %s; Ressources: %s", a->get_cname(), type.c_str(), a->get_remaining(),
37 task.c_str(), (a->dependencies_solved() ? "solved" : "NOT solved"),
38 (a->is_assigned() ? "assigned" : "NOT assigned"));
41 XBT_INFO("------------------- Schedule tasks ---------------------------");
42 auto hosts = e.get_all_hosts();
43 auto count = e.get_host_count();
46 static_cast<simgrid::s4u::Exec*>(dag.back().get())->set_host(hosts[0]);
48 for (const auto& a : dag) {
49 auto* exec = dynamic_cast<simgrid::s4u::Exec*>(a.get());
50 if (exec != nullptr && exec->get_name() != "end") {
51 exec->set_host(hosts[cursor % count]);
54 auto* comm = dynamic_cast<simgrid::s4u::Comm*>(a.get());
55 if (comm != nullptr) {
56 auto pred = dynamic_cast<simgrid::s4u::Exec*>((*comm->get_dependencies().begin()).get());
57 auto succ = dynamic_cast<simgrid::s4u::Exec*>(comm->get_successors().front().get());
58 comm->set_source(pred->get_host())->set_destination(succ->get_host());
62 XBT_INFO("------------------- Run the schedule -------------------------");
65 XBT_INFO("-------------- Summary of executed schedule ------------------");
66 for (const auto& a : dag) {
67 const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(a.get());
68 if (exec != nullptr) {
69 XBT_INFO("[%f->%f] '%s' executed on %s", exec->get_start_time(), exec->get_finish_time(), exec->get_cname(),
70 exec->get_host()->get_cname());
72 const auto* comm = dynamic_cast<simgrid::s4u::Comm*>(a.get());
73 if (comm != nullptr) {
74 XBT_INFO("[%f->%f] '%s' transferred from %s to %s", comm->get_start_time(), comm->get_finish_time(),
75 comm->get_cname(), comm->get_source()->get_cname(), comm->get_destination()->get_cname());