Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MASSIVE cleanup: s/workstation/host/
[simgrid.git] / teshsuite / surf / surf_usage / surf_usage2.c
1 /* A few basic tests for the surf library                                   */
2
3 /* Copyright (c) 2004-2014. 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 #ifdef __BORLANDC__
10 #pragma hdrstop
11 #endif
12
13 #include <stdio.h>
14 #include "simgrid/sg_config.h"
15 #include "surf/surf.h"
16 #include "surf/surf_resource.h"
17 #include "surf/surfxml_parse.h" // for reset callback
18
19 #include "xbt/log.h"
20 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
21                              "Messages specific for surf example");
22
23 const char *string_action(e_surf_action_state_t state);
24 const char *string_action(e_surf_action_state_t state)
25 {
26   switch (state) {
27   case (SURF_ACTION_READY):
28     return "SURF_ACTION_READY";
29   case (SURF_ACTION_RUNNING):
30     return "SURF_ACTION_RUNNING";
31   case (SURF_ACTION_FAILED):
32     return "SURF_ACTION_FAILED";
33   case (SURF_ACTION_DONE):
34     return "SURF_ACTION_DONE";
35   case (SURF_ACTION_NOT_IN_THE_SYSTEM):
36     return "SURF_ACTION_NOT_IN_THE_SYSTEM";
37   default:
38     return "INVALID STATE";
39   }
40 }
41
42
43 void test(char *platform);
44 void test(char *platform)
45 {
46   void *hostA = NULL;
47   void *hostB = NULL;
48   double now = -1.0;
49   int running;
50
51   xbt_cfg_set_parse(_sg_cfg_set, "network/model:CM02");
52   xbt_cfg_set_parse(_sg_cfg_set, "cpu/model:Cas01");
53   parse_platform_file(platform);
54
55   /*********************** HOST ***********************************/
56   hostA = surf_host_resource_by_name("Cpu A");
57   hostB = surf_host_resource_by_name("Cpu B");
58
59   /* Let's check that those two processors exist */
60   XBT_DEBUG("%s : %p", surf_resource_name(hostA), hostA);
61   XBT_DEBUG("%s : %p", surf_resource_name(hostB), hostB);
62
63   /* Let's do something on it */
64   surf_host_execute(hostA, 1000.0);
65   surf_host_execute(hostB, 1000.0);
66   surf_host_sleep(hostB, 7.32);
67
68   surf_host_model_communicate(surf_host_model, hostA, hostB, 150.0, -1.0);
69
70   surf_solve(-1.0);                 /* Takes traces into account. Returns 0.0 */
71   do {
72     surf_action_t action = NULL;
73     unsigned int iter;
74     surf_model_t model = NULL;
75     running = 0;
76
77     now = surf_get_clock();
78     XBT_DEBUG("Next Event : %g", now);
79
80     xbt_dynar_foreach(model_list, iter, model) {
81       XBT_DEBUG("\t %s actions", surf_model_name(model));
82       while ((action = surf_model_extract_failed_action_set((surf_model_t)model))) {
83         XBT_DEBUG("\t * Failed : %p", action);
84         surf_action_unref(action);
85       }
86       while ((action = surf_model_extract_done_action_set((surf_model_t)model))) {
87         XBT_DEBUG("\t * Done : %p", action);
88         surf_action_unref(action);
89       }
90       if (surf_model_running_action_set_size((surf_model_t)model)) {
91         XBT_DEBUG("running %s", surf_model_name(model));
92         running = 1;
93       }
94     }
95   } while (running && surf_solve(-1.0) >= 0.0);
96
97   XBT_DEBUG("Simulation Terminated");
98
99 }
100
101 #ifdef __BORLANDC__
102 #pragma argsused
103 #endif
104
105 int main(int argc, char **argv)
106 {
107   surf_init(&argc, argv);       /* Initialize some common structures */
108   if (argc == 1) {
109     fprintf(stderr, "Usage : %s platform.txt\n", argv[0]);
110     surf_exit();
111     return 1;
112   }
113   test(argv[1]);
114
115   surf_exit();
116   return 0;
117 }