Logo AND Algorithmique Numérique Distribuée

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