Переглянути джерело

- add support for multiple sections combined in a single function

Olivier Aumage 11 роки тому
батько
коміт
24ad3f06bb

+ 2 - 1
include/starpu_openmp.h

@@ -107,7 +107,8 @@ extern void starpu_omp_ordered_inline_begin(unsigned long long i) __STARPU_OMP_N
 extern void starpu_omp_ordered_inline_end(void) __STARPU_OMP_NOTHROW;
 extern void starpu_omp_ordered(void (*f)(unsigned long long _i, void *arg), void *arg, unsigned long long i) __STARPU_OMP_NOTHROW;
 
-extern void starpu_omp_sections(int nb_sections, void (**section_f)(void *arg), void **section_arg, int nowait) __STARPU_OMP_NOTHROW;
+extern void starpu_omp_sections(unsigned long long nb_sections, void (**section_f)(void *arg), void **section_arg, int nowait) __STARPU_OMP_NOTHROW;
+extern void starpu_omp_sections_combined(unsigned long long nb_sections, void (*section_f)(unsigned long long section_num, void *arg), void **section_arg, int nowait) __STARPU_OMP_NOTHROW;
 
 extern void starpu_omp_set_num_threads(int threads) __STARPU_OMP_NOTHROW;
 extern int starpu_omp_get_num_threads() __STARPU_OMP_NOTHROW;

+ 32 - 1
src/util/openmp_runtime_support.c

@@ -1708,7 +1708,7 @@ static inline void _starpu_omp_sections_end(struct starpu_omp_region *parallel_r
 	task->sections_id++;
 }
 
-void starpu_omp_sections(int nb_sections, void (**section_f)(void *arg), void **section_arg, int nowait)
+void starpu_omp_sections(unsigned long long nb_sections, void (**section_f)(void *arg), void **section_arg, int nowait)
 {
 	struct starpu_omp_task *task = STARPU_PTHREAD_GETSPECIFIC(omp_task_key);
 	struct starpu_omp_region *parallel_region = task->owner_region;
@@ -1736,6 +1736,37 @@ void starpu_omp_sections(int nb_sections, void (**section_f)(void *arg), void **
 	}
 }
 
+void starpu_omp_sections_combined(unsigned long long nb_sections, void (*section_f)(unsigned long long section_num, void *arg), void **section_arg, int nowait)
+{
+	struct starpu_omp_task *task = STARPU_PTHREAD_GETSPECIFIC(omp_task_key);
+	struct starpu_omp_region *parallel_region = task->owner_region;
+	struct starpu_omp_sections *sections = _starpu_omp_sections_begin(parallel_region, task);
+	for (;;)
+	{
+		unsigned long long section_num;
+		void *arg = NULL;
+		_starpu_spin_lock(&parallel_region->lock);
+		if (sections->next_section_num < nb_sections)
+		{
+			section_num = sections->next_section_num;
+			arg = section_arg[sections->next_section_num];
+			sections->next_section_num ++;
+		}
+		else
+		{
+			_starpu_spin_unlock(&parallel_region->lock);
+			break;
+		}
+		_starpu_spin_unlock(&parallel_region->lock);
+		section_f(section_num, arg);
+	}
+	_starpu_omp_sections_end(parallel_region, task, sections);
+	if (!nowait)
+	{
+		starpu_omp_barrier();
+	}
+}
+
 /*
  * restore deprecated diagnostics (-Wdeprecated-declarations)
  */

+ 1 - 1
src/util/openmp_runtime_support.h

@@ -291,7 +291,7 @@ struct starpu_omp_loop
 struct starpu_omp_sections
 {
 	int id;
-	int next_section_num;
+	unsigned long long next_section_num;
 	int nb_completed_threads;
 	struct starpu_omp_sections *next_sections;
 };

+ 4 - 0
tests/Makefile.am

@@ -240,6 +240,7 @@ noinst_PROGRAMS =				\
 	openmp/parallel_for_02			\
 	openmp/parallel_for_ordered_01		\
 	openmp/parallel_sections_01		\
+	openmp/parallel_sections_combined_01	\
 	openmp/task_01				\
 	openmp/taskwait_01			\
 	openmp/taskgroup_01			\
@@ -513,6 +514,9 @@ openmp_parallel_for_ordered_01_SOURCES = 	\
 openmp_parallel_sections_01_SOURCES = 	\
 	openmp/parallel_sections_01.c
 
+openmp_parallel_sections_combined_01_SOURCES = 	\
+	openmp/parallel_sections_combined_01.c
+
 openmp_task_01_SOURCES = 	\
 	openmp/task_01.c