ソースを参照

Function starpu_sched_ctx_create() now takes a variable argument list
to define the scheduler to be used, and the minimum and maximum
priority values

Nathalie Furmento 11 年 前
コミット
43838444ce

+ 3 - 0
ChangeLog

@@ -86,6 +86,9 @@ Changes:
     starpu_data_set_tag(), data are received as a raw memory)
   * StarPU-MPI: Fix for being able to receive data with the same tag
     from several nodes (see mpi/tests/gather.c)
+  * Function starpu_sched_ctx_create() now takes a variable argument
+    list to define the scheduler to be used, and the minimum and
+    maximum priority values
 
 StarPU 1.1.0 (svn revision xxxx)
 ==============================================

+ 49 - 21
doc/doxygen/chapters/api/scheduling_contexts.doxy

@@ -39,27 +39,55 @@ hypervisor how the application and the resources are executing.
 @name Scheduling Contexts Basic API
 \ingroup API_Scheduling_Contexts
 
-\fn unsigned starpu_sched_ctx_create(const char *policy_name, int *workerids_ctx, int nworkers_ctx, const char *sched_ctx_name)
-\ingroup API_Scheduling_Contexts
-This function creates a scheduling context which uses the scheduling
-policy \p policy_name and assigns the workers in \p workerids_ctx to
-execute the tasks submitted to it.
-The return value represents the identifier of the context that has
-just been created. It will be further used to indicate the context the
-tasks will be submitted to. The return value should be at most
-\ref STARPU_NMAX_SCHED_CTXS.
-
-\fn unsigned starpu_sched_ctx_create_with_custom_policy(struct starpu_sched_policy *policy, int *workerids, int nworkers, const char *sched_name)
-\ingroup API_Scheduling_Contexts
-This function creates a scheduling context which uses the scheduling
-policy \p policy (the pointer to the custom scheduling policy) and assigns the workers in \p workerids to
-execute the tasks submitted to it.
-The return value represents the identifier of the context that has
-just been created. It will be further used to indicate the context the
-tasks will be submitted to. The return value should be at most
-\ref STARPU_NMAX_SCHED_CTXS.
-
-\fn unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_name, int min_ncpus, int max_ncpus, int min_ngpus, int max_ngpus, unsigned allow_overlap)
+\fn unsigned starpu_sched_ctx_create(int *workerids_ctx, int nworkers_ctx, const char *sched_ctx_name, ...)
+\ingroup API_Scheduling_Contexts
+This function creates a scheduling context with the given parameters
+(see below) and assigns the workers in \p workerids_ctx to execute the
+tasks submitted to it. The return value represents the identifier of
+the context that has just been created. It will be further used to
+indicate the context the tasks will be submitted to. The return value
+should be at most \ref STARPU_NMAX_SCHED_CTXS.
+
+The arguments following the name of the scheduling context can be of
+the following types:
+<ul>
+<li> ::STARPU_SCHED_CTX_POLICY_NAME, followed by the name of a
+predefined scheduling policy
+</li>
+<li> ::STARPU_SCHED_CTX_POLICY_STRUCT, followed by a pointer to a
+custom scheduling policy (struct starpu_sched_policy *)
+</li>
+<li> ::STARPU_SCHED_CTX_POLICY_MIN_PRIO, followed by a integer
+representing the minimum priority value to be defined for the
+scheduling policy.
+</li>
+<li> ::STARPU_SCHED_CTX_POLICY_MAX_PRIO, followed by a integer
+representing the maximum priority value to be defined for the
+scheduling policy.
+</li>
+</ul>
+
+\def STARPU_SCHED_CTX_POLICY_NAME
+\ingroup API_Scheduling_Contexts
+This macro is used when calling starpu_sched_ctx_create() to specify a
+name for a scheduling policy
+
+\def STARPU_SCHED_CTX_POLICY_STRUCT
+\ingroup API_Scheduling_Contexts
+This macro is used when calling starpu_sched_ctx_create() to specify a
+pointer to a scheduling policy
+
+\def STARPU_SCHED_CTX_POLICY_MIN_PRIO
+\ingroup API_Scheduling_Contexts
+This macro is used when calling starpu_sched_ctx_create() to specify a
+minimum scheduler priority value.
+
+\def STARPU_SCHED_CTX_POLICY_MAX_PRIO
+\ingroup API_Scheduling_Contexts
+This macro is used when calling starpu_sched_ctx_create() to specify a
+maximum scheduler priority value.
+
+\fn unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_ctx_name, int min_ncpus, int max_ncpus, int min_ngpus, int max_ngpus, unsigned allow_overlap)
 \ingroup API_Scheduling_Contexts
 Create a context indicating an approximate interval of resources
 

