Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
plug last leaks
[simgrid.git] / teshsuite / surf / surf_usage2 / surf_usage2.cpp
1 /* A few basic tests for the surf library                                   */
2
3 /* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "simgrid/host.h"
9 #include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object
10 #include "simgrid/s4u/Engine.hpp"
11 #include "simgrid/zone.h"
12 #include "src/kernel/EngineImpl.hpp"
13 #include "src/surf/cpu_interface.hpp"
14 #include "src/surf/network_interface.hpp"
15 #include "src/surf/surf_interface.hpp"
16 #include "surf/surf.hpp"
17 #include "xbt/config.hpp"
18
19 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
20
21 int main(int argc, char** argv)
22 {
23   int running;
24
25   simgrid::s4u::Engine e(&argc, argv);
26
27   e.set_config("network/model:CM02");
28   e.set_config("cpu/model:Cas01");
29
30   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
31   e.load_platform(argv[1]);
32
33   /*********************** HOST ***********************************/
34   simgrid::s4u::Host* hostA = e.host_by_name("Cpu A");
35   simgrid::s4u::Host* hostB = e.host_by_name("Cpu B");
36
37   /* Let's do something on it */
38   hostA->get_cpu()->execution_start(1000.0, -1);
39   hostB->get_cpu()->execution_start(1000.0, -1);
40   hostB->get_cpu()->sleep(7.32);
41
42   const_sg_netzone_t as_zone = e.netzone_by_name_or_null("AS0");
43   auto net_model             = as_zone->get_impl()->get_network_model();
44   net_model->communicate(hostA, hostB, 150.0, -1.0);
45
46   surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */
47   do {
48     simgrid::kernel::resource::Action* action = nullptr;
49     running                                   = 0;
50
51     double now = e.get_clock();
52     XBT_INFO("Next Event : %g", now);
53
54     for (auto const& model : e.get_all_models()) {
55       if (not model->get_started_action_set()->empty()) {
56         XBT_DEBUG("\t Running that model");
57         running = 1;
58       }
59
60       action = model->extract_failed_action();
61       while (action != nullptr) {
62         XBT_INFO("   * Done Action");
63         XBT_DEBUG("\t * Failed Action: %p", action);
64         action->unref();
65         action = model->extract_failed_action();
66       }
67
68       action = model->extract_done_action();
69       while (action != nullptr) {
70         XBT_INFO("   * Done Action");
71         XBT_DEBUG("\t * Done Action: %p", action);
72         action->unref();
73         action = model->extract_done_action();
74       }
75     }
76   } while (running && surf_solve(-1.0) >= 0.0);
77
78   XBT_INFO("Simulation Terminated");
79   return 0;
80 }