Selaa lähdekoodia

optionally permit to solve LP in integer mode.

Samuel Thibault 15 vuotta sitten
vanhempi
commit
e5758ea8e4
3 muutettua tiedostoa jossa 29 lisäystä ja 15 poistoa
  1. 3 1
      doc/starpu.texi
  2. 2 2
      include/starpu_bound.h
  3. 24 12
      src/profiling/bound.c

+ 3 - 1
doc/starpu.texi

@@ -1124,7 +1124,9 @@ problem corresponding to the schedule of your tasks. Run it through
 @code{lp_solve} or any other linear programming solver, and that will give you a
 @code{lp_solve} or any other linear programming solver, and that will give you a
 lower bound for the total execution time of your tasks. If StarPU was compiled
 lower bound for the total execution time of your tasks. If StarPU was compiled
 with the glpk library installed, @code{starpu_bound_compute} can be used to
 with the glpk library installed, @code{starpu_bound_compute} can be used to
-solve it immediately and get the optimized minimum.
+solve it immediately and get the optimized minimum. Its @code{integer}
+parameter allows to decide whether integer resolution should be computed
+and returned.
 
 
 The @code{deps} parameter tells StarPU whether to take tasks and implicit data
 The @code{deps} parameter tells StarPU whether to take tasks and implicit data
 dependencies into account. It must be understood that the linear programming
 dependencies into account. It must be understood that the linear programming

+ 2 - 2
include/starpu_bound.h

@@ -29,7 +29,7 @@ void starpu_bound_start(int deps, int prio);
 void starpu_bound_stop(void);
 void starpu_bound_stop(void);
 
 
 /* Get theoretical upper bound (needs glpk support) */
 /* Get theoretical upper bound (needs glpk support) */
-void starpu_bound_compute(double *res);
+void starpu_bound_compute(double *res, double *integer_res, int integer);
 
 
 /* Emit Linear Programming system on output for the recorded tasks in lp format */
 /* Emit Linear Programming system on output for the recorded tasks in lp format */
 void starpu_bound_print_lp(FILE *output);
 void starpu_bound_print_lp(FILE *output);
@@ -38,6 +38,6 @@ void starpu_bound_print_lp(FILE *output);
 void starpu_bound_print_mps(FILE *output);
 void starpu_bound_print_mps(FILE *output);
 
 
 /* Emit statistics of actual execution vs theoretical upper bound */
 /* Emit statistics of actual execution vs theoretical upper bound */
-void starpu_bound_print(FILE *output);
+void starpu_bound_print(FILE *output, int integer);
 
 
 #endif /* __STARPU_BOUND_H__ */
 #endif /* __STARPU_BOUND_H__ */

+ 24 - 12
src/profiling/bound.c

@@ -657,7 +657,7 @@ void starpu_bound_print_mps(FILE *output)
  * GNU Linear Programming Kit backend
  * GNU Linear Programming Kit backend
  */
  */
 #ifdef HAVE_GLPK_H
 #ifdef HAVE_GLPK_H
-static glp_prob *_starpu_bound_glp_resolve(void)
+static glp_prob *_starpu_bound_glp_resolve(int integer)
 {
 {
 	struct bound_task_pool * tp;
 	struct bound_task_pool * tp;
 	int nt; /* Number of different kinds of tasks */
 	int nt; /* Number of different kinds of tasks */
@@ -698,7 +698,8 @@ static glp_prob *_starpu_bound_glp_resolve(void)
 				char name[32];
 				char name[32];
 				snprintf(name, sizeof(name), "w%ut%un", w, t);
 				snprintf(name, sizeof(name), "w%ut%un", w, t);
 				glp_set_col_name(lp, colnum(w, t), name);
 				glp_set_col_name(lp, colnum(w, t), name);
-				glp_set_col_kind(lp, colnum(w, t), GLP_IV);
+				if (integer)
+					glp_set_col_kind(lp, colnum(w, t), GLP_IV);
 				glp_set_col_bnds(lp, colnum(w, t), GLP_LO, 0., 0.);
 				glp_set_col_bnds(lp, colnum(w, t), GLP_LO, 0., 0.);
 			}
 			}
 		glp_set_col_bnds(lp, nw*nt+1, GLP_LO, 0., 0.);
 		glp_set_col_bnds(lp, nw*nt+1, GLP_LO, 0., 0.);
@@ -752,20 +753,23 @@ static glp_prob *_starpu_bound_glp_resolve(void)
 	glp_init_smcp(&parm);
 	glp_init_smcp(&parm);
 	parm.msg_lev = GLP_MSG_OFF;
 	parm.msg_lev = GLP_MSG_OFF;
 	ret = glp_simplex(lp, &parm);
 	ret = glp_simplex(lp, &parm);
