Logo AND Algorithmique Numérique Distribuée

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