1 /* A crash few tests for the maxmin library */
3 /* Copyright (c) 2004-2015. The SimGrid Team.
4 * All rights reserved. */
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. */
9 #include "surf/maxmin.h"
10 #include "xbt/module.h"
11 #include "xbt/xbt_os_time.h"
12 #include "xbt/sysdep.h" /* time manipulation for benchmarking */
19 double float_random(double max);
20 double float_random(double max)
22 return ((max * rand()) / (RAND_MAX + 1.0));
25 int int_random(int max);
26 int int_random(int max)
28 return (int) (((max * 1.0) * rand()) / (RAND_MAX + 1.0));
31 void test(int nb_cnst, int nb_var, int nb_elem, int pw_base_limit, int pw_max_limit, float rate_no_limit, int max_share);
32 void test(int nb_cnst, int nb_var, int nb_elem, int pw_base_limit, int pw_max_limit, float rate_no_limit, int max_share)
34 lmm_system_t Sys = NULL;
35 lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t, nb_cnst);
36 lmm_variable_t *var = xbt_new0(lmm_variable_t, nb_var);
37 int *used = xbt_new0(int, nb_cnst);
40 Sys = lmm_system_new(1);
42 for (i = 0; i < nb_cnst; i++) {
43 cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
44 if(rate_no_limit>float_random(1.0))
45 //Look at what happens when there is no concurrency limit
48 //Badly logarithmically random concurrency limit in [2^pw_base_limit+1,2^pw_base_limit+2^pw_max_limit]
49 l=(1<<pw_base_limit)+(1<<int_random(pw_max_limit));
51 lmm_constraint_concurrency_limit_set(cnst[i],l );
54 for (i = 0; i < nb_var; i++) {
55 var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
56 //Have a few variables with a concurrency share of two (e.g. cross-traffic in some cases)
57 lmm_variable_concurrency_share_set(var[i],1+int_random(max_share));
59 for (j = 0; j < nb_cnst; j++)
61 for (j = 0; j < nb_elem; j++) {
62 k = int_random(nb_cnst);
67 lmm_expand(Sys, cnst[k], var[i], float_random(1.0));
72 printf("Starting to solve\n");
73 date = xbt_os_time() * 1000000;
75 date = xbt_os_time() * 1000000 - date;
77 printf("Max concurrency:\n");
79 for (i = 0; i < nb_cnst; i++) {
80 j=lmm_constraint_concurrency_maximum_get(cnst[i]);
81 k=lmm_constraint_concurrency_limit_get(cnst[i]);
82 xbt_assert(k<0 || j<=k);
85 printf("(%i):%i/%i ",i,j,k);
86 lmm_constraint_concurrency_maximum_reset(cnst[i]);
87 xbt_assert(!lmm_constraint_concurrency_maximum_get(cnst[i]));
91 printf("\nTotal maximum concurrency is %i\n",l);
95 for (i = 0; i < nb_var; i++)
96 lmm_variable_free(Sys, var[i]);
104 int main(int argc, char **argv)
111 float rate_no_limit=0.2;
112 int max_share=1<<(pw_base_limit/2+1);
114 //If you want to test concurrency, you need nb_elem >> 2^pw_base_limit:
115 nb_elem= (1<<pw_base_limit)+(1<<(8*pw_max_limit/10));
116 //Otherwise, just set it to a constant value (and set rate_no_limit to 1.0):
119 xbt_init(&argc, argv);
120 date = xbt_os_time() * 1000000;
121 test(nb_cnst, nb_var, nb_elem, pw_base_limit, pw_max_limit, rate_no_limit,max_share);
122 printf("One shot execution time for a total of %d constraints, "
123 "%d variables with %d active constraint each : %g microseconds \n",
124 nb_cnst, nb_var, nb_elem, date);