Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ensure that I don't 'fix' it by accident in the future
[simgrid.git] / teshsuite / simdag / evaluate-get-route-time / evaluate-get-route-time.c
index c8bf42a..6ce4fd9 100644 (file)
@@ -1,10 +1,10 @@
-/* Copyright (c) 2008-2015. The SimGrid Team.
+/* Copyright (c) 2008-2020. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-//for i in $(seq 1 100); do teshsuite/simdag/platforms/evaluate_get_route_time ../examples/platforms/cluster.xml 1 2> /tmp/null ; done
+//for i in $(seq 1 100); do teshsuite/simdag/platforms/evaluate_get_route_time ../examples/platforms/cluster_backbone.xml 1 2> /tmp/null ; done
 
 
 #include <stdio.h>
@@ -28,13 +28,15 @@ int main(int argc, char **argv)
   /* Random number initialization */
   srand( (int) (xbt_os_time()*1000) );
 
-  do {
-    i = rand()%host_count;
-    j = rand()%host_count;
-  } while(i==j);
+  /* Take random i and j, with i != j */
+  xbt_assert(host_count > 1);
+  i = rand() % host_count;
+  j = rand() % (host_count - 1);
+  if (j >= i) // '>=' is not a bug: j is uniform on host_count-1 values, and shifted on need to maintain uniform random
+    j++;
 
-  sg_host_t h1 = hosts[i];
-  sg_host_t h2 = hosts[j];
+  const_sg_host_t h1 = hosts[i];
+  const_sg_host_t h2 = hosts[j];
   printf("%d\tand\t%d\t\t",i,j);
   xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL);
 
@@ -47,7 +49,6 @@ int main(int argc, char **argv)
   printf("%f\n", xbt_os_timer_elapsed(timer) );
 
   xbt_free(hosts);
-  SD_exit();
 
   return 0;
 }