+ 2 - 0
examples/Makefile.am

@@ -187,6 +187,7 @@ examplebin_PROGRAMS +=				\
 	sched_ctx/sched_ctx			\
 	sched_ctx/parallel_code			\
 	sched_ctx/dummy_sched_with_ctx		\
+	sched_ctx/prio				\
 	reductions/dot_product			\
 	reductions/minmax_reduction		\
 	mandelbrot/mandelbrot			\
@@ -261,6 +262,7 @@ STARPU_EXAMPLES +=				\
 	profiling/profiling			\
 	scheduler/dummy_sched			\
 	sched_ctx/sched_ctx			\
+	sched_ctx/prio				\
 	sched_ctx/dummy_sched_with_ctx		\
 	reductions/dot_product			\
 	reductions/minmax_reduction

+ 1 - 1
examples/sched_ctx/dummy_sched_with_ctx.c

@@ -157,7 +157,7 @@ int main(int argc, char **argv)
 		return 77;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
-	unsigned sched_ctx = starpu_sched_ctx_create_with_custom_policy(&dummy_sched_policy, NULL, -1, "dummy");
+	unsigned sched_ctx = starpu_sched_ctx_create(NULL, -1, "dummy", STARPU_SCHED_CTX_POLICY_STRUCT, &dummy_sched_policy, 0);
 #ifdef STARPU_QUICK_CHECK
 	ntasks /= 100;
 #endif

+ 2 - 2
examples/sched_ctx/parallel_code.c

@@ -83,8 +83,8 @@ int main(int argc, char **argv)
 #endif
 
 	/*create contexts however you want*/
-	unsigned sched_ctx1 = starpu_sched_ctx_create("dmda", procs1, nprocs1, "ctx1");
-	unsigned sched_ctx2 = starpu_sched_ctx_create("dmda", procs2, nprocs2, "ctx2");
+	unsigned sched_ctx1 = starpu_sched_ctx_create(procs1, nprocs1, "ctx1", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
+	unsigned sched_ctx2 = starpu_sched_ctx_create(procs2, nprocs2, "ctx2", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
 
 	/*indicate what to do with the resources when context 2 finishes (it depends on your application)*/
 	starpu_sched_ctx_set_inheritor(sched_ctx2, sched_ctx1);

+ 2 - 2
examples/sched_ctx/sched_ctx.c

@@ -76,8 +76,8 @@ int main(int argc, char **argv)
 #endif
 
 	/*create contexts however you want*/
-	unsigned sched_ctx1 = starpu_sched_ctx_create("eager", procs1, nprocs1, "ctx1");
-	unsigned sched_ctx2 = starpu_sched_ctx_create("eager", procs2, nprocs2, "ctx2");
+	unsigned sched_ctx1 = starpu_sched_ctx_create(procs1, nprocs1, "ctx1", STARPU_SCHED_CTX_POLICY_NAME, "eager", 0);
+	unsigned sched_ctx2 = starpu_sched_ctx_create(procs2, nprocs2, "ctx2", STARPU_SCHED_CTX_POLICY_NAME, "eager",  0);
 
 	/*indicate what to do with the resources when context 2 finishes (it depends on your application)*/
 	starpu_sched_ctx_set_inheritor(sched_ctx2, sched_ctx1);

+ 2 - 2
examples/sched_ctx_utils/sched_ctx_utils.c

@@ -233,7 +233,7 @@ void construct_contexts(void (*bench)(unsigned, unsigned))
 	}
 	printf("\n ");
 
-	p1.ctx = starpu_sched_ctx_create("heft", procs, nprocs1, "sched_ctx1");
+	p1.ctx = starpu_sched_ctx_create(procs, nprocs1, "sched_ctx1", STARPU_SCHED_CTX_POLICY_NAME, "heft", 0);
 	p2.the_other_ctx = (int)p1.ctx;
 	p1.procs = procs;
 	p1.nprocs = nprocs1;
@@ -260,7 +260,7 @@ void construct_contexts(void (*bench)(unsigned, unsigned))
 	}
 	printf("\n");
 
