Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / s4u / dag-incomplete-simulation / dag-incomplete-simulation.cpp
1 /* Copyright (c) 2007-2023. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "simgrid/s4u.hpp"
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(incomplete, "Incomplete DAG test");
10
11 /* Dag ncomplete simulation Test
12  * Scenario:
13  *   - Create a bunch of activities
14  *   - schedule only a subset of them (init, A and D)
15  *   - run the simulation
16  *   - Verify that we detect which activities are blocked and show their state.
17  * The scheduled activity A sends 1GB. Simulation time should be
18  *          1e9/1.25e8 + 1e-4 = 8.0001 seconds
19  * Activity D is scheduled but depends on unscheduled activity C.
20  */
21 int main(int argc, char** argv)
22 {
23   simgrid::s4u::Engine e(&argc, argv);
24   e.load_platform(argv[1]);
25
26   auto* host = e.host_by_name("cpu0");
27   /* creation of the tasks and their dependencies */
28   simgrid::s4u::ExecPtr Init = simgrid::s4u::Exec::init()->set_name("Init")->set_flops_amount(0)->start();
29   simgrid::s4u::CommPtr A = simgrid::s4u::Comm::sendto_init()->set_name("A")->set_payload_size(1e9)->start();
30   simgrid::s4u::CommPtr B = simgrid::s4u::Comm::sendto_init()->set_name("B")->start();
31   simgrid::s4u::ExecPtr C = simgrid::s4u::Exec::init()->set_name("C")->start();
32   simgrid::s4u::CommPtr D = simgrid::s4u::Comm::sendto_init()->set_name("D")->set_payload_size(1e9)->start();
33   std::vector<simgrid::s4u::ActivityPtr> activities = {Init, A, B, C, D};
34
35   Init->add_successor(A);
36   Init->add_successor(B);
37   C->add_successor(D);
38
39   Init->set_host(host);
40   A->set_source(host)->set_destination(host);
41   D->set_source(host)->set_destination(host);
42
43   /* let's launch the simulation! */
44   e.run();
45
46   int count = 0;
47   for (auto a : activities) {
48     if (a->get_state() == simgrid::s4u::Activity::State::STARTING) {
49       count++;
50       XBT_INFO("Activity '%s' blocked: Dependencies: %s; Ressources: %s", a->get_cname(),
51                (a->dependencies_solved() ? "solved" : "NOT solved"), (a->is_assigned() ? "assigned" : "NOT assigned"));
52     }
53   }
54   XBT_INFO("Simulation is finished but %d tasks are still not done", count);
55   // Clean up
56   C->unref();
57   return 0;
58 }