瀏覽代碼

optionally permit to solve LP in integer mode.

Samuel Thibault 15 年之前
父節點
當前提交
e5758ea8e4
共有 3 個文件被更改,包括 29 次插入15 次删除
  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
 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
-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
 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);
 
 /* 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 */
 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);
 
 /* 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__ */

+ 24 - 12
src/profiling/bound.c

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