Logo AND Algorithmique Numérique Distribuée

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