Logo AND Algorithmique Numérique Distribuée

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