Logo AND Algorithmique Numérique Distribuée

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