-	p2.ctx = starpu_sched_ctx_create("heft", procs2, nprocs2, "sched_ctx2");
+	p2.ctx = starpu_sched_ctx_create(procs2, nprocs2, "sched_ctx2", STARPU_SCHED_CTX_POLICY_NAME, "heft", 0);
 	p1.the_other_ctx = (int)p2.ctx;
 	p2.procs = procs2;
 	starpu_sched_ctx_set_inheritor(p1.ctx, p2.ctx);

+ 9 - 4
include/starpu_sched_ctx.h

@@ -24,11 +24,12 @@ extern "C"
 {
 #endif
 
+#define STARPU_SCHED_CTX_POLICY_NAME		 (1<<16)
+#define STARPU_SCHED_CTX_POLICY_STRUCT		 (2<<16)
+#define STARPU_SCHED_CTX_POLICY_MIN_PRIO	 (3<<16)
+#define STARPU_SCHED_CTX_POLICY_MAX_PRIO	 (4<<16)
 
-unsigned starpu_sched_ctx_create(const char *policy_name, int *workerids_ctx, int nworkers_ctx, const char *sched_ctx_name);
-
-struct starpu_sched_policy;
-unsigned starpu_sched_ctx_create_with_custom_policy(struct starpu_sched_policy *policy, int *workerids, int nworkers, const char *sched_name);
+unsigned starpu_sched_ctx_create(int *workerids_ctx, int nworkers_ctx, const char *sched_ctx_name, ...);
 
 unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_name, int min_ncpus, int max_ncpus, int min_ngpus, int max_ngpus, unsigned allow_overlap);
 
@@ -80,6 +81,10 @@ int starpu_sched_ctx_set_min_priority(unsigned sched_ctx_id, int min_prio);
 
 int starpu_sched_ctx_set_max_priority(unsigned sched_ctx_id, int max_prio);
 
+int starpu_sched_ctx_min_priority_is_set(unsigned sched_ctx_id);
+
+int starpu_sched_ctx_max_priority_is_set(unsigned sched_ctx_id);
+
 #define STARPU_MIN_PRIO		(starpu_sched_get_min_priority())
 #define STARPU_MAX_PRIO		(starpu_sched_get_max_priority())
 

+ 2 - 2
sc_hypervisor/examples/app_driven_test/app_driven_test.c

@@ -124,8 +124,8 @@ int main()
 		ressources2[i] = nres1+i;
 
 	/* create contexts */
