Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move globals to EngineImpl
[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/zone.h"
11 #include "src/kernel/EngineImpl.hpp"
12 #include "src/surf/cpu_interface.hpp"
13 #include "src/surf/network_interface.hpp"
14 #include "src/surf/surf_interface.hpp"
15 #include "surf/surf.hpp"
16 #include "xbt/config.hpp"
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
19
20 int main(int argc, char** argv)
21 {
22   int running;
23
24   surf_init(&argc, argv); /* Initialize some common structures */
25
26   simgrid::config::set_parse("network/model:CM02");
27   simgrid::config::set_parse("cpu/model:Cas01");
28
29   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
30   parse_platform_file(argv[1]);
31
32   /*********************** HOST ***********************************/
33   simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
34   simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
35
36   /* Let's do something on it */
37   hostA->pimpl_cpu->execution_start(1000.0);
38   hostB->pimpl_cpu->execution_start(1000.0);
39   hostB->pimpl_cpu->sleep(7.32);
40
41   sg_netzone_t as_zone                               = sg_zone_get_by_name("AS0");
42   simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model();
43   net_model->communicate(hostA, hostB, 150.0, -1.0);
44
45   surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */
46   do {
47     simgrid::kernel::resource::Action* action = nullptr;
48     running                                   = 0;
49
50     double now = surf_get_clock();
51     XBT_INFO("Next Event : %g", now);
52
53     for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
54       if (model->get_started_action_set()->size() != 0) {
55         XBT_DEBUG("\t Running that model");
56         running = 1;
57       }
58
59       action = model->extract_failed_action();
60       while (action != nullptr) {
61         XBT_INFO("   * Done Action");
62         XBT_DEBUG("\t * Failed Action: %p", action);
63         action->unref();
64         action = model->extract_failed_action();
65       }
66
67       action = model->extract_done_action();
68       while (action != nullptr) {
69         XBT_INFO("   * Done Action");
70         XBT_DEBUG("\t * Done Action: %p", action);
71         action->unref();
72         action = model->extract_done_action();
73       }
74     }
75   } while (running && surf_solve(-1.0) >= 0.0);
76
77   XBT_INFO("Simulation Terminated");
78   return 0;
79 }