Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove testsuite/simdag.
[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 "surf/surf.h"
14
15 #include "xbt/log.h"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
17                              "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   int running;
50
51   int workstation_id =
52       find_model_description(surf_workstation_model_description, "CLM03");
53
54   surf_workstation_model_description[workstation_id].
55       model_init_preparse(platform);
56   parse_platform_file(platform);
57   if (surf_workstation_model_description[workstation_id].
58       model_init_postparse)
59     surf_workstation_model_description[workstation_id].
60         model_init_postparse();
61
62   /*********************** WORKSTATION ***********************************/
63   workstationA =
64       surf_model_resource_by_name(surf_workstation_model, "Cpu A");
65   workstationB =
66       surf_model_resource_by_name(surf_workstation_model, "Cpu B");
67
68   /* Let's check that those two processors exist */
69   DEBUG2("%s : %p", surf_resource_name(workstationA), workstationA);
70   DEBUG2("%s : %p", surf_resource_name(workstationB), workstationB);
71
72   /* Let's do something on it */
73   actionA =
74       surf_workstation_model->extension.workstation.execute(workstationA,
75                                                             1000.0);
76   actionB =
77       surf_workstation_model->extension.workstation.execute(workstationB,
78                                                             1000.0);
79   actionC =
80       surf_workstation_model->extension.workstation.sleep(workstationB,
81                                                           7.32);
82
83   commAB =
84       surf_workstation_model->extension.workstation.
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     running = 0;
93
94     now = surf_get_clock();
95     DEBUG1("Next Event : %g", now);
96
97     xbt_dynar_foreach(model_list, iter, model) {
98       DEBUG1("\t %s actions", model->name);
99       while ((action = xbt_swag_extract(model->states.failed_action_set))) {
100         DEBUG1("\t * Failed : %p", action);
101         model->action_unref(action);
102       }
103       while ((action = xbt_swag_extract(model->states.done_action_set))) {
104         DEBUG1("\t * Done : %p", action);
105         model->action_unref(action);
106       }
107       if (xbt_swag_size(model->states.running_action_set)) {
108         DEBUG1("running %s", model->name);
109         running = 1;
110       }
111     }
112   } while (running && surf_solve() >= 0.0);
113
114   DEBUG0("Simulation Terminated");
115
116 }
117
118 #ifdef __BORLANDC__
119 #pragma argsused
120 #endif
121
122 int main(int argc, char **argv)
123 {
124   surf_init(&argc, argv);       /* Initialize some common structures */
125   if (argc == 1) {
126     fprintf(stderr, "Usage : %s platform.txt\n", argv[0]);
127     surf_exit();
128     return 1;
129   }
130   test(argv[1]);
131
132   surf_exit();
133   return 0;
134 }