Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0d1238d551e0335d3c9ee1c337597ceef47e5576
[simgrid.git] / teshsuite / surf / surf_usage / surf_usage.cpp
1 /* A few basic tests for the surf library                                   */
2
3 /* Copyright (c) 2004-2019. 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 "surf/surf.hpp"
12 #include "xbt/config.hpp"
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
15
16 static const char* string_action(simgrid::kernel::resource::Action::State state)
17 {
18   switch (state) {
19     case simgrid::kernel::resource::Action::State::INITED:
20       return "SURF_ACTION_INITED";
21     case simgrid::kernel::resource::Action::State::STARTED:
22       return "SURF_ACTION_RUNNING";
23     case simgrid::kernel::resource::Action::State::FAILED:
24       return "SURF_ACTION_FAILED";
25     case simgrid::kernel::resource::Action::State::FINISHED:
26       return "SURF_ACTION_DONE";
27     case simgrid::kernel::resource::Action::State::IGNORED:
28       return "SURF_ACTION_IGNORED";
29     default:
30       return "INVALID STATE";
31   }
32 }
33
34 int main(int argc, char **argv)
35 {
36   surf_init(&argc, argv);       /* Initialize some common structures */
37   simgrid::config::set_parse("cpu/model:Cas01");
38   simgrid::config::set_parse("network/model:CM02");
39
40   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
41   parse_platform_file(argv[1]);
42
43   XBT_DEBUG("CPU model: %p", surf_cpu_model_pm);
44   XBT_DEBUG("Network model: %p", surf_network_model);
45   simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
46   simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
47
48   /* Let's do something on it */
49   simgrid::kernel::resource::Action* actionA = hostA->pimpl_cpu->execution_start(1000.0);
50   simgrid::kernel::resource::Action* actionB = hostB->pimpl_cpu->execution_start(1000.0);
51   simgrid::kernel::resource::Action* actionC = hostB->pimpl_cpu->sleep(7.32);
52
53   simgrid::kernel::resource::Action::State stateActionA = actionA->get_state();
54   simgrid::kernel::resource::Action::State stateActionB = actionB->get_state();
55   simgrid::kernel::resource::Action::State stateActionC = actionC->get_state();
56
57   /* And just look at the state of these tasks */
58   XBT_INFO("actionA state: %s", string_action(stateActionA));
59   XBT_INFO("actionB state: %s", string_action(stateActionB));
60   XBT_INFO("actionC state: %s", string_action(stateActionC));
61
62
63   /* Let's do something on it */
64   surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
65
66   surf_solve(-1.0);
67   do {
68     XBT_INFO("Next Event : %g", surf_get_clock());
69     XBT_DEBUG("\t CPU actions");
70
71     simgrid::kernel::resource::Action::StateSet* action_list = surf_cpu_model_pm->get_failed_action_set();
72     while (not action_list->empty()) {
73       simgrid::kernel::resource::Action& action = action_list->front();
74       XBT_INFO("   CPU Failed action");
75       XBT_DEBUG("\t * Failed : %p", &action);
76       action.unref();
77     }
78
79     action_list = surf_cpu_model_pm->get_finished_action_set();
80     while (not action_list->empty()) {
81       simgrid::kernel::resource::Action& action = action_list->front();
82       XBT_INFO("   CPU Done action");
83       XBT_DEBUG("\t * Done : %p", &action);
84       action.unref();
85     }
86
87     action_list = surf_network_model->get_failed_action_set();
88     while (not action_list->empty()) {
89       simgrid::kernel::resource::Action& action = action_list->front();
90       XBT_INFO("   Network Failed action");
91       XBT_DEBUG("\t * Failed : %p", &action);
92       action.unref();
93     }
94
95     action_list = surf_network_model->get_finished_action_set();
96     while (not action_list->empty()) {
97       simgrid::kernel::resource::Action& action = action_list->front();
98       XBT_INFO("   Network Done action");
99       XBT_DEBUG("\t * Done : %p", &action);
100       action.unref();
101     }
102
103   } while (
104       (surf_network_model->get_started_action_set()->size() || surf_cpu_model_pm->get_started_action_set()->size()) &&
105       surf_solve(-1.0) >= 0.0);
106
107   XBT_DEBUG("Simulation Terminated");
108
109   return 0;
110 }