Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2d62eab51897d5bd0ea51cbbab7cf9fffb5d68e1
[simgrid.git] / teshsuite / s4u / evaluate-get-route-time / evaluate-get-route-time.cpp
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 /*
8 for i in $(seq 1 20); do
9   teshsuite/s4u/evaluate-get-route-time/evaluate-get-route-time examples/platforms/cluster_backbone.xml 1 2> /tmp/null
10   sleep 1
11 done
12 */
13
14 #include "simgrid/s4u.hpp"
15 #include "xbt/xbt_os_time.h"
16 #include <stdio.h>
17
18 int main(int argc, char** argv)
19 {
20   int i;
21   int j;
22   xbt_os_timer_t timer = xbt_os_timer_new();
23
24   simgrid::s4u::Engine e(&argc, argv);
25   e.load_platform(argv[1]);
26
27   std::vector<simgrid::s4u::Host*> hosts = e.get_all_hosts();
28   int host_count                         = e.get_host_count();
29
30   /* Random number initialization */
31   srand(static_cast<int>(xbt_os_time()));
32
33   /* Take random i and j, with i != j */
34   xbt_assert(host_count > 1);
35   i = rand() % host_count;
36   j = rand() % (host_count - 1);
37   if (j >= i) // '>=' is not a bug: j is uniform on host_count-1 values, and shifted on need to maintain uniform random
38     j++;
39
40   printf("%d\tand\t%d\t\t", i, j);
41
42   std::vector<simgrid::s4u::Link*> route;
43
44   xbt_os_cputimer_start(timer);
45   hosts[i]->route_to(hosts[j], route, nullptr);
46   xbt_os_cputimer_stop(timer);
47
48   printf("%f\n", xbt_os_timer_elapsed(timer));
49
50   return 0;
51 }