1 /* A few basic tests for the surf library */
3 /* Copyright (c) 2004-2015. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "simgrid/sg_config.h"
11 #include "simgrid/host.h"
12 #include "surf/surf.h"
13 #include "src/surf/surf_interface.hpp"
14 #include "src/surf/cpu_interface.hpp"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
18 "Messages specific for surf example");
20 const char *string_action(e_surf_action_state_t state);
21 const char *string_action(e_surf_action_state_t state)
24 case (SURF_ACTION_READY):
25 return "SURF_ACTION_READY";
26 case (SURF_ACTION_RUNNING):
27 return "SURF_ACTION_RUNNING";
28 case (SURF_ACTION_FAILED):
29 return "SURF_ACTION_FAILED";
30 case (SURF_ACTION_DONE):
31 return "SURF_ACTION_DONE";
32 case (SURF_ACTION_NOT_IN_THE_SYSTEM):
33 return "SURF_ACTION_NOT_IN_THE_SYSTEM";
35 return "INVALID STATE";
39 int main(int argc, char **argv)
42 surf_init(&argc, argv); /* Initialize some common structures */
43 xbt_cfg_set_parse(_sg_cfg_set, "cpu/model:Cas01");
44 xbt_cfg_set_parse(_sg_cfg_set, "network/model:CM02");
46 xbt_assert(argc >1, "Usage : %s platform.txt\n", argv[0]);
47 parse_platform_file(argv[1]);
49 XBT_DEBUG("CPU model: %p", surf_cpu_model_pm);
50 XBT_DEBUG("Network model: %p", surf_network_model);
51 sg_host_t hostA = sg_host_by_name("Cpu A");
52 sg_host_t hostB = sg_host_by_name("Cpu B");
54 /* Let's check that those two processors exist */
55 XBT_DEBUG("%s : %p", sg_host_get_name(hostA), hostA);
56 XBT_DEBUG("%s : %p", sg_host_get_name(hostB), hostB);
58 /* Let's do something on it */
59 surf_action_t actionA = hostA->pimpl_cpu->execution_start(1000.0);
60 surf_action_t actionB = hostB->pimpl_cpu->execution_start(1000.0);
61 surf_action_t actionC = surf_host_sleep(hostB, 7.32);
63 /* Use whatever calling style you want... */
64 e_surf_action_state_t stateActionA = actionA->getState(); /* When you know actionA model type */
65 e_surf_action_state_t stateActionB = actionB->getState(); /* If you're unsure about it's model type */
66 e_surf_action_state_t stateActionC = actionC->getState(); /* When you know actionA model type */
68 /* And just look at the state of these tasks */
69 XBT_INFO("actionA state: %s", string_action(stateActionA));
70 XBT_INFO("actionB state: %s", string_action(stateActionB));
71 XBT_INFO("actionC state: %s", string_action(stateActionC));
74 /* Let's do something on it */
75 surf_network_model_communicate(surf_network_model, hostA, hostB, 150.0, -1.0);
79 surf_action_t action = NULL;
80 now = surf_get_clock();
81 XBT_INFO("Next Event : %g", now);
82 XBT_DEBUG("\t CPU actions");
83 while ((action = surf_model_extract_failed_action_set((surf_model_t)surf_cpu_model_pm))) {
84 XBT_INFO(" CPU Failed action");
85 XBT_DEBUG("\t * Failed : %p", action);
88 while ((action = surf_model_extract_done_action_set((surf_model_t)surf_cpu_model_pm))) {
89 XBT_INFO(" CPU Done action");
90 XBT_DEBUG("\t * Done : %p", action);
93 XBT_DEBUG("\t Network actions");
94 while ((action = surf_model_extract_failed_action_set((surf_model_t)surf_network_model))) {
95 XBT_INFO(" Network Failed action");
96 XBT_DEBUG("\t * Failed : %p", action);
99 while ((action = surf_model_extract_done_action_set((surf_model_t)surf_network_model))) {
100 XBT_INFO(" Network Failed action");
101 XBT_DEBUG("\t * Done : %p", action);
105 } while ((surf_model_running_action_set_size((surf_model_t)surf_network_model) ||
106 surf_model_running_action_set_size((surf_model_t)surf_cpu_model_pm)) && surf_solve(-1.0) >= 0.0);
108 XBT_DEBUG("Simulation Terminated");