Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Each action can now have a maximum duration. That is a convenient way to
[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 <sys/time.h>
14
15 long date;
16
17 /* Pour le bench */
18 long us_time(void);
19 long us_time(void)
20 {
21   struct timeval start;
22   gettimeofday(&start, NULL);
23
24   return (start.tv_sec * 1000000 + start.tv_usec);
25 }
26
27
28 xbt_maxmin_float_t float_random(xbt_maxmin_float_t max);
29 xbt_maxmin_float_t float_random(xbt_maxmin_float_t max)
30 {
31   return ((max * rand()) / (RAND_MAX + 1.0));
32 }
33
34 int int_random(int max);
35 int int_random(int max)
36 {
37   return (int) (((max * 1.0) * rand()) / (RAND_MAX + 1.0));
38 }
39
40 void test(int nb_cnst, int nb_var, int nb_elem);
41 void test(int nb_cnst, int nb_var, int nb_elem)
42 {
43   lmm_system_t Sys = NULL;
44   lmm_constraint_t *cnst = calloc(nb_cnst, sizeof(lmm_constraint_t));
45   lmm_variable_t *var = calloc(nb_var, sizeof(lmm_variable_t));
46   int *used = calloc(nb_cnst, sizeof(int));
47   int i, j, k;
48
49   Sys = lmm_system_new();
50
51   for (i = 0; i < nb_cnst; i++) {
52     cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
53   }
54
55   for (i = 0; i < nb_var; i++) {
56     var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
57     for (j = 0; j < nb_cnst; j++)
58       used[j] = 0;
59     for (j = 0; j < nb_elem; j++) {
60       k = int_random(nb_cnst);
61       if (used[k]) {
62         j--;
63         continue;
64       }
65       lmm_expand(Sys, cnst[k], var[i], float_random(1.0));
66       used[k] = 1;
67     }
68   }
69
70   date = us_time();
71   lmm_solve(Sys);
72   date = us_time() - date;
73
74   lmm_system_free(Sys);
75   free(cnst);
76   free(var);
77   free(used);
78 }
79
80
81 int main(int argc, char **argv)
82 {
83   int nb_cnst = 2000;
84   int nb_var = 2000;
85   int nb_elem = 20;
86   date = us_time();
87   test(nb_cnst, nb_var, nb_elem);
88   printf("One shot execution time for a total of %d constraints, "
89          "%d variables with %d active constraint each : %ld microsecondes \n",
90          nb_cnst, nb_var, nb_elem, date);
91   return 0;
92 }