Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A meta-resource : workstation is simply a CPU and a network card.
[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
10 #include <stdio.h>
11 #include "surf/surf.h"
12
13 const char *string_action(e_surf_action_state_t state);
14 const char *string_action(e_surf_action_state_t state)
15 {
16   switch (state) {
17   case (SURF_ACTION_READY):
18     return "SURF_ACTION_READY";
19   case (SURF_ACTION_RUNNING):
20     return "SURF_ACTION_RUNNING";
21   case (SURF_ACTION_FAILED):
22     return "SURF_ACTION_FAILED";
23   case (SURF_ACTION_DONE):
24     return "SURF_ACTION_DONE";
25   case (SURF_ACTION_NOT_IN_THE_SYSTEM):
26     return "SURF_ACTION_NOT_IN_THE_SYSTEM";
27   default:
28     return "INVALID STATE";
29   }
30 }
31
32
33 void test(void);
34 void test(void)
35 {
36   void *workstationA = NULL;
37   void *workstationB = NULL;
38   surf_action_t actionA = NULL;
39   surf_action_t actionB = NULL;
40   surf_action_t actionC = NULL;
41   surf_action_t commAB = NULL;
42   e_surf_action_state_t stateActionA;
43   e_surf_action_state_t stateActionB;
44   e_surf_action_state_t stateActionC;
45   xbt_maxmin_float_t now = -1.0;
46
47   surf_workstation_resource_init("platform.txt");
48
49   /*********************** WORKSTATION ***********************************/
50   workstationA =
51       surf_workstation_resource->common_public->name_service("Cpu A");
52   workstationB =
53       surf_workstation_resource->common_public->name_service("Cpu B");
54
55   /* Let's check that those two processors exist */
56   printf("%s : %p\n",
57          surf_workstation_resource->common_public->
58          get_resource_name(workstationA), workstationA);
59   printf("%s : %p\n",
60          surf_workstation_resource->common_public->
61          get_resource_name(workstationB), workstationB);
62
63   /* Let's do something on it */
64   actionA =
65       surf_workstation_resource->extension_public->execute(workstationA,
66                                                            1000.0);
67   actionB =
68       surf_workstation_resource->extension_public->execute(workstationB,
69                                                            1000.0);
70   actionC =
71       surf_workstation_resource->extension_public->sleep(workstationB,
72                                                          7.32);
73
74   commAB =
75       surf_workstation_resource->extension_public->
76       communicate(workstationA, workstationB, 150.0);
77
78   surf_solve();                 /* Takes traces into account. Returns 0.0 */
79   do {
80     surf_action_t action = NULL;
81     int i;
82     surf_resource_t resource = NULL;
83
84     now = surf_get_clock();
85     printf("Next Event : " XBT_HEAP_FLOAT_T "\n", now);
86     
87     xbt_dynar_foreach (resource_list,i,resource) {
88       printf("\t %s actions\n", resource->common_public->name);
89       while (action =
90              xbt_swag_extract(resource->common_public->states.
91                               failed_action_set)) {
92         printf("\t * Failed : %p\n", action);
93         resource->common_public->action_free(action);
94       }
95       while (action =
96              xbt_swag_extract(resource->common_public->states.
97                               done_action_set)) {
98         printf("\t * Done : %p\n", action);
99         resource->common_public->action_free(action);
100       }
101     }
102   } while (surf_solve());
103
104   printf("Simulation Terminated\n");
105
106   surf_finalize();
107 }
108
109
110 int main(int argc, char **argv)
111 {
112   surf_init(&argc, argv);       /* Initialize some common structures */
113   test();
114   return 0;
115 }