-	glp_iocp iocp;
-	glp_init_iocp(&iocp);
-	iocp.msg_lev = GLP_MSG_OFF;
-	glp_intopt(lp, &iocp);
 	if (ret) {
 	if (ret) {
 		glp_delete_prob(lp);
 		glp_delete_prob(lp);
 		lp = NULL;
 		lp = NULL;
+		return NULL;
+	}
+	if (integer) {
+		glp_iocp iocp;
+		glp_init_iocp(&iocp);
+		iocp.msg_lev = GLP_MSG_OFF;
+		glp_intopt(lp, &iocp);
 	}
 	}
 
 
 	return lp;
 	return lp;
 }
 }
 #endif /* HAVE_GLPK_H */
 #endif /* HAVE_GLPK_H */
 
 
-void starpu_bound_print(FILE *output) {
+void starpu_bound_print(FILE *output, int integer) {
 #ifdef HAVE_GLPK_H
 #ifdef HAVE_GLPK_H
 	if (recorddeps) {
 	if (recorddeps) {
 		fprintf(output, "Not supported\n");
 		fprintf(output, "Not supported\n");
@@ -773,7 +777,7 @@ void starpu_bound_print(FILE *output) {
 	}
 	}
 
 
 	PTHREAD_MUTEX_LOCK(&mutex);
 	PTHREAD_MUTEX_LOCK(&mutex);
-	glp_prob *lp = _starpu_bound_glp_resolve();
+	glp_prob *lp = _starpu_bound_glp_resolve(integer);
 	if (lp) {
 	if (lp) {
 		struct bound_task_pool * tp;
 		struct bound_task_pool * tp;
 		int t, w;
 		int t, w;
@@ -782,14 +786,20 @@ void starpu_bound_print(FILE *output) {
 
 
 		nw = starpu_worker_get_count();
 		nw = starpu_worker_get_count();
 
 
-		tmax = glp_get_obj_val(lp);
+		if (integer)
+			tmax = glp_mip_obj_val(lp);
+		else
+			tmax = glp_get_obj_val(lp);
 
 
 		fprintf(output, "Theoretical minimum execution time: %f ms\n", tmax);
 		fprintf(output, "Theoretical minimum execution time: %f ms\n", tmax);
 
 
 		for (t = 0, tp = task_pools; tp; t++, tp = tp->next) {
 		for (t = 0, tp = task_pools; tp; t++, tp = tp->next) {
 			fprintf(output, "%s key %x\n", tp->cl->model->symbol, (unsigned) tp->footprint);
 			fprintf(output, "%s key %x\n", tp->cl->model->symbol, (unsigned) tp->footprint);
 			for (w = 0; w < nw; w++)
 			for (w = 0; w < nw; w++)
-				fprintf(output, "\tw%ut%un %f", w, t, glp_mip_col_val(lp, colnum(w, t)));
+				if (integer)
+					fprintf(output, "\tw%ut%un %f", w, t, glp_mip_col_val(lp, colnum(w, t)));
+				else
+					fprintf(output, "\tw%ut%un %f", w, t, glp_get_col_prim(lp, colnum(w, t)));
 			fprintf(output, "\n");
 			fprintf(output, "\n");
 		}
 		}
 
 
@@ -803,7 +813,7 @@ void starpu_bound_print(FILE *output) {
 #endif /* HAVE_GLPK_H */
 #endif /* HAVE_GLPK_H */
 }
 }
 
 
-void starpu_bound_compute(double *res) {
+void starpu_bound_compute(double *res, double *integer_res, int integer) {
 #ifdef HAVE_GLPK_H
 #ifdef HAVE_GLPK_H
 	double ret;
 	double ret;
 
 
@@ -813,9 +823,11 @@ void starpu_bound_compute(double *res) {
 	}
 	}
 
 
 	PTHREAD_MUTEX_LOCK(&mutex);
 	PTHREAD_MUTEX_LOCK(&mutex);
-	glp_prob *lp = _starpu_bound_glp_resolve();
+	glp_prob *lp = _starpu_bound_glp_resolve(integer);
 	if (lp) {
 	if (lp) {
 		ret = glp_get_obj_val(lp);
 		ret = glp_get_obj_val(lp);
+		if (integer)
+			*integer_res = glp_mip_obj_val(lp);
 		glp_delete_prob(lp);
 		glp_delete_prob(lp);
 	} else
 	} else
 		ret = 0.;
 		ret = 0.;