Logo AND Algorithmique Numérique Distribuée

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