Logo AND Algorithmique Numérique Distribuée

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