Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Need to set DIR_IS_LINK for use pwd -P
[simgrid.git] / testsuite / surf / maxmin_bench.c
1 /* A crash few tests for the maxmin library                                 */
2
3 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. 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 #ifdef __BORLANDC__
10 #pragma hdrstop
11 #endif
12
13
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include "surf/maxmin.h"
17 #include "xbt/xbt_os_time.h"
18 #include "xbt/sysdep.h"         /* time manipulation for benchmarking */
19
20 double date;
21
22 double float_random(double max);
23 double float_random(double max)
24 {
25   return ((max * rand()) / (RAND_MAX + 1.0));
26 }
27
28 int int_random(int max);
29 int int_random(int max)
30 {
31   return (int) (((max * 1.0) * rand()) / (RAND_MAX + 1.0));
32 }
33
34 void test(int nb_cnst, int nb_var, int nb_elem);
35 void test(int nb_cnst, int nb_var, int nb_elem)
36 {
37   lmm_system_t Sys = NULL;
38   lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t, nb_cnst);
39   lmm_variable_t *var = xbt_new0(lmm_variable_t, nb_var);
40   int *used = xbt_new0(int, nb_cnst);
41   int i, j, k;
42
43   Sys = lmm_system_new();
44
45   for (i = 0; i < nb_cnst; i++) {
46     cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
47   }
48
49   for (i = 0; i < nb_var; i++) {
50     var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
51     for (j = 0; j < nb_cnst; j++)
52       used[j] = 0;
53     for (j = 0; j < nb_elem; j++) {
54       k = int_random(nb_cnst);
55       if (used[k]) {
56         j--;
57         continue;
58       }
59       lmm_expand(Sys, cnst[k], var[i], float_random(1.0));
60       used[k] = 1;
61     }
62   }
63
64   printf("Starting to solve\n");
65   date = xbt_os_time() * 1000000;
66   lmm_solve(Sys);
67   date = xbt_os_time() * 1000000 - date;
68
69   lmm_system_free(Sys);
70   free(cnst);
71   free(var);
72   free(used);
73 }
74
75 #ifdef __BORLANDC__
76 #pragma argsused
77 #endif
78
79
80 int main(int argc, char **argv)
81 {
82   int nb_cnst = 2000;
83   int nb_var = 2000;
84   int nb_elem = 80;
85   date = xbt_os_time() * 1000000;
86   test(nb_cnst, nb_var, nb_elem);
87   printf("One shot execution time for a total of %d constraints, "
88          "%d variables with %d active constraint each : %g microsecondes \n",
89          nb_cnst, nb_var, nb_elem, date);
90   return 0;
91 }