Logo AND Algorithmique Numérique Distribuée

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