Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Those two files are now compatible.
[simgrid.git] / teshsuite / simdag / platforms / Evaluate_get_route_time.c
1 /* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 //for i in $(seq 1 100); do teshsuite/simdag/platforms/evaluate_get_route_time ../examples/platforms/One_cluster.xml 1 2> /tmp/null ; done
8
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "simdag/simdag.h"
13 #include "surf/surf_private.h"
14 #include <time.h>
15
16 #define BILLION  1000000000L;
17 extern routing_global_t global_routing;
18
19 int main(int argc, char **argv)
20 {
21         SD_workstation_t w1, w2;
22         const SD_workstation_t *workstations;
23         int i, j;
24         int list_size;
25         struct timespec start, stop;
26         double accum;
27
28         /* initialisation of SD */
29         SD_init(&argc, argv);
30
31         /* creation of the environment */
32         SD_create_environment(argv[1]);
33
34         workstations = SD_workstation_get_list();
35         list_size = SD_workstation_get_number();
36
37         unsigned int seed;
38         struct timespec time;
39         //clock_gettime( CLOCK_REALTIME, &time);
40 #if _POSIX_TIMERS > 0
41       clock_gettime(CLOCK_REALTIME, &time);
42 #else
43       struct timeval tv;
44       gettimeofday(&tv, NULL);
45       time.tv_sec = tv.tv_sec;
46       time.tv_nsec = tv.tv_usec*1000;
47 #endif
48         seed = time.tv_nsec;
49
50         srand(seed);
51
52         do{
53                 i = rand()%list_size;
54                 j = rand()%list_size;
55         }while(i==j);
56
57         w1 = workstations[i];
58         w2 = workstations[j];
59         printf("%d\tand\t%d\t\t",i,j);
60
61 #if _POSIX_TIMERS > 0
62         if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) {
63         perror( "clock gettime" );
64         return EXIT_FAILURE;
65         }
66 #else
67       gettimeofday(&tv, NULL);
68       start.tv_sec = tv.tv_sec;
69       start.tv_nsec = tv.tv_usec*1000;
70 #endif
71
72         SD_route_get_list(w1, w2);
73
74 #if _POSIX_TIMERS > 0
75         if( clock_gettime( CLOCK_REALTIME, &stop) == -1 ) {
76         perror( "clock gettime" );
77         return EXIT_FAILURE;
78         }
79 #else
80       gettimeofday(&tv, NULL);
81       stop.tv_sec = tv.tv_sec;
82       stop.tv_nsec = tv.tv_usec*1000;
83 #endif
84
85         accum = ( stop.tv_sec - start.tv_sec )
86            + (double)( stop.tv_nsec - start.tv_nsec )
87                  / (double)BILLION;
88         printf("%lf\n", accum);
89
90         SD_exit();
91
92         return 0;
93 }