From 95df6747cf1978aa1732d8b93af585e34cec4987 Mon Sep 17 00:00:00 2001 From: AndreyChurbanov Date: Wed, 4 Mar 2020 18:15:05 +0300 Subject: [PATCH] [openmp] OpenMP 5.1 omp_display_env function implementation. Patch by Michael Klemm. Differential Revision: https://reviews.llvm.org/D74956 --- openmp/runtime/src/dllexports | 1 + openmp/runtime/src/include/omp.h.var | 3 +++ openmp/runtime/src/include/omp_lib.f.var | 5 +++++ openmp/runtime/src/include/omp_lib.f90.var | 6 ++++++ openmp/runtime/src/include/omp_lib.h.var | 5 +++++ openmp/runtime/src/kmp.h | 2 ++ openmp/runtime/src/kmp_ftn_entry.h | 7 +++++++ openmp/runtime/src/kmp_ftn_os.h | 4 ++++ openmp/runtime/src/kmp_runtime.cpp | 10 +++++++++- openmp/runtime/src/kmp_settings.cpp | 11 +++++++---- openmp/runtime/src/kmp_settings.h | 1 + openmp/runtime/test/api/omp_display_env0.c | 14 ++++++++++++++ 12 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 openmp/runtime/test/api/omp_display_env0.c diff --git a/openmp/runtime/src/dllexports b/openmp/runtime/src/dllexports index f76619e..45a294b 100644 --- a/openmp/runtime/src/dllexports +++ b/openmp/runtime/src/dllexports @@ -533,6 +533,7 @@ kmp_set_disp_num_buffers 890 omp_pause_resource_all 757 omp_get_supported_active_levels 758 omp_fulfill_event 759 + omp_display_env 733 omp_null_allocator DATA omp_default_mem_alloc DATA diff --git a/openmp/runtime/src/include/omp.h.var b/openmp/runtime/src/include/omp.h.var index dd5b8ce..f62afc2 100644 --- a/openmp/runtime/src/include/omp.h.var +++ b/openmp/runtime/src/include/omp.h.var @@ -355,6 +355,9 @@ extern int __KAI_KMPC_CONVENTION omp_get_supported_active_levels(void); + /* OpenMP 5.1 Display Environment */ + extern void omp_display_env(int verbose); + # undef __KAI_KMPC_CONVENTION # undef __KMP_IMP diff --git a/openmp/runtime/src/include/omp_lib.f.var b/openmp/runtime/src/include/omp_lib.f.var index d631438..bf40c78 100644 --- a/openmp/runtime/src/include/omp_lib.f.var +++ b/openmp/runtime/src/include/omp_lib.f.var @@ -488,6 +488,11 @@ integer (kind=kmp_size_t_kind) omp_capture_affinity end function omp_capture_affinity + subroutine omp_display_env(verbose) bind(c) + use omp_lib_kinds + logical (kind=omp_logical_kind), value :: verbose + end subroutine omp_display_env + ! *** ! *** kmp_* entry points ! *** diff --git a/openmp/runtime/src/include/omp_lib.f90.var b/openmp/runtime/src/include/omp_lib.f90.var index ac56848..fbbb7b9 100644 --- a/openmp/runtime/src/include/omp_lib.f90.var +++ b/openmp/runtime/src/include/omp_lib.f90.var @@ -503,6 +503,12 @@ integer (kind=kmp_size_t_kind) :: omp_capture_affinity end function omp_capture_affinity + subroutine omp_display_env(verbose) bind(c) + use omp_lib_kinds + logical (kind=omp_logical_kind), value :: verbose + end subroutine omp_display_env + + ! *** ! *** kmp_* entry points ! *** diff --git a/openmp/runtime/src/include/omp_lib.h.var b/openmp/runtime/src/include/omp_lib.h.var index 8775128..f1b6b03 100644 --- a/openmp/runtime/src/include/omp_lib.h.var +++ b/openmp/runtime/src/include/omp_lib.h.var @@ -580,6 +580,11 @@ integer (kind=kmp_size_t_kind) :: omp_capture_affinity end function omp_capture_affinity + subroutine omp_display_env(verbose) bind(c) + import + logical (kind=omp_logical_kind), value :: verbose + end subroutine omp_display_env + ! *** ! *** kmp_* entry points ! *** diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h index bb1f3ed..c912157 100644 --- a/openmp/runtime/src/kmp.h +++ b/openmp/runtime/src/kmp.h @@ -3908,6 +3908,8 @@ static inline void __kmp_resume_if_hard_paused() { } } +extern void __kmp_omp_display_env(int verbose); + #ifdef __cplusplus } #endif diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h index 89172c0..ab57907 100644 --- a/openmp/runtime/src/kmp_ftn_entry.h +++ b/openmp/runtime/src/kmp_ftn_entry.h @@ -1371,6 +1371,13 @@ void FTN_STDCALL FTN_FULFILL_EVENT(kmp_event_t *event) { #endif } +// display environment variables when requested +void FTN_STDCALL FTN_DISPLAY_ENV(int verbose) { +#ifndef KMP_STUB + __kmp_omp_display_env(verbose); +#endif +} + // GCC compatibility (versioned symbols) #ifdef KMP_USE_VERSION_SYMBOLS diff --git a/openmp/runtime/src/kmp_ftn_os.h b/openmp/runtime/src/kmp_ftn_os.h index 41cafab..cd04914 100644 --- a/openmp/runtime/src/kmp_ftn_os.h +++ b/openmp/runtime/src/kmp_ftn_os.h @@ -133,6 +133,7 @@ #define FTN_PAUSE_RESOURCE omp_pause_resource #define FTN_PAUSE_RESOURCE_ALL omp_pause_resource_all #define FTN_GET_SUPPORTED_ACTIVE_LEVELS omp_get_supported_active_levels +#define FTN_DISPLAY_ENV omp_display_env #define FTN_FULFILL_EVENT omp_fulfill_event #endif /* KMP_FTN_PLAIN */ @@ -256,6 +257,7 @@ #define FTN_PAUSE_RESOURCE omp_pause_resource_ #define FTN_PAUSE_RESOURCE_ALL omp_pause_resource_all_ #define FTN_GET_SUPPORTED_ACTIVE_LEVELS omp_get_supported_active_levels_ +#define FTN_DISPLAY_ENV omp_display_env_ #define FTN_FULFILL_EVENT omp_fulfill_event_ #endif /* KMP_FTN_APPEND */ @@ -377,6 +379,7 @@ #define FTN_PAUSE_RESOURCE OMP_PAUSE_RESOURCE #define FTN_PAUSE_RESOURCE_ALL OMP_PAUSE_RESOURCE_ALL #define FTN_GET_SUPPORTED_ACTIVE_LEVELS OMP_GET_SUPPORTED_ACTIVE_LEVELS +#define FTN_DISPLAY_ENV OMP_DISPLAY_ENV #define FTN_FULFILL_EVENT OMP_FULFILL_EVENT #endif /* KMP_FTN_UPPER */ @@ -500,6 +503,7 @@ #define FTN_PAUSE_RESOURCE OMP_PAUSE_RESOURCE_ #define FTN_PAUSE_RESOURCE_ALL OMP_PAUSE_RESOURCE_ALL_ #define FTN_GET_SUPPORTED_ACTIVE_LEVELS OMP_GET_SUPPORTED_ACTIVE_LEVELS_ +#define FTN_DISPLAY_ENV OMP_DISPLAY_ENV_ #define FTN_FULFILL_EVENT OMP_FULFILL_EVENT_ #endif /* KMP_FTN_UAPPEND */ diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp index acd157d..4df3fef 100644 --- a/openmp/runtime/src/kmp_runtime.cpp +++ b/openmp/runtime/src/kmp_runtime.cpp @@ -8217,7 +8217,6 @@ __kmp_determine_reduction_method( return (retval); } - // this function is for testing set/get/determine reduce method kmp_int32 __kmp_get_reduce_method(void) { return ((__kmp_entry_thread()->th.th_local.packed_reduction_method) >> 8); @@ -8297,3 +8296,12 @@ int __kmp_pause_resource(kmp_pause_status_t level) { return 1; } } + + +void __kmp_omp_display_env(int verbose) { + __kmp_acquire_bootstrap_lock(&__kmp_initz_lock); + if (__kmp_init_serial == 0) + __kmp_do_serial_initialize(); + __kmp_display_env_impl(!verbose, verbose); + __kmp_release_bootstrap_lock(&__kmp_initz_lock); +} diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp index c7dec4d..f76e310 100644 --- a/openmp/runtime/src/kmp_settings.cpp +++ b/openmp/runtime/src/kmp_settings.cpp @@ -5720,7 +5720,11 @@ void __kmp_env_print() { } // __kmp_env_print void __kmp_env_print_2() { + __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose); +} // __kmp_env_print_2 + +void __kmp_display_env_impl(int display_env, int display_env_verbose) { kmp_env_blk_t block; kmp_str_buf_t buffer; @@ -5737,9 +5741,9 @@ void __kmp_env_print_2() { for (int i = 0; i < __kmp_stg_count; ++i) { if (__kmp_stg_table[i].print != NULL && - ((__kmp_display_env && + ((display_env && strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) || - __kmp_display_env_verbose)) { + display_env_verbose)) { __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name, __kmp_stg_table[i].data); } @@ -5754,7 +5758,6 @@ void __kmp_env_print_2() { __kmp_str_buf_free(&buffer); __kmp_printf("\n"); - -} // __kmp_env_print_2 +} // end of file diff --git a/openmp/runtime/src/kmp_settings.h b/openmp/runtime/src/kmp_settings.h index 3247ffc..d61c406 100644 --- a/openmp/runtime/src/kmp_settings.h +++ b/openmp/runtime/src/kmp_settings.h @@ -17,6 +17,7 @@ void __kmp_reset_global_vars(void); void __kmp_env_initialize(char const *); void __kmp_env_print(); void __kmp_env_print_2(); +void __kmp_display_env_impl(int display_env, int display_env_verbose); int __kmp_initial_threads_capacity(int req_nproc); void __kmp_init_dflt_team_nth(); diff --git a/openmp/runtime/test/api/omp_display_env0.c b/openmp/runtime/test/api/omp_display_env0.c new file mode 100644 index 0000000..afea3b9 --- /dev/null +++ b/openmp/runtime/test/api/omp_display_env0.c @@ -0,0 +1,14 @@ +// RUN: %libomp-compile-and-run 2>&1 | FileCheck %s +// RUN: %libomp-cxx-compile-and-run 2>&1 | FileCheck %s +#include +#include +int main() +{ + omp_display_env(0); + printf("passed\n"); + return 0; +} + +// CHECK: OPENMP DISPLAY ENVIRONMENT BEGIN +// CHECK: _OPENMP +// CHECK: OPENMP DISPLAY ENVIRONMENT END -- 2.7.4