瀏覽代碼

examples/scheduler/heteroprio_test.c: fix code when no CPU device is available

Nathalie Furmento 10 年之前
父節點
當前提交
45ab968fd1
共有 1 個文件被更改,包括 18 次插入11 次删除
  1. 18 11
      examples/scheduler/heteroprio_test.c

+ 18 - 11
examples/scheduler/heteroprio_test.c

@@ -24,30 +24,35 @@ void initSchedulerCallback()
 {
 	// CPU uses 3 buckets
 #ifdef STARPU_USE_CPU
-	starpu_heteroprio_set_nb_prios(0, STARPU_CPU_IDX, 3);
-	// It uses direct mapping idx => idx
-	unsigned idx;
-	for(idx = 0; idx < 3; ++idx)
+	if (starpu_cpu_worker_get_count())
 	{
-		starpu_heteroprio_set_mapping(0, STARPU_CPU_IDX, idx, idx);
-		starpu_heteroprio_set_faster_arch(0, STARPU_CPU_IDX, idx);
+		starpu_heteroprio_set_nb_prios(0, STARPU_CPU_IDX, 3);
+		// It uses direct mapping idx => idx
+		unsigned idx;
+		for(idx = 0; idx < 3; ++idx)
+		{
+			starpu_heteroprio_set_mapping(0, STARPU_CPU_IDX, idx, idx);
+			starpu_heteroprio_set_faster_arch(0, STARPU_CPU_IDX, idx);
+		}
 	}
 #endif
 #ifdef STARPU_USE_OPENCL
 	// OpenCL is enabled and uses 2 buckets
 	starpu_heteroprio_set_nb_prios(0, STARPU_OPENCL_IDX, 2);
 	// OpenCL will first look to priority 2
-	starpu_heteroprio_set_mapping(0, STARPU_OPENCL_IDX, 0, 2);
+	int prio2 = starpu_cpu_worker_get_count() ? 2 : 1;
+	starpu_heteroprio_set_mapping(0, STARPU_OPENCL_IDX, 0, prio2);
 	// For this bucket OpenCL is the fastest
-	starpu_heteroprio_set_faster_arch(0, STARPU_OPENCL_IDX, 2);
+	starpu_heteroprio_set_faster_arch(0, STARPU_OPENCL_IDX, prio2);
 	// And CPU is 4 times slower
 #ifdef STARPU_USE_CPU
 	starpu_heteroprio_set_arch_slow_factor(0, STARPU_CPU_IDX, 2, 4.0f);
 #endif
 
-	starpu_heteroprio_set_mapping(0, STARPU_OPENCL_IDX, 1, 1);
+	int prio1 = starpu_cpu_worker_get_count() ? 1 : 0;
+	starpu_heteroprio_set_mapping(0, STARPU_OPENCL_IDX, 1, prio1);
 	// We let the CPU as the fastest and tell that OpenCL is 1.7 times slower
-	starpu_heteroprio_set_arch_slow_factor(0, STARPU_OPENCL_IDX, 1, 1.7f);
+	starpu_heteroprio_set_arch_slow_factor(0, STARPU_OPENCL_IDX, prio1, 1.7f);
 #endif
 }
 
@@ -180,6 +185,8 @@ int main(int argc, char** argv)
 	const int nbTasks = 4;
 	FPRINTF(stderr, "Submit %d tasks \n", nbTasks);
 
+	int prio2 = starpu_cpu_worker_get_count() ? 2 : 1;
+
 	int idxTask;
 	for(idxTask = 0; idxTask < nbTasks; ++idxTask)
 	{
@@ -194,7 +201,7 @@ int main(int argc, char** argv)
 				   (STARPU_RW), handles[(idxTask*2)%nbHandles],
 				   0);
 		starpu_insert_task(&codeleteC,
-				   STARPU_PRIORITY, 2,
+				   STARPU_PRIORITY, prio2,
 				   (STARPU_RW), handles[(idxTask)%nbHandles],
 				   (STARPU_RW), handles[(idxTask*idxTask)%nbHandles],
 				   0);