1 /* A few basic tests for the surf library */
3 /* Copyright (c) 2004-2021. 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. */
8 #include "simgrid/host.h"
9 #include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object
10 #include "simgrid/zone.h"
11 #include "src/surf/cpu_interface.hpp"
12 #include "src/surf/network_interface.hpp"
13 #include "surf/surf.hpp"
14 #include "xbt/config.hpp"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
18 static const char* string_action(simgrid::kernel::resource::Action::State state)
21 case simgrid::kernel::resource::Action::State::INITED:
22 return "SURF_ACTION_INITED";
23 case simgrid::kernel::resource::Action::State::STARTED:
24 return "SURF_ACTION_RUNNING";
25 case simgrid::kernel::resource::Action::State::FAILED:
26 return "SURF_ACTION_FAILED";
27 case simgrid::kernel::resource::Action::State::FINISHED:
28 return "SURF_ACTION_DONE";
29 case simgrid::kernel::resource::Action::State::IGNORED:
30 return "SURF_ACTION_IGNORED";
32 return "INVALID STATE";
36 int main(int argc, char** argv)
38 surf_init(&argc, argv); /* Initialize some common structures */
39 simgrid::config::set_parse("cpu/model:Cas01");
40 simgrid::config::set_parse("network/model:CM02");
42 xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
43 parse_platform_file(argv[1]);
45 sg_netzone_t as_zone = sg_zone_get_by_name("AS0");
46 simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model();
48 XBT_DEBUG("CPU model: %p", surf_cpu_model_pm);
49 XBT_DEBUG("Network model: %p", net_model);
50 simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
51 simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
53 /* Let's do something on it */
54 const simgrid::kernel::resource::Action* actionA = hostA->pimpl_cpu->execution_start(1000.0);
55 const simgrid::kernel::resource::Action* actionB = hostB->pimpl_cpu->execution_start(1000.0);
56 const simgrid::kernel::resource::Action* actionC = hostB->pimpl_cpu->sleep(7.32);
58 simgrid::kernel::resource::Action::State stateActionA = actionA->get_state();
59 simgrid::kernel::resource::Action::State stateActionB = actionB->get_state();
60 simgrid::kernel::resource::Action::State stateActionC = actionC->get_state();
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));
67 /* Let's do something on it */
68 net_model->communicate(hostA, hostB, 150.0, -1.0);
72 XBT_INFO("Next Event : %g", surf_get_clock());
73 XBT_DEBUG("\t CPU actions");
75 simgrid::kernel::resource::Action::StateSet* action_list = surf_cpu_model_pm->get_failed_action_set();
76 while (not action_list->empty()) {
77 simgrid::kernel::resource::Action& action = action_list->front();
78 XBT_INFO(" CPU Failed action");
79 XBT_DEBUG("\t * Failed : %p", &action);
83 action_list = surf_cpu_model_pm->get_finished_action_set();
84 while (not action_list->empty()) {
85 simgrid::kernel::resource::Action& action = action_list->front();
86 XBT_INFO(" CPU Done action");
87 XBT_DEBUG("\t * Done : %p", &action);
91 action_list = net_model->get_failed_action_set();
92 while (not action_list->empty()) {
93 simgrid::kernel::resource::Action& action = action_list->front();
94 XBT_INFO(" Network Failed action");
95 XBT_DEBUG("\t * Failed : %p", &action);
99 action_list = net_model->get_finished_action_set();
100 while (not action_list->empty()) {
101 simgrid::kernel::resource::Action& action = action_list->front();
102 XBT_INFO(" Network Done action");
103 XBT_DEBUG("\t * Done : %p", &action);
106 } while ((net_model->get_started_action_set()->size() || surf_cpu_model_pm->get_started_action_set()->size()) &&
107 surf_solve(-1.0) >= 0.0);
109 XBT_DEBUG("Simulation Terminated");