1 /* A few basic tests for the surf library */
3 /* Copyright (c) 2004-2015. The SimGrid Team. All rights reserved. */
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. */
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"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
19 static const char *string_action(simgrid::surf::Action::State state)
22 case (simgrid::surf::Action::State::ready):
23 return "SURF_ACTION_READY";
24 case (simgrid::surf::Action::State::running):
25 return "SURF_ACTION_RUNNING";
26 case (simgrid::surf::Action::State::failed):
27 return "SURF_ACTION_FAILED";
28 case (simgrid::surf::Action::State::done):
29 return "SURF_ACTION_DONE";
30 case (simgrid::surf::Action::State::not_in_the_system):
31 return "SURF_ACTION_NOT_IN_THE_SYSTEM";
33 return "INVALID STATE";
37 int main(int argc, char **argv)
40 surf_init(&argc, argv); /* Initialize some common structures */
41 xbt_cfg_set_parse("cpu/model:Cas01");
42 xbt_cfg_set_parse("network/model:CM02");
44 xbt_assert(argc >1, "Usage : %s platform.txt\n", argv[0]);
45 parse_platform_file(argv[1]);
47 XBT_DEBUG("CPU model: %p", surf_cpu_model_pm);
48 XBT_DEBUG("Network model: %p", surf_network_model);
49 sg_host_t hostA = sg_host_by_name("Cpu A");
50 sg_host_t hostB = sg_host_by_name("Cpu B");
52 /* Let's check that those two processors exist */
53 XBT_DEBUG("%s : %p", sg_host_get_name(hostA), hostA);
54 XBT_DEBUG("%s : %p", sg_host_get_name(hostB), hostB);
56 /* Let's do something on it */
57 simgrid::surf::Action *actionA = hostA->pimpl_cpu->execution_start(1000.0);
58 simgrid::surf::Action *actionB = hostB->pimpl_cpu->execution_start(1000.0);
59 simgrid::surf::Action *actionC = surf_host_sleep(hostB, 7.32);
61 /* Use whatever calling style you want... */
62 simgrid::surf::Action::State stateActionA = actionA->getState(); /* When you know actionA model type */
63 simgrid::surf::Action::State stateActionB = actionB->getState(); /* If you're unsure about it's model type */
64 simgrid::surf::Action::State stateActionC = actionC->getState(); /* When you know actionA model type */
66 /* And just look at the state of these tasks */
67 XBT_INFO("actionA state: %s", string_action(stateActionA));
68 XBT_INFO("actionB state: %s", string_action(stateActionB));
69 XBT_INFO("actionC state: %s", string_action(stateActionC));
72 /* Let's do something on it */
73 surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
77 simgrid::surf::ActionList *action_list = nullptr;
78 now = surf_get_clock();
79 XBT_INFO("Next Event : %g", now);
80 XBT_DEBUG("\t CPU actions");
82 action_list = surf_cpu_model_pm->getFailedActionSet();
83 for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ;
84 it != itend ; it=itNext) {
86 simgrid::surf::Action *action = static_cast<simgrid::surf::CpuAction*>(&*it);
87 XBT_INFO(" CPU Failed action");
88 XBT_DEBUG("\t * Failed : %p", action);
92 action_list = surf_cpu_model_pm->getDoneActionSet();
93 for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ;
94 it != itend ; it=itNext) {
96 simgrid::surf::Action *action = static_cast<simgrid::surf::CpuAction*>(&*it);
97 XBT_INFO(" CPU Done action");
98 XBT_DEBUG("\t * Done : %p", action);
102 action_list = surf_network_model->getFailedActionSet();
103 for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ;
104 it != itend ; it=itNext) {
106 simgrid::surf::Action *action = static_cast<simgrid::surf::NetworkAction*>(&*it);
107 XBT_INFO(" Network Failed action");
108 XBT_DEBUG("\t * Failed : %p", action);
112 action_list = surf_network_model->getDoneActionSet();
113 for(simgrid::surf::ActionList::iterator it(action_list->begin()), itNext = it, itend(action_list->end()) ;
114 it != itend ; it=itNext) {
116 simgrid::surf::Action *action = static_cast<simgrid::surf::NetworkAction*>(&*it);
117 XBT_INFO(" Network Done action");
118 XBT_DEBUG("\t * Done : %p", action);
122 } while ((surf_network_model->getRunningActionSet()->size() ||
123 surf_cpu_model_pm->getRunningActionSet()->size()) && surf_solve(-1.0) >= 0.0);
125 XBT_DEBUG("Simulation Terminated");