Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fixed a dummy bug and removed an assertion that was over-testing
[simgrid.git] / teshsuite / surf / maxmin_bench / maxmin_bench.c
1 /* A crash few tests for the maxmin library                                 */
2
3 /* Copyright (c) 2004-2015. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "surf/maxmin.h"
10 #include "xbt/module.h"
11 #include "xbt/xbt_os_time.h"
12 #include "xbt/sysdep.h"         /* time manipulation for benchmarking */
13
14 #include <stdlib.h>
15 #include <stdio.h>
16
17 double date;
18
19 double float_random(double max);
20 double float_random(double max)
21 {
22   return ((max * rand()) / (RAND_MAX + 1.0));
23 }
24
25 int int_random(int max);
26 int int_random(int max)
27 {
28   return (int) (((max * 1.0) * rand()) / (RAND_MAX + 1.0));
29 }
30
31 void test(int nb_cnst, int nb_var, int nb_elem);
32 void test(int nb_cnst, int nb_var, int nb_elem)
33 {
34   lmm_system_t Sys = NULL;
35   lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t, nb_cnst);
36   lmm_variable_t *var = xbt_new0(lmm_variable_t, nb_var);
37   int *used = xbt_new0(int, nb_cnst);
38   int i, j, k;
39
40   Sys = lmm_system_new(1);
41
42   for (i = 0; i < nb_cnst; i++) {
43     cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
44   }
45
46   for (i = 0; i < nb_var; i++) {
47     var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
48     for (j = 0; j < nb_cnst; j++)
49       used[j] = 0;
50     for (j = 0; j < nb_elem; j++) {
51       k = int_random(nb_cnst);
52       if (used[k]) {
53         j--;
54         continue;
55       }
56       lmm_expand(Sys, cnst[k], var[i], float_random(1.0));
57       used[k] = 1;
58     }
59   }
60
61   printf("Starting to solve\n");
62   date = xbt_os_time() * 1000000;
63   lmm_solve(Sys);
64   date = xbt_os_time() * 1000000 - date;
65
66   for (i = 0; i < nb_var; i++)
67     lmm_variable_free(Sys, var[i]);
68   lmm_system_free(Sys);
69   free(cnst);
70   free(var);
71   free(used);
72 }
73
74 int main(int argc, char **argv)
75 {
76   int nb_cnst = 2000;
77   int nb_var = 2000;
78   int nb_elem = 80;
79   xbt_init(&argc, argv);
80   date = xbt_os_time() * 1000000;
81   test(nb_cnst, nb_var, nb_elem);
82   printf("One shot execution time for a total of %d constraints, "
83          "%d variables with %d active constraint each : %g microsecondes \n",
84          nb_cnst, nb_var, nb_elem, date);
85   return 0;
86 }