Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / teshsuite / s4u / evaluate-get-route-time / evaluate-get-route-time.cpp
1 /* Copyright (c) 2008-2022. 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   e.seal_platform();
26
27   std::vector<simgrid::s4u::Host*> hosts = e.get_all_hosts();
28   int host_count                         = static_cast<int>(e.get_host_count());
29
30   /* Random number initialization */
31   simgrid::xbt::random::set_mersenne_seed(static_cast<int>(xbt_os_time()));
32
33   /* Take random i and j, with i != j */
34   xbt_assert(host_count > 1);
35   int i = simgrid::xbt::random::uniform_int(0, host_count - 1);
36   int j = simgrid::xbt::random::uniform_int(0, host_count - 2);
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 }