浏览代码

add starpu_bound_compute

Samuel Thibault 14 年之前
父节点
当前提交
0529e72b29
共有 3 个文件被更改,包括 52 次插入17 次删除
  1. 4 5
      examples/lu/lu_example.c
  2. 3 0
      include/starpu_bound.h
  3. 45 12
      src/profiling/bound.c

+ 4 - 5
examples/lu/lu_example.c

@@ -318,12 +318,11 @@ int main(int argc, char **argv)
 	}
 
 	if (bound) {
+		double min;
 		starpu_bound_stop();
-#ifdef HAVE_GLPK_H
-		starpu_bound_print(stderr);
-#else
-		starpu_bound_print_lp(stderr);
-#endif
+		starpu_bound_compute(&min);
+		if (min != 0.)
+			fprintf(stderr, "theoretical min: %lf ms\n", min);
 	}
 
 	if (check)

+ 3 - 0
include/starpu_bound.h

@@ -27,6 +27,9 @@ void starpu_bound_start(void);
 /* Stop recording tasks */
 void starpu_bound_stop(void);
 
+/* Get theoretical upper bound (needs glpk support) */
+void starpu_bound_compute(double *res);
+
 /* Emit Linear Programming system on output for the recorded tasks in lp format */
 void starpu_bound_print_lp(FILE *output);
 

+ 45 - 12
src/profiling/bound.c

@@ -273,19 +273,16 @@ void starpu_bound_print_mps(FILE *output)
 /*
  * GNU Linear Programming Kit backend
  */
-void starpu_bound_print(FILE *output)
-{
 #ifdef HAVE_GLPK_H
+static glp_prob *_starpu_bound_glp_resolve(void)
+{
 	struct task_pool * tp;
 	int nt; /* Number of different kinds of tasks */
 	int nw; /* Number of different workers */
 	int t, w;
 	glp_prob *lp;
-	double tmax;
 	int ret;
 
-	PTHREAD_MUTEX_LOCK(&mutex);
-
 	nw = starpu_worker_get_count();
 	nt = 0;
 	for (tp = task_pools; tp; tp = tp->next)
@@ -301,7 +298,7 @@ void starpu_bound_print(FILE *output)
 		int ne =
 			nw * (nt+1)	/* worker execution time */
 			+ nt * nw
-			+ 1; /* glpk dumbness */
+			+ 1; /* glp dumbness */
 		int n = 1;
 		int ia[ne], ja[ne];
 		double ar[ne];
@@ -310,7 +307,7 @@ void starpu_bound_print(FILE *output)
 
 		/* Variables: number of tasks i assigned to worker j, and tmax */
 		glp_add_cols(lp, nw*nt+1);
-#define colnum(w, t) ((w)*nt+(t)+1)
+#define colnum(w, t) ((t)*nw+(w)+1)
 		glp_set_obj_coef(lp, nw*nt+1, 1.);
 
 		for (w = 0; w < nw; w++)
@@ -370,8 +367,26 @@ void starpu_bound_print(FILE *output)
 	parm.msg_lev = GLP_MSG_OFF;
 	ret = glp_simplex(lp, &parm);
 	if (ret) {
-		fprintf(output, "simplex failed: %d\n", ret);
-	} else {
+		glp_delete_prob(lp);
+		lp = NULL;
+	}
+
+	return lp;
+}
+#endif /* HAVE_GLPK_H */
+
+void starpu_bound_print(FILE *output) {
+#ifdef HAVE_GLPK_H
+	PTHREAD_MUTEX_LOCK(&mutex);
+	glp_prob *lp = _starpu_bound_glp_resolve();
+	if (lp) {
+		struct task_pool * tp;
+		int t, w;
+		int nw; /* Number of different workers */
+		double tmax;
+
+		nw = starpu_worker_get_count();
+
 		tmax = glp_get_obj_val(lp);
 
 		fprintf(output, "Theoretical minimum execution time: %f ms\n", tmax);
@@ -382,12 +397,30 @@ void starpu_bound_print(FILE *output)
 				fprintf(output, "\tw%dt%d %f", w, t, glp_get_col_prim(lp, colnum(w, t)));
 			fprintf(output, "\n");
 		}
-	}
 
-	glp_delete_prob(lp);
+		glp_delete_prob(lp);
+	} else {
+		fprintf(stderr, "Simplex failed\n");
+	}
+	PTHREAD_MUTEX_UNLOCK(&mutex);
+#else /* HAVE_GLPK_H */
+	fprintf(output, "Please rebuild StarPU with glpk installed.\n");
+#endif /* HAVE_GLPK_H */
+}
 
+void starpu_bound_compute(double *res) {
+#ifdef HAVE_GLPK_H
+	double ret;
+	PTHREAD_MUTEX_LOCK(&mutex);
+	glp_prob *lp = _starpu_bound_glp_resolve();
+	if (lp) {
+		ret = glp_get_obj_val(lp);
+		glp_delete_prob(lp);
+	} else
+		ret = 0.;
 	PTHREAD_MUTEX_UNLOCK(&mutex);
+	*res = ret;
 #else /* HAVE_GLPK_H */
-	fprintf(output, "Please rebuild StarPU with glpk enabled.\n");
+	*res = 0.;
 #endif /* HAVE_GLPK_H */
 }