Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3825f361ea298d6d5c1d5e98516cc71542ca1d46
[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/host.h"
10 #include "simgrid/s4u/host.hpp"
11 #include "simgrid/sg_config.h"
12 #include "src/surf/cpu_interface.hpp"
13 #include "src/surf/network_interface.hpp"
14 #include "src/surf/surf_interface.hpp"
15
16 #include "xbt/log.h"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
18
19 int main(int argc, char **argv)
20 {
21   double now = -1.0;
22   int running;
23
24   surf_init(&argc, argv);       /* Initialize some common structures */
25
26   xbt_cfg_set_parse("network/model:CM02");
27   xbt_cfg_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   surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
42
43   surf_solve(-1.0);                 /* Takes traces into account. Returns 0.0 */
44   do {
45     surf_action_t action = nullptr;
46     running = 0;
47
48     now = surf_get_clock();
49     XBT_INFO("Next Event : %g", now);
50
51     for (auto model: *all_existing_models) {
52       if (surf_model_running_action_set_size(model)) {
53         XBT_DEBUG("\t Running that model");
54         running = 1;
55       }
56
57       action = surf_model_extract_failed_action_set(model);
58       while (action != nullptr) {
59         XBT_INFO("   * Done Action");
60         XBT_DEBUG("\t * Failed Action: %p", action);
61         action->unref();
62         action = surf_model_extract_failed_action_set(model);
63       }
64
65       action = surf_model_extract_done_action_set(model);
66       while (action != nullptr){
67         XBT_INFO("   * Done Action");
68         XBT_DEBUG("\t * Done Action: %p", action);
69         action->unref();
70         action = surf_model_extract_done_action_set(model);
71       }
72     }
73   } while (running && surf_solve(-1.0) >= 0.0);
74
75   XBT_INFO("Simulation Terminated");
76   return 0;
77 }