Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
inline a useless function
[simgrid.git] / teshsuite / surf / surf_usage / surf_usage.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 #include <stdio.h>
16
17 #include "xbt/log.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
19
20 static const char *string_action(simgrid::surf::Action::State state)
21 {
22   switch (state) {
23     case simgrid::surf::Action::State::ready:
24       return "SURF_ACTION_READY";
25     case simgrid::surf::Action::State::running:
26       return "SURF_ACTION_RUNNING";
27     case simgrid::surf::Action::State::failed:
28       return "SURF_ACTION_FAILED";
29     case simgrid::surf::Action::State::done:
30       return "SURF_ACTION_DONE";
31     case simgrid::surf::Action::State::not_in_the_system:
32       return "SURF_ACTION_NOT_IN_THE_SYSTEM";
33     default:
34       return "INVALID STATE";
35   }
36 }
37
38 int main(int argc, char **argv)
39 {
40   double now = -1.0;
41   surf_init(&argc, argv);       /* Initialize some common structures */
42   xbt_cfg_set_parse("cpu/model:Cas01");
43   xbt_cfg_set_parse("network/model:CM02");
44
45   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
46   parse_platform_file(argv[1]);
47
48   XBT_DEBUG("CPU model: %p", surf_cpu_model_pm);
49   XBT_DEBUG("Network model: %p", surf_network_model);
50   simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
51   simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
52
53   /* Let's do something on it */
54   simgrid::surf::Action* actionA = hostA->pimpl_cpu->execution_start(1000.0);
55   simgrid::surf::Action* actionB = hostB->pimpl_cpu->execution_start(1000.0);
56   simgrid::surf::Action* actionC = hostB->pimpl_cpu->sleep(7.32);
57
58   simgrid::surf::Action::State stateActionA = actionA->getState();
59   simgrid::surf::Action::State stateActionB = actionB->getState();
60   simgrid::surf::Action::State stateActionC = actionC->getState();
61
62   /* And just look at the state of these tasks */
63   XBT_INFO("actionA state: %s", string_action(stateActionA));
64   XBT_INFO("actionB state: %s", string_action(stateActionB));
65   XBT_INFO("actionC state: %s", string_action(stateActionC));
66
67
68   /* Let's do something on it */
69   surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
70
71   surf_solve(-1.0);
72   do {
73     simgrid::surf::ActionList *action_list = nullptr;
74     now = surf_get_clock();
75     XBT_INFO("Next Event : %g", now);
76     XBT_DEBUG("\t CPU actions");
77
78     action_list = surf_cpu_model_pm->getFailedActionSet();
79     for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ;
80         it != itend ; it=itNext) {
81       ++itNext;
82       simgrid::surf::Action *action = static_cast<simgrid::surf::CpuAction*>(&*it);
83        XBT_INFO("   CPU Failed action");
84        XBT_DEBUG("\t * Failed : %p", action);
85        action->unref();
86     }
87
88     action_list = surf_cpu_model_pm->getDoneActionSet();
89     for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ;
90         it != itend ; it=itNext) {
91       ++itNext;
92       simgrid::surf::Action *action = static_cast<simgrid::surf::CpuAction*>(&*it);
93       XBT_INFO("   CPU Done action");
94       XBT_DEBUG("\t * Done : %p", action);
95       action->unref();
96     }
97
98     action_list = surf_network_model->getFailedActionSet();
99     for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ;
100         it != itend ; it=itNext) {
101       ++itNext;
102       simgrid::surf::Action *action = static_cast<simgrid::surf::NetworkAction*>(&*it);
103        XBT_INFO("   Network Failed action");
104        XBT_DEBUG("\t * Failed : %p", action);
105        action->unref();
106     }
107
108     action_list = surf_network_model->getDoneActionSet();
109     for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ;
110         it != itend ; it=itNext) {
111       ++itNext;
112       simgrid::surf::Action *action = static_cast<simgrid::surf::NetworkAction*>(&*it);
113       XBT_INFO("   Network Done action");
114       XBT_DEBUG("\t * Done : %p", action);
115       action->unref();
116     }
117
118   } while ((surf_network_model->getRunningActionSet()->size() ||
119            surf_cpu_model_pm->getRunningActionSet()->size()) && surf_solve(-1.0) >= 0.0);
120
121   XBT_DEBUG("Simulation Terminated");
122
123   return 0;
124 }