|
@@ -28,13 +28,9 @@ struct ispeed_lp_data
|
|
int *workers;
|
|
int *workers;
|
|
};
|
|
};
|
|
|
|
|
|
-/*
|
|
|
|
- * GNU Linear Programming Kit backend
|
|
|
|
- */
|
|
|
|
#ifdef STARPU_HAVE_GLPK_H
|
|
#ifdef STARPU_HAVE_GLPK_H
|
|
-#include <glpk.h>
|
|
|
|
-static double _glp_resolve (int ns, int nw, double final_w_in_s[ns][nw],
|
|
|
|
- unsigned is_integer, double tmax, void *specific_data)
|
|
|
|
|
|
+static double _compute_workers_distrib(int ns, int nw, double final_w_in_s[ns][nw],
|
|
|
|
+ unsigned is_integer, double tmax, void *specific_data)
|
|
{
|
|
{
|
|
struct ispeed_lp_data *sd = (struct ispeed_lp_data *)specific_data;
|
|
struct ispeed_lp_data *sd = (struct ispeed_lp_data *)specific_data;
|
|
|
|
|
|
@@ -43,220 +39,11 @@ static double _glp_resolve (int ns, int nw, double final_w_in_s[ns][nw],
|
|
|
|
|
|
double **final_flops_on_w = sd->flops_on_w;
|
|
double **final_flops_on_w = sd->flops_on_w;
|
|
|
|
|
|
- double w_in_s[ns][nw];
|
|
|
|
- double flops_on_w[ns][nw];
|
|
|
|
-
|
|
|
|
- int w, s;
|
|
|
|
- glp_prob *lp;
|
|
|
|
-
|
|
|
|
-// printf("try with tmax %lf\n", tmax);
|
|
|
|
- lp = glp_create_prob();
|
|
|
|
- glp_set_prob_name(lp, "StarPU theoretical bound");
|
|
|
|
- glp_set_obj_dir(lp, GLP_MAX);
|
|
|
|
- glp_set_obj_name(lp, "total execution time");
|
|
|
|
-
|
|
|
|
- {
|
|
|
|
- int ne = 5 * ns * nw /* worker execution time */
|
|
|
|
- + 1; /* glp dumbness */
|
|
|
|
- int n = 1;
|
|
|
|
- int ia[ne], ja[ne];
|
|
|
|
- double ar[ne];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /* Variables: number of flops assigned to worker w in context s, and
|
|
|
|
- the acknwoledgment that the worker w belongs to the context s */
|
|
|
|
- glp_add_cols(lp, 2*nw*ns);
|
|
|
|
-#define colnum(w, s) ((s)*nw+(w)+1)
|
|
|
|
- for(s = 0; s < ns; s++)
|
|
|
|
- for(w = 0; w < nw; w++)
|
|
|
|
- glp_set_obj_coef(lp, nw*ns+colnum(w,s), 1.);
|
|
|
|
-
|
|
|
|
- for(s = 0; s < ns; s++)
|
|
|
|
- for(w = 0; w < nw; w++)
|
|
|
|
- {
|
|
|
|
- char name[32];
|
|
|
|
- snprintf(name, sizeof(name), "flopsw%ds%dn", w, s);
|
|
|
|
- glp_set_col_name(lp, colnum(w,s), name);
|
|
|
|
- glp_set_col_bnds(lp, colnum(w,s), GLP_LO, 0., 0.);
|
|
|
|
-
|
|
|
|
- snprintf(name, sizeof(name), "w%ds%dn", w, s);
|
|
|
|
- glp_set_col_name(lp, nw*ns+colnum(w,s), name);
|
|
|
|
- if (is_integer)
|
|
|
|
- {
|
|
|
|
- glp_set_col_kind(lp, nw*ns+colnum(w, s), GLP_IV);
|
|
|
|
- glp_set_col_bnds(lp, nw*ns+colnum(w,s), GLP_DB, 0, 1);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- glp_set_col_bnds(lp, nw*ns+colnum(w,s), GLP_DB, 0.0, 1.0);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- int curr_row_idx = 0;
|
|
|
|
- /* Total worker execution time */
|
|
|
|
- glp_add_rows(lp, nw*ns);
|
|
|
|
-
|
|
|
|
- /*nflops[s][w]/v[s][w] < x[s][w]*tmax */
|
|
|
|
- for(s = 0; s < ns; s++)
|
|
|
|
- {
|
|
|
|
- for (w = 0; w < nw; w++)
|
|
|
|
- {
|
|
|
|
- char name[32], title[64];
|
|
|
|
- starpu_worker_get_name(w, name, sizeof(name));
|
|
|
|
- snprintf(title, sizeof(title), "worker %s", name);
|
|
|
|
- glp_set_row_name(lp, curr_row_idx+s*nw+w+1, title);
|
|
|
|
-
|
|
|
|
- /* nflosp[s][w] */
|
|
|
|
- ia[n] = curr_row_idx+s*nw+w+1;
|
|
|
|
- ja[n] = colnum(w, s);
|
|
|
|
- ar[n] = 1 / speed[s][w];
|
|
|
|
-
|
|
|
|
- n++;
|
|
|
|
-
|
|
|
|
- /* x[s][w] = 1 | 0 */
|
|
|
|
- ia[n] = curr_row_idx+s*nw+w+1;
|
|
|
|
- ja[n] = nw*ns+colnum(w,s);
|
|
|
|
- ar[n] = (-1) * tmax;
|
|
|
|
- n++;
|
|
|
|
- glp_set_row_bnds(lp, curr_row_idx+s*nw+w+1, GLP_UP, 0.0, 0.0);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- curr_row_idx += nw*ns;
|
|
|
|
-
|
|
|
|
- /* sum(flops[s][w]) = flops[s] */
|
|
|
|
- glp_add_rows(lp, ns);
|
|
|
|
- for (s = 0; s < ns; s++)
|
|
|
|
- {
|
|
|
|
- char name[32], title[64];
|
|
|
|
- starpu_worker_get_name(w, name, sizeof(name));
|
|
|
|
- snprintf(title, sizeof(title), "flops %lf ctx%d", flops[s], s);
|
|
|
|
- glp_set_row_name(lp, curr_row_idx+s+1, title);
|
|
|
|
- for (w = 0; w < nw; w++)
|
|
|
|
- {
|
|
|
|
- ia[n] = curr_row_idx+s+1;
|
|
|
|
- ja[n] = colnum(w, s);
|
|
|
|
- ar[n] = 1;
|
|
|
|
- n++;
|
|
|
|
- }
|
|
|
|
- glp_set_row_bnds(lp, curr_row_idx+s+1, GLP_FX, flops[s], flops[s]);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- curr_row_idx += ns;
|
|
|
|
-
|
|
|
|
- /* sum(x[s][w]) = 1 */
|
|
|
|
- glp_add_rows(lp, nw);
|
|
|
|
- for (w = 0; w < nw; w++)
|
|
|
|
- {
|
|
|
|
- char name[32], title[64];
|
|
|
|
- starpu_worker_get_name(w, name, sizeof(name));
|
|
|
|
- snprintf(title, sizeof(title), "w%x", w);
|
|
|
|
- glp_set_row_name(lp, curr_row_idx+w+1, title);
|
|
|
|
- for(s = 0; s < ns; s++)
|
|
|
|
- {
|
|
|
|
- ia[n] = curr_row_idx+w+1;
|
|
|
|
- ja[n] = nw*ns+colnum(w,s);
|
|
|
|
- ar[n] = 1;
|
|
|
|
- n++;
|
|
|
|
- }
|
|
|
|
- if(is_integer)
|
|
|
|
- glp_set_row_bnds(lp, curr_row_idx+w+1, GLP_FX, 1, 1);
|
|
|
|
- else
|
|
|
|
- glp_set_row_bnds(lp, curr_row_idx+w+1, GLP_FX, 1.0, 1.0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- curr_row_idx += nw;
|
|
|
|
-
|
|
|
|
- /* sum(nflops[s][w]) > 0*/
|
|
|
|
- glp_add_rows(lp, nw);
|
|
|
|
- for (w = 0; w < nw; w++)
|
|
|
|
- {
|
|
|
|
- char name[32], title[64];
|
|
|
|
- starpu_worker_get_name(w, name, sizeof(name));
|
|
|
|
- snprintf(title, sizeof(title), "flopsw%x", w);
|
|
|
|
- glp_set_row_name(lp, curr_row_idx+w+1, title);
|
|
|
|
- for(s = 0; s < ns; s++)
|
|
|
|
- {
|
|
|
|
- ia[n] = curr_row_idx+w+1;
|
|
|
|
- ja[n] = colnum(w,s);
|
|
|
|
- ar[n] = 1;
|
|
|
|
- n++;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- glp_set_row_bnds(lp, curr_row_idx+w+1, GLP_LO, 0.1, 0.);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(n != ne)
|
|
|
|
- printf("ns= %d nw = %d n = %d ne = %d\n", ns, nw, n, ne);
|
|
|
|
- STARPU_ASSERT(n == ne);
|
|
|
|
-
|
|
|
|
- glp_load_matrix(lp, ne-1, ia, ja, ar);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- glp_smcp parm;
|
|
|
|
- glp_init_smcp(&parm);
|
|
|
|
- parm.msg_lev = GLP_MSG_OFF;
|
|
|
|
- int ret = glp_simplex(lp, &parm);
|
|
|
|
- if (ret)
|
|
|
|
- {
|
|
|
|
- glp_delete_prob(lp);
|
|
|
|
- lp = NULL;
|
|
|
|
- return 0.0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (is_integer)
|
|
|
|
- {
|
|
|
|
- glp_iocp iocp;
|
|
|
|
- glp_init_iocp(&iocp);
|
|
|
|
- iocp.msg_lev = GLP_MSG_OFF;
|
|
|
|
- glp_intopt(lp, &iocp);
|
|
|
|
- int stat = glp_mip_status(lp);
|
|
|
|
- /* if we don't have a solution return */
|
|
|
|
- if(stat == GLP_NOFEAS)
|
|
|
|
- {
|
|
|
|
- glp_delete_prob(lp);
|
|
|
|
- lp = NULL;
|
|
|
|
- return 0.0;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int stat = glp_get_prim_stat(lp);
|
|
|
|
- /* if we don't have a solution return */
|
|
|
|
- if(stat == GLP_NOFEAS)
|
|
|
|
- {
|
|
|
|
- glp_delete_prob(lp);
|
|
|
|
- lp = NULL;
|
|
|
|
- return 0.0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- double res = glp_get_obj_val(lp);
|
|
|
|
-
|
|
|
|
- for(s = 0; s < ns; s++)
|
|
|
|
- for(w = 0; w < nw; w++)
|
|
|
|
- {
|
|
|
|
- flops_on_w[s][w] = glp_get_col_prim(lp, colnum(w, s));
|
|
|
|
- if (is_integer)
|
|
|
|
- w_in_s[s][w] = (double)glp_mip_col_val(lp, nw*ns+colnum(w, s));
|
|
|
|
- else
|
|
|
|
- w_in_s[s][w] = glp_get_col_prim(lp, nw*ns+colnum(w,s));
|
|
|
|
-// printf("w_in_s[s%d][w%d] = %lf flops[s%d][w%d] = %lf \n", s, w, w_in_s[s][w], s, w, flops_on_w[s][w]);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- glp_delete_prob(lp);
|
|
|
|
- for(s = 0; s < ns; s++)
|
|
|
|
- for(w = 0; w < nw; w++)
|
|
|
|
- {
|
|
|
|
- final_w_in_s[s][w] = w_in_s[s][w];
|
|
|
|
- final_flops_on_w[s][w] = flops_on_w[s][w];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return res;
|
|
|
|
|
|
+ return sc_hypervisor_lp_simulate_distrib_flops_on_sample(ns, nw, final_w_in_s, is_integer, tmax, speed, flops, final_flops_on_w);
|
|
}
|
|
}
|
|
|
|
|
|
static unsigned _compute_flops_distribution_over_ctxs(int ns, int nw, double w_in_s[ns][nw], double **flops_on_w, unsigned *sched_ctxs, int *workers)
|
|
static unsigned _compute_flops_distribution_over_ctxs(int ns, int nw, double w_in_s[ns][nw], double **flops_on_w, unsigned *sched_ctxs, int *workers)
|
|
{
|
|
{
|
|
-// double flops[ns];
|
|
|
|
-// double speed[ns][nw];
|
|
|
|
double *flops = (double*)malloc(ns*sizeof(double));
|
|
double *flops = (double*)malloc(ns*sizeof(double));
|
|
double **speed = (double **)malloc(ns*sizeof(double*));
|
|
double **speed = (double **)malloc(ns*sizeof(double*));
|
|
int i;
|
|
int i;
|
|
@@ -312,7 +99,7 @@ static unsigned _compute_flops_distribution_over_ctxs(int ns, int nw, double w_i
|
|
specific_data.workers = workers;
|
|
specific_data.workers = workers;
|
|
|
|
|
|
unsigned found_sol = sc_hypervisor_lp_execute_dichotomy(ns, nw, w_in_s, 1, (void*)&specific_data,
|
|
unsigned found_sol = sc_hypervisor_lp_execute_dichotomy(ns, nw, w_in_s, 1, (void*)&specific_data,
|
|
- tmin, tmax, smallest_tmax, _glp_resolve);
|
|
|
|
|
|
+ tmin, tmax, smallest_tmax, _compute_workers_distrib);
|
|
|
|
|
|
for(i = 0; i < ns; i++)
|
|
for(i = 0; i < ns; i++)
|
|
free(speed[i]);
|
|
free(speed[i]);
|
|
@@ -416,7 +203,6 @@ static void ispeed_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
|
|
if(sc_hypervisor_check_idle(sched_ctx, worker))
|
|
if(sc_hypervisor_check_idle(sched_ctx, worker))
|
|
{
|
|
{
|
|
_try_resizing(NULL, -1, NULL, -1);
|
|
_try_resizing(NULL, -1, NULL, -1);
|
|
-// sc_hypervisor_move_workers(sched_ctx, 3 - sched_ctx, &worker, 1, 1);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
|
|
starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
|