Browse Source

- omp icvs declaration and general initialization

Olivier Aumage 11 years ago
parent
commit
b809761a76
3 changed files with 149 additions and 0 deletions
  1. 1 0
      src/Makefile.am
  2. 53 0
      src/util/openmp_runtime_support.c
  3. 95 0
      src/util/openmp_runtime_support.h

+ 1 - 0
src/Makefile.am

@@ -127,6 +127,7 @@ noinst_HEADERS = 						\
 	debug/traces/starpu_fxt.h				\
 	profiling/bound.h					\
 	profiling/profiling.h					\
+	util/openmp_runtime_support.h				\
 	util/starpu_task_insert_utils.h				\
 	util/starpu_data_cpy.h					\
 	starpu_parameters.h					\

+ 53 - 0
src/util/openmp_runtime_support.c

@@ -15,12 +15,48 @@
  */
 
 #include <starpu.h>
+#include <util/openmp_runtime_support.h>
 
 #ifdef STARPU_OPENMP
 #define __not_implemented__ do { fprintf (stderr, "omp lib function %s not implemented\n", __func__); abort(); } while (0)
 
 static double _starpu_omp_clock_ref = 0.0; /* clock reference for starpu_omp_get_wtick */
 
+static struct starpu_omp_global_icvs _global_icvs;
+static struct starpu_omp_initial_icv_values _initial_icv_values =
+{
+	.dyn_var = 0,
+	.nest_var = 0,
+	.nthreads_var = NULL,
+	.run_sched_var = 0,
+	.def_sched_var = 0,
+	.bind_var = NULL,
+	.stacksize_var = 0,
+	.wait_policy_var = 0,
+	.max_active_levels_var = 0,
+	.active_levels_var = 0,
+	.levels_var = 0,
+	.place_partition_var = 0,
+	.cancel_var = 0,
+	.default_device_var = 0
+};
+
+struct starpu_omp_global_icvs *starpu_omp_global_icvs = NULL;
+struct starpu_omp_initial_icv_values *starpu_omp_initial_icv_values = NULL;
+
+static void read_int_var(const char *var, int *dest)
+{
+	const char *env = getenv(var);
+	if (env) {
+		int v = (int)strtol(env, NULL, 16);
+		if (errno != 0) {
+			fprintf(stderr, "Warning: could not parse environment variable %s, strtol failed with error %s\n", var, strerror(errno));
+		} else {
+			*dest = v;
+		}
+	}
+}
+
 /*
  * Entry point to be called by the OpenMP runtime constructor
  */
@@ -28,6 +64,23 @@ int starpu_omp_init(void)
 {
 	int ret;
 
+	read_int_var("OMP_DYNAMIC", &_initial_icv_values.dyn_var);
+	read_int_var("OMP_NESTED", &_initial_icv_values.nest_var);
+	/* TODO: OMP_NUM_THREADS */
+	read_int_var("OMP_SCHEDULE", &_initial_icv_values.run_sched_var);
+	/* TODO: OMP_PROC_BIND */
+	read_int_var("OMP_STACKSIZE", &_initial_icv_values.stacksize_var);
+	read_int_var("OMP_WAIT_POLICY", &_initial_icv_values.wait_policy_var);
+	read_int_var("OMP_THREAD_LIMIT", &_initial_icv_values.thread_limit_var);
+	read_int_var("OMP_MAX_ACTIVE_LEVELS", &_initial_icv_values.max_active_levels_var);
+	read_int_var("OMP_PLACES", &_initial_icv_values.place_partition_var);
+	read_int_var("OMP_CANCELLATION", &_initial_icv_values.cancel_var);
+	read_int_var("OMP_DEFAULT_DEVICE", &_initial_icv_values.default_device_var);
+	starpu_omp_initial_icv_values = &_initial_icv_values;
+
+	_global_icvs.cancel_var = starpu_omp_initial_icv_values->cancel_var;
+	starpu_omp_global_icvs = &_global_icvs;
+
 	ret = starpu_init(0);
 	if(ret < 0)
 		return ret;

+ 95 - 0
src/util/openmp_runtime_support.h

@@ -0,0 +1,95 @@
+/* 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.
+ */
+
+#ifndef __OPENMP_RUNTIME_SUPPORT_H__
+#define __OPENMP_RUNTIME_SUPPORT_H__
+
+#include <starpu.h>
+
+#ifdef STARPU_OPENMP
+
+/* 
+ * Internal Control Variables (ICVs) declared following
+ * OpenMP 4.0.0 spec section 2.3.1
+ */
+struct starpu_omp_data_environment_icvs
+{
+	/* parallel region icvs */
+	int dyn_var;
+	int nest_var;
+	int *nthreads_var; /* nthreads_var ICV is a list */
+	int thread_limit_var;
+
+	int active_levels_var;
+	int levels_var;
+	int *bind_var; /* bind_var ICV is a list */
+
+	/* loop region icvs */
+	int run_sched_var;
+
+	/* program execution icvs */
+	int default_device_var;
+};
+
+struct starpu_omp_device_icvs
+{
+	/* parallel region icvs */
+	int max_active_levels_var;
+
+	/* loop region icvs */
+	int def_sched_var;
+
+	/* program execution icvs */
+	int stacksize_var;
+	int wait_policy_var;
+};
+
+struct starpu_omp_implicit_task_icvs
+{
+	/* parallel region icvs */
+	int place_partition_var;
+};
+
+struct starpu_omp_global_icvs
+{
+	/* program execution icvs */
+	int cancel_var;
+};
+
+struct starpu_omp_initial_icv_values
+{
+	int dyn_var;
+	int nest_var;
+	int *nthreads_var;
+	int run_sched_var;
+	int def_sched_var;
+	int *bind_var;
+	int stacksize_var;
+	int wait_policy_var;
+	int thread_limit_var;
+	int max_active_levels_var;
+	int active_levels_var;
+	int levels_var;
+	int place_partition_var;
+	int cancel_var;
+	int default_device_var;
+};
+
+extern struct starpu_omp_global_icvs *starpu_omp_global_icvs;
+extern struct starpu_omp_initial_icv_values *starpu_omp_initial_icv_values;
+#endif // STARPU_OPENMP
+
+#endif // __OPENMP_RUNTIME_SUPPORT_H__