Browse Source

- add check for named omp critical
- fix named omp critical implementation

Olivier Aumage 11 years ago
parent
commit
9b64273b52
3 changed files with 103 additions and 2 deletions
  1. 3 2
      src/util/openmp_runtime_support.c
  2. 4 0
      tests/Makefile.am
  3. 96 0
      tests/openmp/parallel_critical_named_01.c

+ 3 - 2
src/util/openmp_runtime_support.c

@@ -463,15 +463,16 @@ void starpu_omp_shutdown(void)
 	destroy_omp_critical_struct(_global_state.default_critical);
 	_global_state.default_critical = NULL;
 	_starpu_spin_lock(&_global_state.named_criticals_lock);
-	if (_global_state.named_criticals)
 	{
 		struct starpu_omp_critical *critical, *tmp;
-		HASH_ITER(hh, _global_state.named_criticals, critical, tmp);
+		HASH_ITER(hh, _global_state.named_criticals, critical, tmp)
 		{
+			STARPU_ASSERT(critical != NULL);
 			HASH_DEL(_global_state.named_criticals, critical);
 			destroy_omp_critical_struct(critical);
 		}
 	}
+	STARPU_ASSERT(_global_state.named_criticals == NULL);
 	_starpu_spin_unlock(&_global_state.named_criticals_lock);
 	_starpu_spin_destroy(&_global_state.named_criticals_lock);
 	STARPU_PTHREAD_KEY_DELETE(omp_task_key);

+ 4 - 0
tests/Makefile.am

@@ -230,6 +230,7 @@ noinst_PROGRAMS =				\
 	openmp/parallel_single_wait_01		\
 	openmp/parallel_single_nowait_01	\
 	openmp/parallel_critical_01		\
+	openmp/parallel_critical_named_01	\
 	overlap/overlap				\
 	overlap/gpu_concurrency			\
 	parallel_tasks/explicit_combined_worker	\
@@ -473,6 +474,9 @@ openmp_parallel_single_nowait_01_SOURCES = 	\
 openmp_parallel_critical_01_SOURCES = 	\
 	openmp/parallel_critical_01.c
 
+openmp_parallel_critical_named_01_SOURCES = 	\
+	openmp/parallel_critical_named_01.c
+
 ###################
 # Block interface #
 ###################

+ 96 - 0
tests/openmp/parallel_critical_named_01.c

@@ -0,0 +1,96 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2014  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>
+
+#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 critical_g(void *arg)
+{
+	(void) arg;
+	int worker_id;
+	pthread_t tid;
+	tid = pthread_self();
+	worker_id = starpu_worker_get_id();
+	printf("[tid %p] task thread = %d -- critical \"g\"\n", (void *)tid, worker_id);
+}
+
+void critical_h(void *arg)
+{
+	(void) arg;
+	int worker_id;
+	pthread_t tid;
+	tid = pthread_self();
+	worker_id = starpu_worker_get_id();
+	printf("[tid %p] task thread = %d -- critical \"h\"\n", (void *)tid, worker_id);
+}
+
+void parallel_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 -- parallel -->\n", (void *)tid, worker_id);
+	starpu_omp_critical(critical_g, NULL, "g");
+	starpu_omp_critical(critical_h, NULL, "h");
+	starpu_omp_critical(critical_g, NULL, "g");
+	starpu_omp_critical(critical_h, NULL, "h");
+	printf("[tid %p] task thread = %d -- parallel <--\n", (void *)tid, worker_id);
+}
+
+static struct starpu_codelet parallel_region_cl =
+{
+	.cpu_funcs    = { parallel_region_f, NULL },
+	.where        = STARPU_CPU,
+	.nbuffers     = 0
+
+};
+
+int
+main (int argc, char *argv[]) {
+	pthread_t tid;
+	tid = pthread_self();
+	printf("<main>\n");
+	starpu_omp_parallel_region(&parallel_region_cl, NULL);
+	printf("<main>\n");
+	starpu_omp_parallel_region(&parallel_region_cl, NULL);
+	printf("<main>\n");
+	return 0;
+}
+#endif