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 const_sg_netzone_t as_zone = sg_zone_get_by_name("AS0");
46 auto net_model = as_zone->get_impl()->get_network_model();
47 auto cpu_model_pm = as_zone->get_impl()->get_cpu_pm_model();
49 XBT_DEBUG("CPU model: %p", cpu_model_pm.get());
50 XBT_DEBUG("Network model: %p", net_model.get());
51 simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
52 simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
54 /* Let's do something on it */
55 const simgrid::kernel::resource::Action* actionA = hostA->get_cpu()->execution_start(1000.0);
56 const simgrid::kernel::resource::Action* actionB = hostB->get_cpu()->execution_start(1000.0);
57 const simgrid::kernel::resource::Action* actionC = hostB->get_cpu()->sleep(7.32);
59 simgrid::kernel::resource::Action::State stateActionA = actionA->get_state();
60 simgrid::kernel::resource::Action::State stateActionB = actionB->get_state();
61 simgrid::kernel::resource::Action::State stateActionC = actionC->get_state();
63 /* And just look at the state of these tasks */
64 XBT_INFO("actionA state: %s", string_action(stateActionA));
65 XBT_INFO("actionB state: %s", string_action(stateActionB));
66 XBT_INFO("actionC state: %s", string_action(stateActionC));
68 /* Let's do something on it */
69 net_model->communicate(hostA, hostB, 150.0, -1.0);
73 XBT_INFO("Next Event : %g", surf_get_clock());
74 XBT_DEBUG("\t CPU actions");
76 simgrid::kernel::resource::Action::StateSet* action_list = cpu_model_pm->get_failed_action_set();
77 while (not action_list->empty()) {
78 simgrid::kernel::resource::Action& action = action_list->front();
79 XBT_INFO(" CPU Failed action");
80 XBT_DEBUG("\t * Failed : %p", &action);
84 action_list = cpu_model_pm->get_finished_action_set();
85 while (not action_list->empty()) {
86 simgrid::kernel::resource::Action& action = action_list->front();
87 XBT_INFO(" CPU Done action");
88 XBT_DEBUG("\t * Done : %p", &action);
92 action_list = net_model->get_failed_action_set();
93 while (not action_list->empty()) {
94 simgrid::kernel::resource::Action& action = action_list->front();
95 XBT_INFO(" Network Failed action");
96 XBT_DEBUG("\t * Failed : %p", &action);
100 action_list = net_model->get_finished_action_set();
101 while (not action_list->empty()) {
102 simgrid::kernel::resource::Action& action = action_list->front();
103 XBT_INFO(" Network Done action");
104 XBT_DEBUG("\t * Done : %p", &action);
107 } while ((net_model->get_started_action_set()->size() || cpu_model_pm->get_started_action_set()->size()) &&
108 surf_solve(-1.0) >= 0.0);
110 XBT_DEBUG("Simulation Terminated");