Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Gras listener thread of each process do select(-1) instead of while(1) {select(0.5)}
[simgrid.git] / testsuite / surf / surf_usage2.c
1 /*      $Id$     */
2
3 /* A few basic tests for the surf library                                   */
4
5 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9 #ifdef __BORLANDC__
10 #pragma hdrstop
11 #endif
12
13 #include <stdio.h>
14 #include "surf/surf.h"
15
16 #include "xbt/log.h"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
18
19 const char *string_action(e_surf_action_state_t state);
20 const char *string_action(e_surf_action_state_t state)
21 {
22   switch (state) {
23   case (SURF_ACTION_READY):
24     return "SURF_ACTION_READY";
25   case (SURF_ACTION_RUNNING):
26     return "SURF_ACTION_RUNNING";
27   case (SURF_ACTION_FAILED):
28     return "SURF_ACTION_FAILED";
29   case (SURF_ACTION_DONE):
30     return "SURF_ACTION_DONE";
31   case (SURF_ACTION_NOT_IN_THE_SYSTEM):
32     return "SURF_ACTION_NOT_IN_THE_SYSTEM";
33   default:
34     return "INVALID STATE";
35   }
36 }
37
38
39 void test(char *platform);
40 void test(char *platform)
41 {
42   void *workstationA = NULL;
43   void *workstationB = NULL;
44   surf_action_t actionA = NULL;
45   surf_action_t actionB = NULL;
46   surf_action_t actionC = NULL;
47   surf_action_t commAB = NULL;
48   double now = -1.0;
49
50   int workstation_id =
51       find_model_description(surf_workstation_model_description,"CLM03");
52
53   surf_workstation_model_description[workstation_id].model_init(platform);
54   parse_platform_file(platform);
55   if (surf_workstation_model_description[workstation_id].create_ws)
56     surf_workstation_model_description[workstation_id].create_ws();
57
58   /*********************** WORKSTATION ***********************************/
59   workstationA =
60       surf_workstation_model->common_public->name_service("Cpu A");
61   workstationB =
62       surf_workstation_model->common_public->name_service("Cpu B");
63
64   /* Let's check that those two processors exist */
65   DEBUG2("%s : %p",
66          surf_workstation_model->common_public->
67          get_resource_name(workstationA), workstationA);
68   DEBUG2("%s : %p",
69          surf_workstation_model->common_public->
70          get_resource_name(workstationB), workstationB);
71
72   /* Let's do something on it */
73   actionA =
74       surf_workstation_model->extension_public->execute(workstationA,
75                                                            1000.0);
76   actionB =
77       surf_workstation_model->extension_public->execute(workstationB,
78                                                            1000.0);
79   actionC =
80       surf_workstation_model->extension_public->sleep(workstationB,
81                                                          7.32);
82
83   commAB =
84       surf_workstation_model->extension_public->
85       communicate(workstationA, workstationB, 150.0, -1.0);
86
87   surf_solve();                 /* Takes traces into account. Returns 0.0 */
88   do {
89     surf_action_t action = NULL;
90     unsigned int iter;
91     surf_model_t model = NULL;
92
93     now = surf_get_clock();
94     DEBUG1("Next Event : %g", now);
95
96     xbt_dynar_foreach(model_list, iter, model) {
97       DEBUG1("\t %s actions", model->common_public->name);
98       while ((action =
99              xbt_swag_extract(model->common_public->states.
100                               failed_action_set))) {
101         DEBUG1("\t * Failed : %p", action);
102         model->common_public->action_free(action);
103       }
104       while ((action =
105              xbt_swag_extract(model->common_public->states.
106                               done_action_set))) {
107         DEBUG1("\t * Done : %p", action);
108         model->common_public->action_free(action);
109       }
110     }
111   } while (surf_solve()>=0.0);
112
113   DEBUG0("Simulation Terminated");
114
115 }
116
117 #ifdef __BORLANDC__
118 #pragma argsused
119 #endif
120
121 int main(int argc, char **argv)
122 {
123   surf_init(&argc, argv);       /* Initialize some common structures */
124   if(argc==1) {
125      fprintf(stderr,"Usage : %s platform.txt\n",argv[0]);
126      surf_exit();
127      return 1;
128   }
129   test(argv[1]);
130
131   surf_exit();
132   return 0;
133 }