Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
give simgrid::Host a p_cpu field instead of relying on extensions for non-optional...
[simgrid.git] / teshsuite / surf / surf_usage / surf_usage2.c
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
14 #include "xbt/log.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
16                              "Messages specific for surf example");
17
18 const char *string_action(e_surf_action_state_t state);
19 const char *string_action(e_surf_action_state_t state)
20 {
21   switch (state) {
22   case (SURF_ACTION_READY):
23     return "SURF_ACTION_READY";
24   case (SURF_ACTION_RUNNING):
25     return "SURF_ACTION_RUNNING";
26   case (SURF_ACTION_FAILED):
27     return "SURF_ACTION_FAILED";
28   case (SURF_ACTION_DONE):
29     return "SURF_ACTION_DONE";
30   case (SURF_ACTION_NOT_IN_THE_SYSTEM):
31     return "SURF_ACTION_NOT_IN_THE_SYSTEM";
32   default:
33     return "INVALID STATE";
34   }
35 }
36
37
38 void test(char *platform);
39 void test(char *platform)
40 {
41   sg_host_t hostA = NULL;
42   sg_host_t hostB = NULL;
43   double now = -1.0;
44   int running;
45
46   xbt_cfg_set_parse(_sg_cfg_set, "network/model:CM02");
47   xbt_cfg_set_parse(_sg_cfg_set, "cpu/model:Cas01");
48   parse_platform_file(platform);
49
50   /*********************** HOST ***********************************/
51   hostA = sg_host_by_name("Cpu A");
52   hostB = sg_host_by_name("Cpu B");
53
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);
57
58   /* Let's do something on it */
59   surf_host_execute(hostA, 1000.0);
60   surf_host_execute(hostB, 1000.0);
61   surf_host_sleep(hostB, 7.32);
62
63   surf_network_model_communicate(surf_network_model, hostA, hostB, 150.0, -1.0);
64
65   surf_solve(-1.0);                 /* Takes traces into account. Returns 0.0 */
66   do {
67     surf_action_t action = NULL;
68     unsigned int iter;
69     surf_model_t model = NULL;
70     running = 0;
71
72     now = surf_get_clock();
73     XBT_DEBUG("Next Event : %g", now);
74
75     xbt_dynar_foreach(all_existing_models, iter, model) {
76       XBT_DEBUG("\t Actions");
77       while ((action = surf_model_extract_failed_action_set((surf_model_t)model))) {
78         XBT_DEBUG("\t * Failed : %p", action);
79         surf_action_unref(action);
80       }
81       while ((action = surf_model_extract_done_action_set((surf_model_t)model))) {
82         XBT_DEBUG("\t * Done : %p", action);
83         surf_action_unref(action);
84       }
85       if (surf_model_running_action_set_size((surf_model_t)model)) {
86         XBT_DEBUG("running that model");
87         running = 1;
88       }
89     }
90   } while (running && surf_solve(-1.0) >= 0.0);
91
92   XBT_DEBUG("Simulation Terminated");
93
94 }
95
96 int main(int argc, char **argv)
97 {
98   surf_init(&argc, argv);       /* Initialize some common structures */
99   if (argc == 1) {
100     fprintf(stderr, "Usage : %s platform.txt\n", argv[0]);
101     surf_exit();
102     return 1;
103   }
104   test(argv[1]);
105
106   surf_exit();
107   return 0;
108 }