Logo AND Algorithmique Numérique Distribuée

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