Przeglądaj źródła

- add some basic, crude support for OpenMP orphaned tasks

Olivier Aumage 8 lat temu
rodzic
commit
653fea9506
3 zmienionych plików z 100 dodań i 14 usunięć
  1. 23 14
      src/util/openmp_runtime_support.c
  2. 4 0
      tests/Makefile.am
  3. 73 0
      tests/openmp/task_03.c

+ 23 - 14
src/util/openmp_runtime_support.c

@@ -1534,26 +1534,35 @@ void starpu_omp_task_region(const struct starpu_omp_task_region_attr *attr)
 	int is_merged = 0;
 	int is_merged = 0;
 	int ret;
 	int ret;
 
 
-	if (!attr->if_clause)
+	if (generating_task == _global_state.initial_task)
 	{
 	{
 		is_undeferred = 1;
 		is_undeferred = 1;
-	}
-	if (generating_task->flags & STARPU_OMP_TASK_FLAGS_FINAL)
-	{
 		is_final = 1;
 		is_final = 1;
 		is_included = 1;
 		is_included = 1;
 	}
 	}
-	else if (attr->final_clause)
-	{
-		is_final = 1;
-	}
-	if (is_included)
-	{
-		is_undeferred = 1;
-	}
-	if ((is_undeferred || is_included) & attr->mergeable_clause)
+	else
 	{
 	{
-		is_merged = 1;
+		if (!attr->if_clause)
+		{
+			is_undeferred = 1;
+		}
+		if (generating_task->flags & STARPU_OMP_TASK_FLAGS_FINAL)
+		{
+			is_final = 1;
+			is_included = 1;
+		}
+		else if (attr->final_clause)
+		{
+			is_final = 1;
+		}
+		if (is_included)
+		{
+			is_undeferred = 1;
+		}
+		if ((is_undeferred || is_included) & attr->mergeable_clause)
+		{
+			is_merged = 1;
+		}
 	}
 	}
 	if (is_merged)
 	if (is_merged)
 	{
 	{

+ 4 - 0
tests/Makefile.am

@@ -298,6 +298,7 @@ myPROGRAMS +=				\
 	openmp/parallel_sections_combined_01	\
 	openmp/parallel_sections_combined_01	\
 	openmp/task_01				\
 	openmp/task_01				\
 	openmp/task_02				\
 	openmp/task_02				\
+	openmp/task_03				\
 	openmp/taskwait_01			\
 	openmp/taskwait_01			\
 	openmp/taskgroup_01			\
 	openmp/taskgroup_01			\
 	openmp/taskgroup_02			\
 	openmp/taskgroup_02			\
@@ -651,6 +652,9 @@ openmp_task_01_SOURCES = 	\
 openmp_task_02_SOURCES = 	\
 openmp_task_02_SOURCES = 	\
 	openmp/task_02.c
 	openmp/task_02.c
 
 
+openmp_task_03_SOURCES = 	\
+	openmp/task_03.c
+
 openmp_taskwait_01_SOURCES = 	\
 openmp_taskwait_01_SOURCES = 	\
 	openmp/taskwait_01.c
 	openmp/taskwait_01.c
 
 

+ 73 - 0
tests/openmp/task_03.c

@@ -0,0 +1,73 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2014, 2016  INRIA
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <pthread.h>
+#include <starpu.h>
+#include "../helper.h"
+#include <stdio.h>
+
+/*
+ * Check the OpenMP orphaned task support.
+ */
+
+#if !defined(STARPU_OPENMP)
+int main(int argc, char **argv)
+{
+	return STARPU_TEST_SKIPPED;
+}
+#else
+__attribute__((constructor))
+static void omp_constructor(void)
+{
+	int ret = starpu_omp_init();
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_omp_init");
+}
+
+__attribute__((destructor))
+static void omp_destructor(void)
+{
+	starpu_omp_shutdown();
+}
+
+void task_region_f(void *buffers[], void *args)
+{
+	(void) buffers;
+	(void) args;
+	int worker_id;
+	pthread_t tid;
+	tid = pthread_self();
+	worker_id = starpu_worker_get_id();
+	printf("[tid %p] task thread = %d: explicit task \"f\"\n", (void *)tid, worker_id);
+}
+
+int
+main (int argc, char *argv[])
+{
+	struct starpu_omp_task_region_attr attr;
+	memset(&attr, 0, sizeof(attr));
+	attr.cl.cpu_funcs[0]  = task_region_f;
+	attr.cl.where         = STARPU_CPU;
+	attr.if_clause        = 1;
+	attr.final_clause     = 0;
+	attr.untied_clause    = 1;
+	attr.mergeable_clause = 0;
+	starpu_omp_task_region(&attr);
+	starpu_omp_task_region(&attr);
+	starpu_omp_task_region(&attr);
+	starpu_omp_task_region(&attr);
+	return 0;
+}
+#endif