Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'pikachuyann/simgrid-xbt_random'
[simgrid.git] / teshsuite / simdag / evaluate-get-route-time / evaluate-get-route-time.c
1 /* Copyright (c) 2008-2020. 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/cluster_backbone.xml 1 2> /tmp/null ; done
8
9
10 #include <stdio.h>
11 #include "simgrid/simdag.h"
12 #include "xbt/xbt_os_time.h"
13
14 #define BILLION  1000000000L;
15
16 int main(int argc, char **argv)
17 {
18   int i;
19   int j;
20   xbt_os_timer_t timer = xbt_os_timer_new();
21
22   SD_init(&argc, argv);
23   SD_create_environment(argv[1]);
24
25   sg_host_t *hosts = sg_host_list();
26   int host_count = sg_host_count();
27
28   /* Random number initialization */
29   srand( (int) (xbt_os_time()*1000) );
30
31   /* Take random i and j, with i != j */
32   xbt_assert(host_count > 1);
33   i = rand() % host_count;
34   j = rand() % (host_count - 1);
35   if (j >= i)
36     j++;
37
38   const_sg_host_t h1 = hosts[i];
39   const_sg_host_t h2 = hosts[j];
40   printf("%d\tand\t%d\t\t",i,j);
41   xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL);
42
43   xbt_os_cputimer_start(timer);
44   sg_host_route(h1, h2, route);
45   xbt_os_cputimer_stop(timer);
46
47   xbt_dynar_free(&route);
48
49   printf("%f\n", xbt_os_timer_elapsed(timer) );
50
51   xbt_free(hosts);
52
53   return 0;
54 }