From 52ab4d1ba3b6e5fed667ced26c063c75e4e4a040 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 30 Dec 2015 14:39:02 +0000 Subject: [PATCH] GRIB-884: OpenMP Support --- CMakeLists.txt | 15 ++++--- eccodes_config.h.in | 1 + fortran/grib_fortran.c | 58 ++++++++++++++++--------- python/grib_interface.c | 61 +++++++++++++++++---------- src/action.c | 15 +++++++ src/action_class_concept.c | 15 +++++++ src/action_class_when.c | 15 +++++++ src/grib_accessor_class.c | 18 +++++++- src/grib_accessor_class_smart_table.c | 15 +++++++ src/grib_api_internal.h | 22 ++++++++-- src/grib_context.c | 16 +++++++ src/grib_filepool.c | 15 +++++++ src/grib_handle.c | 17 ++++++++ src/grib_hash_keys.c | 16 ++++++- src/grib_ibmfloat.c | 15 +++++++ src/grib_ieeefloat.c | 15 +++++++ src/grib_index.c | 17 ++++++++ src/grib_itrie.c | 15 +++++++ src/grib_memory.c | 15 +++++++ src/grib_parse_utils.c | 25 +++++++++++ src/grib_trie.c | 15 +++++++ 21 files changed, 364 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e16b4133..9a3dc074e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,11 +82,11 @@ endif() # advanced options (not visible in cmake-gui ) -ecbuild_add_option( FEATURE MEMORY_MANAGEMENT DESCRIPTION "enable memory management" DEFAULT OFF ADVANCED ) -ecbuild_add_option( FEATURE ALIGN_MEMORY DESCRIPTION "enable memory alignment" DEFAULT OFF ADVANCED ) - -ecbuild_add_option( FEATURE GRIB_TIMER DESCRIPTION "enable timer" DEFAULT OFF ADVANCED ) -ecbuild_add_option( FEATURE ECCODES_THREADS DESCRIPTION "enable threads" DEFAULT OFF ADVANCED ) +ecbuild_add_option( FEATURE MEMORY_MANAGEMENT DESCRIPTION "enable memory management" DEFAULT OFF ADVANCED ) +ecbuild_add_option( FEATURE ALIGN_MEMORY DESCRIPTION "enable memory alignment" DEFAULT OFF ADVANCED ) +ecbuild_add_option( FEATURE GRIB_TIMER DESCRIPTION "enable timer" DEFAULT OFF ADVANCED ) +ecbuild_add_option( FEATURE ECCODES_THREADS DESCRIPTION "enable POSIX threads" DEFAULT OFF ADVANCED ) +ecbuild_add_option( FEATURE ECCODES_OMP_THREADS DESCRIPTION "enable OMP threads" DEFAULT OFF ADVANCED ) ############################################################################### # macro processing @@ -166,6 +166,7 @@ if( NOT ${CMAKE_USE_PTHREADS_INIT} ) endif() set( GRIB_PTHREADS 0 ) +set( GRIB_OMP_THREADS 0 ) set( GRIB_LINUX_PTHREADS 0 ) #if( HAVE_ECCODES_THREADS AND CMAKE_THREAD_LIBS_INIT ) if( HAVE_ECCODES_THREADS ) @@ -175,8 +176,12 @@ if( HAVE_ECCODES_THREADS ) set( GRIB_LINUX_PTHREADS 1 ) endif() endif() +elseif(HAVE_ECCODES_OMP_THREADS) + ecbuild_enable_omp() + set( GRIB_OMP_THREADS 1 ) endif() message(STATUS " GRIB_PTHREADS=${GRIB_PTHREADS}") +message(STATUS " GRIB_OMP_THREADS=${GRIB_OMP_THREADS}") set( GRIB_MEM_ALIGN 0 ) if( ENABLE_ALIGN_MEMORY ) diff --git a/eccodes_config.h.in b/eccodes_config.h.in index d09883a1c..588e6b03d 100644 --- a/eccodes_config.h.in +++ b/eccodes_config.h.in @@ -32,6 +32,7 @@ #define GRIB_MEM_ALIGN @GRIB_MEM_ALIGN@ #define GRIB_PTHREADS @GRIB_PTHREADS@ +#define GRIB_OMP_THREADS @GRIB_OMP_THREADS@ #define ECCODES_SAMPLES_PATH "@ECCODES_SAMPLES_PATH@" diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index ab5557a5b..868cffb31 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -32,28 +32,48 @@ #define MIN_FILE_ID 50000 #if GRIB_PTHREADS -static pthread_once_t once = PTHREAD_ONCE_INIT; -static pthread_mutex_t handle_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t index_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t multi_handle_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t iterator_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t keys_iterator_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_once_t once = PTHREAD_ONCE_INIT; + static pthread_mutex_t handle_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t index_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t multi_handle_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t iterator_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t keys_iterator_mutex = PTHREAD_MUTEX_INITIALIZER; + static void init() { + pthread_mutexattr_t attr; -static void init() { - pthread_mutexattr_t attr; - - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&handle_mutex,&attr); - pthread_mutex_init(&index_mutex,&attr); - pthread_mutex_init(&multi_handle_mutex,&attr); - pthread_mutex_init(&iterator_mutex,&attr); - pthread_mutex_init(&keys_iterator_mutex,&attr); - pthread_mutexattr_destroy(&attr); - -} + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&handle_mutex,&attr); + pthread_mutex_init(&index_mutex,&attr); + pthread_mutex_init(&multi_handle_mutex,&attr); + pthread_mutex_init(&iterator_mutex,&attr); + pthread_mutex_init(&keys_iterator_mutex,&attr); + pthread_mutexattr_destroy(&attr); + } +#elif GRIB_OMP_THREADS + static int once = 0; + static omp_nest_lock_t handle_mutex; + static omp_nest_lock_t index_mutex; + static omp_nest_lock_t multi_handle_mutex; + static omp_nest_lock_t iterator_mutex; + static omp_nest_lock_t keys_iterator_mutex; + static void init() + { + GRIB_OMP_CRITICAL(lock_fortran) + { + if (once == 0) + { + omp_init_nest_lock(&handle_mutex); + omp_init_nest_lock(&index_mutex); + omp_init_nest_lock(&multi_handle_mutex); + omp_init_nest_lock(&iterator_mutex); + omp_init_nest_lock(&keys_iterator_mutex); + once = 1; + } + } + } #endif int GRIB_NULL=-1; diff --git a/python/grib_interface.c b/python/grib_interface.c index 815b2bac4..5ff752ec4 100644 --- a/python/grib_interface.c +++ b/python/grib_interface.c @@ -26,28 +26,49 @@ #include #if GRIB_PTHREADS -static pthread_once_t once = PTHREAD_ONCE_INIT; -static pthread_mutex_t handle_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t index_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t multi_handle_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t iterator_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t keys_iterator_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_once_t once = PTHREAD_ONCE_INIT; + static pthread_mutex_t handle_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t index_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t multi_handle_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t iterator_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t keys_iterator_mutex = PTHREAD_MUTEX_INITIALIZER; + static void init() { + pthread_mutexattr_t attr; -static void init() { - pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&handle_mutex,&attr); + pthread_mutex_init(&index_mutex,&attr); + pthread_mutex_init(&multi_handle_mutex,&attr); + pthread_mutex_init(&iterator_mutex,&attr); + pthread_mutex_init(&keys_iterator_mutex,&attr); + pthread_mutexattr_destroy(&attr); - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&handle_mutex,&attr); - pthread_mutex_init(&index_mutex,&attr); - pthread_mutex_init(&multi_handle_mutex,&attr); - pthread_mutex_init(&iterator_mutex,&attr); - pthread_mutex_init(&keys_iterator_mutex,&attr); - pthread_mutexattr_destroy(&attr); - -} + } +#elif GRIB_OMP_THREADS + static int once = 0; + static omp_nest_lock_t handle_mutex; + static omp_nest_lock_t index_mutex; + static omp_nest_lock_t multi_handle_mutex; + static omp_nest_lock_t iterator_mutex; + static omp_nest_lock_t keys_iterator_mutex; + static void init() + { + GRIB_OMP_CRITICAL(lock_fortran) + { + if (once == 0) + { + omp_init_nest_lock(&handle_mutex); + omp_init_nest_lock(&index_mutex); + omp_init_nest_lock(&multi_handle_mutex); + omp_init_nest_lock(&iterator_mutex); + omp_init_nest_lock(&keys_iterator_mutex); + once = 1; + } + } + } #endif int GRIB_NULL=-1; @@ -1855,7 +1876,6 @@ int grib_c_set_real8_array(int* gid, char* key, double*val, int* size) if(!h) return GRIB_INVALID_GRIB; return grib_set_double_array(h, key, val, lsize); - } int grib_c_set_double_array(int* gid, char* key, double*val, int* size) @@ -1867,7 +1887,6 @@ int grib_c_set_double_array(int* gid, char* key, double*val, int* size) if(!h) return GRIB_INVALID_GRIB; return grib_set_double_array(h, key, val, lsize); - } int grib_c_get_string(int* gid, char* key, char* val, size_t *lsize) @@ -1955,11 +1974,9 @@ int grib_c_copy_message(int* gid, void* mess,size_t* len) return GRIB_BUFFER_TOO_SMALL; } - memcpy(mess,h->buffer->data,h->buffer->ulength); *len=h->buffer->ulength; return GRIB_SUCCESS; - } void grib_c_check(int* err,char* call,char* str) diff --git a/src/action.c b/src/action.c index 3d7c39006..23b39d3fa 100644 --- a/src/action.c +++ b/src/action.c @@ -27,6 +27,21 @@ static void init_mutex() { pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex1; + +static void init_mutex() +{ + GRIB_OMP_CRITICAL(lock_action_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex1); + once = 1; + } + } +} #endif diff --git a/src/action_class_concept.c b/src/action_class_concept.c index 7f30409a8..2a721d114 100644 --- a/src/action_class_concept.c +++ b/src/action_class_concept.c @@ -105,6 +105,21 @@ static void init() { pthread_mutex_init(&mutex,&attr); pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_action_class_concept_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex); + once = 1; + } + } +} #endif static grib_concept_value* get_concept(grib_handle* h,grib_action_concept* self); diff --git a/src/action_class_when.c b/src/action_class_when.c index 398a2befa..7a79eec8e 100644 --- a/src/action_class_when.c +++ b/src/action_class_when.c @@ -95,6 +95,21 @@ static void init() { pthread_mutex_init(&mutex,&attr); pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_action_class_when_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex); + once = 1; + } + } +} #endif grib_action* grib_action_create_when( grib_context* context, diff --git a/src/grib_accessor_class.c b/src/grib_accessor_class.c index 91d8f912d..f2b5bda01 100644 --- a/src/grib_accessor_class.c +++ b/src/grib_accessor_class.c @@ -28,6 +28,21 @@ static void init() { pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex1; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_accessor_class_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex1); + once = 1; + } + } +} #endif struct table_entry @@ -176,7 +191,8 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, return a; } -static void link_same_attributes(grib_accessor* a,grib_accessor* b) { +static void link_same_attributes(grib_accessor* a,grib_accessor* b) +{ int i=0; int idx=0; grib_accessor* bAttribute=NULL; diff --git a/src/grib_accessor_class_smart_table.c b/src/grib_accessor_class_smart_table.c index d3d126131..a77c7c3b2 100644 --- a/src/grib_accessor_class_smart_table.c +++ b/src/grib_accessor_class_smart_table.c @@ -173,6 +173,21 @@ static void thread_init() { pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex; + +static void thread_init() +{ + GRIB_OMP_CRITICAL(lock_grib_accessor_class_smart_table_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex); + once = 1; + } + } +} #endif static int grib_load_smart_table(grib_context* c,const char* filename, diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 43a160b5f..ad92ac8bf 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -127,10 +127,22 @@ extern "C" { #define GRIB_MUTEX_INIT_ONCE(a,b) pthread_once(a,b); #define GRIB_MUTEX_LOCK(a) pthread_mutex_lock(a); #define GRIB_MUTEX_UNLOCK(a) pthread_mutex_unlock(a); -/* -#define GRIB_MUTEX_LOCK(a) {pthread_mutex_lock(a); printf("MUTEX LOCK %p %s line %d\n",(void*)a,__FILE__,__LINE__);} -#define GRIB_MUTEX_UNLOCK(a) {pthread_mutex_unlock(a);printf("MUTEX UNLOCK %p %s line %d\n",(void*)a,__FILE__,__LINE__);} -*/ + /* + #define GRIB_MUTEX_LOCK(a) {pthread_mutex_lock(a); printf("MUTEX LOCK %p %s line %d\n",(void*)a,__FILE__,__LINE__);} + #define GRIB_MUTEX_UNLOCK(a) {pthread_mutex_unlock(a);printf("MUTEX UNLOCK %p %s line %d\n",(void*)a,__FILE__,__LINE__);} + */ +#elif GRIB_OMP_THREADS + #include + #ifdef _MSC_VER + #define GRIB_OMP_CRITICAL(a) __pragma(omp critical (a)) + #else + #define GRIB_OMP_STR(a) #a + #define GRIB_OMP_XSTR(a) GRIB_OMP_STR(a) + #define GRIB_OMP_CRITICAL(a) _Pragma( GRIB_OMP_XSTR(omp critical (a) ) ) + #endif + #define GRIB_MUTEX_INIT_ONCE(a,b) (*(b))(); + #define GRIB_MUTEX_LOCK(a) omp_set_nest_lock(a); + #define GRIB_MUTEX_UNLOCK(a) omp_unset_nest_lock(a); #else #define GRIB_MUTEX_INIT_ONCE(a,b) #define GRIB_MUTEX_LOCK(a) @@ -1031,6 +1043,8 @@ struct grib_context grib_trie* lists; #if GRIB_PTHREADS pthread_mutex_t mutex; +#elif GRIB_OMP_THREADS + omp_nest_lock_t mutex; #endif }; diff --git a/src/grib_context.c b/src/grib_context.c index c851a06ec..4f7162be4 100644 --- a/src/grib_context.c +++ b/src/grib_context.c @@ -40,7 +40,23 @@ static void init() pthread_mutex_init(&mutex_mem,&attr); pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex_mem; +static omp_nest_lock_t mutex_c; +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_context_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex_mem); + omp_init_nest_lock(&mutex_c); + once = 1; + } + } +} #endif diff --git a/src/grib_filepool.c b/src/grib_filepool.c index e9eb3176c..f564b4bb3 100644 --- a/src/grib_filepool.c +++ b/src/grib_filepool.c @@ -29,6 +29,21 @@ static void init() { pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex1; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_filepool_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex1); + once = 1; + } + } +} #endif static short next_id=0; diff --git a/src/grib_handle.c b/src/grib_handle.c index 858ac5a3d..1623ac0dd 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -30,6 +30,23 @@ static void init() { pthread_mutexattr_destroy(&attr); } +/* #elif GRIB_OMP_THREADS */ +static int once = 0; +static omp_nest_lock_t mutex1; +static omp_nest_lock_t mutex2; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_handle_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex1); + omp_init_nest_lock(&mutex2); + once = 1; + } + } +} #endif diff --git a/src/grib_hash_keys.c b/src/grib_hash_keys.c index f187f7700..ca08ed945 100644 --- a/src/grib_hash_keys.c +++ b/src/grib_hash_keys.c @@ -7472,6 +7472,21 @@ static void init() { pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_hash_keys_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex); + once = 1; + } + } +} #endif struct grib_itrie { grib_itrie* next[SIZE]; @@ -7542,7 +7557,6 @@ int grib_hash_keys_insert(grib_itrie* t,const char* key) int* count; GRIB_MUTEX_INIT_ONCE(&once,&init) - GRIB_MUTEX_LOCK(&mutex) count=t->count; diff --git a/src/grib_ibmfloat.c b/src/grib_ibmfloat.c index 4d27bb8d9..7ef562bc3 100644 --- a/src/grib_ibmfloat.c +++ b/src/grib_ibmfloat.c @@ -21,6 +21,21 @@ static void init() { pthread_mutex_init(&mutex,&attr); pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_ibmfloat_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex); + once = 1; + } + } +} #endif typedef struct ibm_table_t ibm_table_t; diff --git a/src/grib_ieeefloat.c b/src/grib_ieeefloat.c index 1204a7e0e..9c9d78571 100644 --- a/src/grib_ieeefloat.c +++ b/src/grib_ieeefloat.c @@ -25,6 +25,21 @@ static void init() { pthread_mutex_init(&mutex,&attr); pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_ieeefloat_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex); + once = 1; + } + } +} #endif #if 1 diff --git a/src/grib_index.c b/src/grib_index.c index 0ff87775e..331ad2fac 100644 --- a/src/grib_index.c +++ b/src/grib_index.c @@ -38,6 +38,23 @@ static void init() { pthread_mutexattr_destroy(&attr); } +/* #elif GRIB_OMP_THREADS */ +static int once = 0; +static omp_nest_lock_t mutex1; +static omp_nest_lock_t mutex2; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_index_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex1); + omp_init_nest_lock(&mutex2); + once = 1; + } + } +} #endif diff --git a/src/grib_itrie.c b/src/grib_itrie.c index 8f100c25a..7b5fe4506 100644 --- a/src/grib_itrie.c +++ b/src/grib_itrie.c @@ -284,6 +284,21 @@ static void init() { pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_itrie_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex); + once = 1; + } + } +} #endif struct grib_itrie { grib_itrie* next[SIZE]; diff --git a/src/grib_memory.c b/src/grib_memory.c index fa67c1fa2..0575a1005 100644 --- a/src/grib_memory.c +++ b/src/grib_memory.c @@ -27,6 +27,21 @@ static void init() { pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_memory_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex); + once = 1; + } + } +} #endif union align { diff --git a/src/grib_parse_utils.c b/src/grib_parse_utils.c index 6507bc566..f9a9540b8 100644 --- a/src/grib_parse_utils.c +++ b/src/grib_parse_utils.c @@ -48,6 +48,31 @@ static void init() pthread_mutex_init(&mutex_parse,&attr); pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex_file; +static omp_nest_lock_t mutex_rules; +static omp_nest_lock_t mutex_concept; +static omp_nest_lock_t mutex_hash_array; +static omp_nest_lock_t mutex_stream; +static omp_nest_lock_t mutex_parse; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_parse_utils_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex_file); + omp_init_nest_lock(&mutex_rules); + omp_init_nest_lock(&mutex_concept); + omp_init_nest_lock(&mutex_hash_array); + omp_init_nest_lock(&mutex_stream); + omp_init_nest_lock(&mutex_parse); + once = 1; + } + } +} #endif int grib_recompose_name(grib_handle* h, grib_accessor *observer, const char* uname, char* fname,int fail) diff --git a/src/grib_trie.c b/src/grib_trie.c index d8b0a8364..be2bd0011 100644 --- a/src/grib_trie.c +++ b/src/grib_trie.c @@ -283,6 +283,21 @@ static void init() { pthread_mutex_init(&mutex,&attr); pthread_mutexattr_destroy(&attr); } +#elif GRIB_OMP_THREADS +static int once = 0; +static omp_nest_lock_t mutex; + +static void init() +{ + GRIB_OMP_CRITICAL(lock_grib_trie_c) + { + if (once == 0) + { + omp_init_nest_lock(&mutex); + once = 1; + } + } +} #endif struct grib_trie {