Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update path.
[simgrid.git] / teshsuite / surf / surf_usage2 / surf_usage2.cpp
1 /* A few basic tests for the surf library                                   */
2
3 /* Copyright (c) 2004-2023. 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/kernel/resource/CpuImpl.hpp"
14 #include "src/kernel/resource/NetworkModel.hpp"
15 #include "xbt/config.hpp"
16
17 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
18
19 int main(int argc, char** argv)
20 {
21   int running;
22
23   simgrid::s4u::Engine e(&argc, argv);
24
25   simgrid::s4u::Engine::set_config("network/model:CM02");
26   simgrid::s4u::Engine::set_config("cpu/model:Cas01");
27
28   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
29   e.load_platform(argv[1]);
30
31   /*********************** HOST ***********************************/
32   simgrid::s4u::Host* hostA = e.host_by_name("Cpu A");
33   simgrid::s4u::Host* hostB = e.host_by_name("Cpu B");
34
35   /* Let's do something on it */
36   hostA->get_cpu()->execution_start(1000.0, -1);
37   hostB->get_cpu()->execution_start(1000.0, -1);
38   hostB->get_cpu()->sleep(7.32);
39
40   const_sg_netzone_t as_zone = e.netzone_by_name_or_null("AS0");
41   auto net_model             = as_zone->get_impl()->get_network_model();
42   net_model->communicate(hostA, hostB, 150.0, -1.0, false);
43
44   e.get_impl()->solve(-1.0); /* Takes traces into account. Returns 0.0 */
45   do {
46     simgrid::kernel::resource::Action* action = nullptr;
47     running                                   = 0;
48
49     double now = simgrid::s4u::Engine::get_clock();
50     XBT_INFO("Next Event : %g", now);
51
52     for (auto const& model : e.get_all_models()) {
53       if (not model->get_started_action_set()->empty()) {
54         XBT_DEBUG("\t Running that model");
55         running = 1;
56       }
57
58       action = model->extract_failed_action();
59       while (action != nullptr) {
60         XBT_INFO("   * Done Action");
61         XBT_DEBUG("\t * Failed Action: %p", action);
62         action->unref();
63         action = model->extract_failed_action();
64       }
65
66       action = model->extract_done_action();
67       while (action != nullptr) {
68         XBT_INFO("   * Done Action");
69         XBT_DEBUG("\t * Done Action: %p", action);
70         action->unref();
71         action = model->extract_done_action();
72       }
73     }
74   } while (running && e.get_impl()->solve(-1.0) >= 0.0);
75
76   XBT_INFO("Simulation Terminated");
77   return 0;
78 }