Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not declare empty sets
[simgrid.git] / teshsuite / surf / surf_usage / surf_usage2.cpp
1 /* A few basic tests for the surf library                                   */
2
3 /* Copyright (c) 2004-2015. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #include <stdio.h>
10 #include "simgrid/sg_config.h"
11 #include "surf/surf.h"
12 #include "surf/surfxml_parse.h" // for reset callback
13 #include "src/surf/surf_interface.hpp"
14 #include "src/surf/cpu_interface.hpp"
15
16 #include "xbt/log.h"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
18                              "Messages specific for surf example");
19
20 const char *string_action(e_surf_action_state_t state);
21 const char *string_action(e_surf_action_state_t state)
22 {
23   switch (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";
34   default:
35     return "INVALID STATE";
36   }
37 }
38
39
40 void test(char *platform);
41 void test(char *platform)
42 {
43   sg_host_t hostA = NULL;
44   sg_host_t hostB = NULL;
45   double now = -1.0;
46   int running;
47
48   xbt_cfg_set_parse(_sg_cfg_set, "network/model:CM02");
49   xbt_cfg_set_parse(_sg_cfg_set, "cpu/model:Cas01");
50   parse_platform_file(platform);
51
52   /*********************** HOST ***********************************/
53   hostA = sg_host_by_name("Cpu A");
54   hostB = sg_host_by_name("Cpu B");
55
56   /* Let's check that those two processors exist */
57   XBT_DEBUG("%s : %p", sg_host_get_name(hostA), hostA);
58   XBT_DEBUG("%s : %p", sg_host_get_name(hostB), hostB);
59
60   /* Let's do something on it */
61   hostA->pimpl_cpu->execution_start(1000.0);
62   hostB->pimpl_cpu->execution_start(1000.0);
63   surf_host_sleep(hostB, 7.32);
64
65   surf_network_model_communicate(surf_network_model, hostA, hostB, 150.0, -1.0);
66
67   surf_solve(-1.0);                 /* Takes traces into account. Returns 0.0 */
68   do {
69     surf_action_t action = NULL;
70     unsigned int iter;
71     surf_model_t model = NULL;
72     running = 0;
73
74     now = surf_get_clock();
75     XBT_DEBUG("Next Event : %g", now);
76
77     xbt_dynar_foreach(all_existing_models, iter, model) {
78       XBT_DEBUG("\t Actions");
79       while ((action = surf_model_extract_failed_action_set((surf_model_t)model))) {
80         XBT_DEBUG("\t * Failed : %p", action);
81         action->unref();
82       }
83       while ((action = surf_model_extract_done_action_set((surf_model_t)model))) {
84         XBT_DEBUG("\t * Done : %p", action);
85         action->unref();
86       }
87       if (surf_model_running_action_set_size((surf_model_t)model)) {
88         XBT_DEBUG("running that model");
89         running = 1;
90       }
91     }
92   } while (running && surf_solve(-1.0) >= 0.0);
93
94   XBT_DEBUG("Simulation Terminated");
95
96 }
97
98 int main(int argc, char **argv)
99 {
100   surf_init(&argc, argv);       /* Initialize some common structures */
101   if (argc == 1) {
102     fprintf(stderr, "Usage : %s platform.txt\n", argv[0]);
103     surf_exit();
104     return 1;
105   }
106   test(argv[1]);
107
108   surf_exit();
109   return 0;
110 }