Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Taking latencies into account to bound the effective bandwidth.
[simgrid.git] / testsuite / surf / surf_usage.c
1 /* A few basic tests for the surf library                                   */
2
3 /* Authors: Arnaud Legrand                                                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6    under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include <stdio.h>
9 #include "surf/surf.h"
10
11 const char *string_action(e_surf_action_state_t state);
12 const char *string_action(e_surf_action_state_t state)
13 {
14   switch (state) {
15   case (SURF_ACTION_READY):
16     return "SURF_ACTION_READY";
17   case (SURF_ACTION_RUNNING):
18     return "SURF_ACTION_RUNNING";
19   case (SURF_ACTION_FAILED):
20     return "SURF_ACTION_FAILED";
21   case (SURF_ACTION_DONE):
22     return "SURF_ACTION_DONE";
23   case (SURF_ACTION_NOT_IN_THE_SYSTEM):
24     return "SURF_ACTION_NOT_IN_THE_SYSTEM";
25   default:
26     return "INVALID STATE";
27   }
28 }
29
30
31 void test(void);
32 void test(void)
33 {
34   void *cpuA = NULL;
35   void *cpuB = NULL;
36   void *cardA = NULL;
37   void *cardB = NULL;
38   surf_action_t actionA = NULL;
39   surf_action_t actionB = NULL;
40   surf_action_t commAB = NULL;
41   e_surf_action_state_t stateActionA;
42   e_surf_action_state_t stateActionB;
43   xbt_maxmin_float_t now = -1.0;
44
45   surf_cpu_resource_init("platform.txt"); /* Now it is possible to use CPUs */
46   surf_network_resource_init("platform.txt"); /* Now it is possible to use eth0 */
47
48   /*********************** CPU ***********************************/
49   printf("%p \n", surf_cpu_resource);
50   cpuA = surf_cpu_resource->common_public->name_service("Cpu A");
51   cpuB = surf_cpu_resource->common_public->name_service("Cpu B");
52
53   /* Let's check that those two processors exist */
54   printf("%s : %p\n", surf_cpu_resource->common_public->get_resource_name(cpuA), cpuA);
55   printf("%s : %p\n", surf_cpu_resource->common_public->get_resource_name(cpuB), cpuB);
56
57   /* Let's do something on it */
58   actionA = surf_cpu_resource->extension_public->execute(cpuA, 1000.0);
59   actionB = surf_cpu_resource->extension_public->execute(cpuB, 1000.0);
60
61   /* Use whatever calling style you want... */
62   stateActionA = surf_cpu_resource->common_public->action_get_state(actionA);   /* When you know actionA resource type */
63   stateActionB = actionB->resource_type->common_public->action_get_state(actionB);      /* If you're unsure about it's resource type */
64
65   /* And just look at the stat of these tasks */
66   printf("actionA : %p (%s)\n", actionA, string_action(stateActionA));
67   printf("actionB : %p (%s)\n", actionB, string_action(stateActionB));
68
69   /*********************** Network *******************************/
70   printf("%p \n", surf_network_resource);
71   cardA = surf_network_resource->common_public->name_service("Cpu A");
72   cardB = surf_network_resource->common_public->name_service("Cpu B");
73
74   /* Let's check that those two processors exist */
75   printf("%s : %p\n", surf_network_resource->common_public->get_resource_name(cardA), cardA);
76   printf("%s : %p\n", surf_network_resource->common_public->get_resource_name(cardB), cardB);
77
78   /* Let's do something on it */
79   commAB = surf_network_resource->extension_public->communicate(cardA, cardB, 150.0);
80
81   surf_solve(); /* Takes traces into account. Returns 0.0 */
82   do {
83     surf_action_t action = NULL;    
84     now = surf_get_clock();
85     printf("Next Event : " XBT_HEAP_FLOAT_T "\n", now);
86     printf("\t CPU actions\n");
87     while(action=xbt_swag_extract(surf_cpu_resource->common_public->states.failed_action_set)) {
88       printf("\t * Failed : %p\n", action);
89       action->resource_type->common_public->action_free(action);
90     }
91     while(action=xbt_swag_extract(surf_cpu_resource->common_public->states.done_action_set)) {
92       printf("\t * Done : %p\n", action);
93       action->resource_type->common_public->action_free(action);
94     }
95     printf("\t Network actions\n");
96     while(action=xbt_swag_extract(surf_network_resource->common_public->states.failed_action_set)) {
97       printf("\t * Failed : %p\n", action);
98       action->resource_type->common_public->action_free(action);
99     }
100     while(action=xbt_swag_extract(surf_network_resource->common_public->states.done_action_set)) {
101       printf("\t * Done : %p\n", action);
102       action->resource_type->common_public->action_free(action);
103     }
104
105   } while(surf_solve());
106
107   printf("Simulation Terminated\n");
108
109   surf_finalize();
110 }
111
112
113 int main(int argc, char **argv)
114 {
115   surf_init(&argc, argv); /* Initialize some common structures */
116   test();
117   return 0;
118 }