-	unsigned sched_ctx1 = starpu_sched_ctx_create("dmda", ressources1, nres1, "sched_ctx1");
-	unsigned sched_ctx2 = starpu_sched_ctx_create("dmda", ressources2, nres2, "sched_ctx2");
+	unsigned sched_ctx1 = starpu_sched_ctx_create(ressources1, nres1, "sched_ctx1", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
+	unsigned sched_ctx2 = starpu_sched_ctx_create(ressources2, nres2, "sched_ctx2", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
 
 	/* initialize the hypervisor */
 	struct sc_hypervisor_policy policy;

+ 2 - 2
sc_hypervisor/examples/lp_test/lp_resize_test.c

@@ -85,8 +85,8 @@ int main()
 
 
 	/* create contexts */
-	unsigned sched_ctx1 = starpu_sched_ctx_create("dmda", NULL, 0, "sched_ctx1");
-	unsigned sched_ctx2 = starpu_sched_ctx_create("dmda", NULL, 0, "sched_ctx2");
+	unsigned sched_ctx1 = starpu_sched_ctx_create(NULL, 0, "sched_ctx1", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
+	unsigned sched_ctx2 = starpu_sched_ctx_create(NULL, 0, "sched_ctx2", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
 
 	/* initialize the hypervisor */
 	struct sc_hypervisor_policy policy;

+ 2 - 2
sc_hypervisor/examples/lp_test/lp_test.c

@@ -84,8 +84,8 @@ int main()
 
 
 	/* create contexts */
-	unsigned sched_ctx1 = starpu_sched_ctx_create("dmda", NULL, 0, "sched_ctx1");
-	unsigned sched_ctx2 = starpu_sched_ctx_create("dmda", NULL, 0, "sched_ctx2");
+	unsigned sched_ctx1 = starpu_sched_ctx_create(NULL, 0, "sched_ctx1", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
+	unsigned sched_ctx2 = starpu_sched_ctx_create(NULL, 0, "sched_ctx2", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
 
 	/* initialize the hypervisor */
 	struct sc_hypervisor_policy policy;

+ 2 - 2
sc_hypervisor/examples/sched_ctx_utils/sched_ctx_utils.c

@@ -266,7 +266,7 @@ void construct_contexts(void (*bench)(float*, unsigned, unsigned))
 	for(i = 0; i < 12; i++)
 		p1.workers[i] = i;
 
-	p1.ctx = starpu_sched_ctx_create("heft", p1.workers, nworkers1, "sched_ctx1");
+	p1.ctx = starpu_sched_ctx_create(p1.workers, nworkers1, "sched_ctx1", STARPU_SCHED_CTX_POLICY_NAME, "heft", 0);
 	starpu_sched_ctx_set_perf_counters(p1.ctx, perf_counters);
 	p2.the_other_ctx = (int)p1.ctx;
 	p1.nworkers = nworkers1;
@@ -302,7 +302,7 @@ void construct_contexts(void (*bench)(float*, unsigned, unsigned))
 	/* for(i = n_all_gpus  + cpu1; i < n_all_gpus + cpu1 + cpu2; i++) */
 	/* 	p2.workers[k++] = i; */
 
-	p2.ctx = starpu_sched_ctx_create("heft", p2.workers, 0, "sched_ctx2");
+	p2.ctx = starpu_sched_ctx_create(p2.workers, 0, "sched_ctx2", STARPU_SCHED_CTX_POLICY_NAME, "heft", 0);
 	starpu_sched_ctx_set_perf_counters(p2.ctx, perf_counters);
 	p1.the_other_ctx = (int)p2.ctx;
 	p2.nworkers = 0;

+ 1 - 1
socl/src/cl_createcontext.c

@@ -141,7 +141,7 @@ soclCreateContext(const cl_context_properties * properties,
    for (i=0; i<num_devices; i++) {
       workers[i] = ctx->devices[i]->worker_id;
    }
-   ctx->sched_ctx = starpu_sched_ctx_create(scheduler, workers, num_devices, name);
+   ctx->sched_ctx = starpu_sched_ctx_create(workers, num_devices, name, STARPU_SCHED_CTX_POLICY_NAME, scheduler, 0);
 
    if (errcode_ret != NULL)
       *errcode_ret = CL_SUCCESS;

+ 63 - 23
src/core/sched_ctx.c

@@ -17,6 +17,7 @@
 #include <core/sched_policy.h>
 #include <core/sched_ctx.h>
 #include <common/utils.h>
+#include <stdarg.h>
 
 starpu_pthread_rwlock_t changing_ctx_mutex[STARPU_NMAX_SCHED_CTXS];
 
@@ -252,9 +253,11 @@ static void _starpu_sched_ctx_create_hwloc_tree(struct _starpu_sched_ctx *sched_
 }
 #endif
 
-struct _starpu_sched_ctx*  _starpu_create_sched_ctx(struct starpu_sched_policy *policy, int *workerids,
-				  int nworkers_ctx, unsigned is_initial_sched,
-				  const char *sched_name)
+struct _starpu_sched_ctx* _starpu_create_sched_ctx(struct starpu_sched_policy *policy, int *workerids,
+						   int nworkers_ctx, unsigned is_initial_sched,
+						   const char *sched_ctx_name,
+						   int min_prio_set, int min_prio,
+						   int max_prio_set, int max_prio)
 {
 	struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
 
@@ -279,11 +282,13 @@ struct _starpu_sched_ctx*  _starpu_create_sched_ctx(struct starpu_sched_policy *
 
 	sched_ctx->sched_policy = (struct starpu_sched_policy*)malloc(sizeof(struct starpu_sched_policy));
 	sched_ctx->is_initial_sched = is_initial_sched;
-	sched_ctx->name = sched_name;
+	sched_ctx->name = sched_ctx_name;
 	sched_ctx->inheritor = STARPU_NMAX_SCHED_CTXS;
 	sched_ctx->finished_submit = 0;
-	sched_ctx->min_priority = 0;
-	sched_ctx->max_priority = 1;
+	sched_ctx->min_priority_is_set = min_prio_set;
+	if (sched_ctx->min_priority_is_set) sched_ctx->min_priority = min_prio;
+	sched_ctx->max_priority_is_set = max_prio_set;
+	if (sched_ctx->max_priority_is_set) sched_ctx->max_priority = max_prio;
 	sem_init(&sched_ctx->parallel_code_sem, 0, 0);
 
 	_starpu_barrier_counter_init(&sched_ctx->tasks_barrier, 0);
@@ -445,7 +450,7 @@ static void _get_workers(int min, int max, int *workers, int *nw, enum starpu_wo
 	}
 }
 
-unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_name,
+unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_ctx_name,
 						 int min_ncpus, int max_ncpus, int min_ngpus, int max_ngpus,
 						 unsigned allow_overlap)
 {
@@ -464,7 +469,7 @@ unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const
 	for(i = 0; i < nw; i++)
 		printf("%d ", workers[i]);
 	printf("\n");
-	sched_ctx = _starpu_create_sched_ctx(selected_policy, workers, nw, 0, sched_name);
+	sched_ctx = _starpu_create_sched_ctx(selected_policy, workers, nw, 0, sched_ctx_name, 0, 0, 0, 0);
 	sched_ctx->min_ncpus = min_ncpus;
 	sched_ctx->max_ncpus = max_ncpus;
 	sched_ctx->min_ngpus = min_ngpus;
@@ -478,26 +483,49 @@ unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const
 
 }
 
-unsigned starpu_sched_ctx_create(const char *policy_name, int *workerids,
-				 int nworkers, const char *sched_name)
+unsigned starpu_sched_ctx_create(int *workerids, int nworkers, const char *sched_ctx_name, ...)
 {
-	struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
-	struct starpu_sched_policy *selected_policy = _starpu_select_sched_policy(config, policy_name);
+	va_list varg_list;
+	int arg_type;
+	int min_prio_set = 0;
+	int max_prio_set = 0;
+	int min_prio = 0;
+	int max_prio = 0;
+	struct starpu_sched_policy *sched_policy;
 
-	struct _starpu_sched_ctx *sched_ctx = NULL;
-	sched_ctx = _starpu_create_sched_ctx(selected_policy, workerids, nworkers, 0, sched_name);
+	va_start(varg_list, sched_ctx_name);
+	while ((arg_type = va_arg(varg_list, int)) != 0)
+	{
+		if (arg_type == STARPU_SCHED_CTX_POLICY_NAME)
+		{
+			char *policy_name = va_arg(varg_list, char *);
+			struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
+			sched_policy = _starpu_select_sched_policy(config, policy_name);
+		}
+		else if (arg_type == STARPU_SCHED_CTX_POLICY_STRUCT)
+		{
+			sched_policy = va_arg(varg_list, struct starpu_sched_policy *);
+		}
+		else if (arg_type == STARPU_SCHED_CTX_POLICY_MIN_PRIO)
+		{
+			min_prio = va_arg(varg_list, int);
+			min_prio_set = 1;
+		}
+		else if (arg_type == STARPU_SCHED_CTX_POLICY_MAX_PRIO)
+		{
+			max_prio = va_arg(varg_list, int);
+			max_prio_set = 1;
+		}
+		else
+		{
+			STARPU_ABORT_MSG("Unrecognized argument %d\n", arg_type);
+		}
 
-	_starpu_update_workers_with_ctx(sched_ctx->workers->workerids, sched_ctx->workers->nworkers, sched_ctx->id);
-#ifdef STARPU_USE_SC_HYPERVISOR
-	sched_ctx->perf_counters = NULL;
-#endif
-	return sched_ctx->id;
-}
+	}
+	va_end(varg_list);
 
-unsigned starpu_sched_ctx_create_with_custom_policy(struct starpu_sched_policy *policy, int *workerids, int nworkers, const char *sched_name)
-{
 	struct _starpu_sched_ctx *sched_ctx = NULL;
-	sched_ctx = _starpu_create_sched_ctx(policy, workerids, nworkers, 0, sched_name);
+	sched_ctx = _starpu_create_sched_ctx(sched_policy, workerids, nworkers, 0, sched_ctx_name, min_prio_set, min_prio, max_prio_set, max_prio);
 
 	_starpu_update_workers_with_ctx(sched_ctx->workers->workerids, sched_ctx->workers->nworkers, sched_ctx->id);
 #ifdef STARPU_USE_SC_HYPERVISOR
@@ -1121,6 +1149,18 @@ int starpu_sched_ctx_set_max_priority(unsigned sched_ctx_id, int max_prio)
 	return 0;
 }
 
+int starpu_sched_ctx_min_priority_is_set(unsigned sched_ctx_id)
+{
+	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
+	return sched_ctx->min_priority_is_set;
+}
+
+int starpu_sched_ctx_max_priority_is_set(unsigned sched_ctx_id)
+{
+	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
+	return sched_ctx->max_priority_is_set;
+}
+
 unsigned _starpu_sched_ctx_last_worker_awake(struct _starpu_worker *worker)
 {
 	struct _starpu_sched_ctx_list *l = NULL;

+ 5 - 1
src/core/sched_ctx.h

@@ -98,6 +98,8 @@ struct _starpu_sched_ctx
          * task (level 1) or it is not (level 0). */
      	int min_priority;
 	int max_priority;
+     	int min_priority_is_set;
+	int max_priority_is_set;
 
 	/* semaphore that block appl thread until threads are ready 
 	   to exec the parallel code */
@@ -124,7 +126,9 @@ struct _starpu_machine_config;
 void _starpu_init_all_sched_ctxs(struct _starpu_machine_config *config);
 
 /* allocate all structures belonging to a context */
-struct _starpu_sched_ctx*  _starpu_create_sched_ctx(struct starpu_sched_policy *policy, int *workerid, int nworkerids, unsigned is_init_sched, const char *sched_name);
+struct _starpu_sched_ctx*  _starpu_create_sched_ctx(struct starpu_sched_policy *policy, int *workerid, int nworkerids, unsigned is_init_sched, const char *sched_name,
+						    int min_prio_set, int min_prio,
+						    int max_prio_set, int max_prio);
 
 /* delete all sched_ctx */
 void _starpu_delete_all_sched_ctxs();

+ 1 - 1
src/core/workers.c

@@ -1033,7 +1033,7 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 	if (!is_a_sink)
 	{
 		struct starpu_sched_policy *selected_policy = _starpu_select_sched_policy(&config, config.conf->sched_policy_name);
-		_starpu_create_sched_ctx(selected_policy, NULL, -1, 1, "init");
+		_starpu_create_sched_ctx(selected_policy, NULL, -1, 1, "init", 0, 0, 0, 0);
 
 	}
 

+ 4 - 2
src/sched_policies/deque_modeling_policy_data_aware.c

@@ -882,8 +882,10 @@ static void initialize_dmda_sorted_policy(unsigned sched_ctx_id)
 	initialize_dmda_policy(sched_ctx_id);
 
 	/* The application may use any integer */
-	starpu_sched_ctx_set_min_priority(sched_ctx_id, INT_MIN);
-	starpu_sched_ctx_set_max_priority(sched_ctx_id, INT_MAX);
+	if (starpu_sched_ctx_min_priority_is_set(sched_ctx_id) == 0)
+		starpu_sched_ctx_set_min_priority(sched_ctx_id, INT_MIN);
+	if (starpu_sched_ctx_max_priority_is_set(sched_ctx_id) == 0)
+		starpu_sched_ctx_set_max_priority(sched_ctx_id, INT_MAX);
 }
 
 static void deinitialize_dmda_policy(unsigned sched_ctx_id)

+ 22 - 14
src/sched_policies/eager_central_priority_policy.c

@@ -26,17 +26,17 @@
 
 #include <common/fxt.h>
 
-#define MIN_LEVEL	(-5)
-#define MAX_LEVEL	(+5)
-
-#define NPRIO_LEVELS	(MAX_LEVEL - MIN_LEVEL + 1)
+#define DEFAULT_MIN_LEVEL	(-5)
+#define DEFAULT_MAX_LEVEL	(+5)
 
 struct _starpu_priority_taskq
 {
+	int min_prio;
+	int max_prio;
 	/* the actual lists
 	 *	taskq[p] is for priority [p - STARPU_MIN_PRIO] */
-	struct starpu_task_list taskq[NPRIO_LEVELS];
-	unsigned ntasks[NPRIO_LEVELS];
+	struct starpu_task_list *taskq;
+	unsigned *ntasks;
 
 	unsigned total_ntasks;
 };
@@ -51,15 +51,19 @@ struct _starpu_eager_central_prio_data
  * Centralized queue with priorities
  */
 
-static struct _starpu_priority_taskq *_starpu_create_priority_taskq(void)
+static struct _starpu_priority_taskq *_starpu_create_priority_taskq(int min_prio, int max_prio)
 {
 	struct _starpu_priority_taskq *central_queue;
 
 	central_queue = (struct _starpu_priority_taskq *) malloc(sizeof(struct _starpu_priority_taskq));
+	central_queue->min_prio = min_prio;
+	central_queue->max_prio = max_prio;
 	central_queue->total_ntasks = 0;
+	central_queue->taskq = malloc((max_prio-min_prio+1) * sizeof(struct starpu_task_list));
+	central_queue->ntasks = malloc((max_prio-min_prio+1) * sizeof(unsigned));
 
-	unsigned prio;
-	for (prio = 0; prio < NPRIO_LEVELS; prio++)
+	int prio;
+	for (prio = 0; prio < (max_prio-min_prio+1); prio++)
 	{
 		starpu_task_list_init(&central_queue->taskq[prio]);
 		central_queue->ntasks[prio] = 0;
@@ -70,6 +74,8 @@ static struct _starpu_priority_taskq *_starpu_create_priority_taskq(void)
 
 static void _starpu_destroy_priority_taskq(struct _starpu_priority_taskq *priority_queue)
 {
+	free(priority_queue->ntasks);
+	free(priority_queue->taskq);
 	free(priority_queue);
 }
 
@@ -79,11 +85,14 @@ static void initialize_eager_center_priority_policy(unsigned sched_ctx_id)
 	struct _starpu_eager_central_prio_data *data = (struct _starpu_eager_central_prio_data*)malloc(sizeof(struct _starpu_eager_central_prio_data));
 
 	/* In this policy, we support more than two levels of priority. */
-	starpu_sched_ctx_set_min_priority(sched_ctx_id, MIN_LEVEL);
-	starpu_sched_ctx_set_max_priority(sched_ctx_id, MAX_LEVEL);
+
+	if (starpu_sched_ctx_min_priority_is_set(sched_ctx_id) == 0)
+		starpu_sched_ctx_set_min_priority(sched_ctx_id, DEFAULT_MIN_LEVEL);
+	if (starpu_sched_ctx_max_priority_is_set(sched_ctx_id) == 0)
+		starpu_sched_ctx_set_max_priority(sched_ctx_id, DEFAULT_MAX_LEVEL);
 
 	/* only a single queue (even though there are several internaly) */
-	data->taskq = _starpu_create_priority_taskq();
+	data->taskq = _starpu_create_priority_taskq(starpu_sched_ctx_get_min_priority(sched_ctx_id), starpu_sched_ctx_get_max_priority(sched_ctx_id));
 
 	/* Tell helgrind that it's fine to check for empty fifo in
 	 * _starpu_priority_pop_task without actual mutex (it's just an
@@ -91,7 +100,6 @@ static void initialize_eager_center_priority_policy(unsigned sched_ctx_id)
 	STARPU_HG_DISABLE_CHECKING(data->taskq->total_ntasks);
 	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)data);
 	STARPU_PTHREAD_MUTEX_INIT(&data->policy_mutex, NULL);
-
 }
 
 static void deinitialize_eager_center_priority_policy(unsigned sched_ctx_id)
@@ -176,7 +184,7 @@ static struct starpu_task *_starpu_priority_pop_task(unsigned sched_ctx_id)
 	   there's no need for their own mutex to be locked */
 	STARPU_PTHREAD_MUTEX_LOCK(&data->policy_mutex);
 
-	unsigned priolevel = NPRIO_LEVELS - 1;
+	unsigned priolevel = taskq->max_prio - taskq->min_prio;
 	do
 	{
 		if (taskq->ntasks[priolevel] > 0)