diff options
author | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2018-12-13 23:14:24 +0000 |
---|---|---|
committer | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2018-12-13 23:14:24 +0000 |
commit | 6d88e049dc51be8a9ba2e853e17fdf8c4fa6026b (patch) | |
tree | 5791e2d26aeb82d58420cb0d8c23811fe7fc5951 /openmp/runtime/src/kmp_io.cpp | |
parent | 66c6c5abea94e3fcaef169f54b0c91e087ec15dc (diff) | |
download | bcm5719-llvm-6d88e049dc51be8a9ba2e853e17fdf8c4fa6026b.tar.gz bcm5719-llvm-6d88e049dc51be8a9ba2e853e17fdf8c4fa6026b.zip |
[OpenMP] Implement OpenMP 5.0 affinity format functionality
This patch adds the affinity format functionality introduced in OpenMP 5.0.
This patch adds: Two new environment variables:
OMP_DISPLAY_AFFINITY=TRUE|FALSE
OMP_AFFINITY_FORMAT=<string>
and Four new API:
1) omp_set_affinity_format()
2) omp_get_affinity_format()
3) omp_display_affinity()
4) omp_capture_affinity()
The affinity format functionality has two ICV's associated with it:
affinity-display-var (bool) and affinity-format-var (string).
The affinity-display-var enables/disables the functionality through the
envirable OMP_DISPLAY_AFFINITY. The affinity-format-var is a formatted
string with the special field types beginning with a '%' character
similar to printf
For example, the affinity-format-var could be:
"OMP: host:%H pid:%P OStid:%i num_threads:%N thread_num:%n affinity:{%A}"
The affinity-format-var is displayed by every thread implicitly at the beginning
of a parallel region when any thread's affinity has changed (including a brand
new thread being spawned), or explicitly using the omp_display_affinity() API.
The omp_capture_affinity() function can capture the affinity-format-var in a
char buffer. And omp_set|get_affinity_format() allow the user to set|get the
affinity-format-var explicitly at runtime. omp_capture_affinity() and
omp_get_affinity_format() both return the number of characters needed to hold
the entire string it tried to make (not including NULL character). If not
enough buffer space is available,
both these functions truncate their output.
Differential Revision: https://reviews.llvm.org/D55148
llvm-svn: 349089
Diffstat (limited to 'openmp/runtime/src/kmp_io.cpp')
-rw-r--r-- | openmp/runtime/src/kmp_io.cpp | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/openmp/runtime/src/kmp_io.cpp b/openmp/runtime/src/kmp_io.cpp index 73508330b77..24c6e725aef 100644 --- a/openmp/runtime/src/kmp_io.cpp +++ b/openmp/runtime/src/kmp_io.cpp @@ -46,10 +46,7 @@ kmp_bootstrap_lock_t __kmp_console_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( #if KMP_OS_WINDOWS -#ifdef KMP_DEBUG -/* __kmp_stdout is used only for dev build */ static HANDLE __kmp_stdout = NULL; -#endif static HANDLE __kmp_stderr = NULL; static int __kmp_console_exists = FALSE; static kmp_str_buf_t __kmp_console_buf; @@ -76,10 +73,7 @@ void __kmp_close_console(void) { /* wait until user presses return before closing window */ /* TODO only close if a window was opened */ if (__kmp_console_exists) { -#ifdef KMP_DEBUG - /* standard out is used only in dev build */ __kmp_stdout = NULL; -#endif __kmp_stderr = NULL; __kmp_str_buf_free(&__kmp_console_buf); __kmp_console_exists = FALSE; @@ -92,21 +86,17 @@ static void __kmp_redirect_output(void) { __kmp_acquire_bootstrap_lock(&__kmp_console_lock); if (!__kmp_console_exists) { -#ifdef KMP_DEBUG - /* standard out is used only in dev build */ HANDLE ho; -#endif HANDLE he; __kmp_str_buf_init(&__kmp_console_buf); AllocConsole(); -// We do not check the result of AllocConsole because -// 1. the call is harmless -// 2. it is not clear how to communicate failue -// 3. we will detect failure later when we get handle(s) + // We do not check the result of AllocConsole because + // 1. the call is harmless + // 2. it is not clear how to communicate failue + // 3. we will detect failure later when we get handle(s) -#ifdef KMP_DEBUG ho = GetStdHandle(STD_OUTPUT_HANDLE); if (ho == INVALID_HANDLE_VALUE || ho == NULL) { @@ -118,7 +108,6 @@ static void __kmp_redirect_output(void) { __kmp_stdout = ho; // temporary code, need new global for ho } -#endif he = GetStdHandle(STD_ERROR_HANDLE); if (he == INVALID_HANDLE_VALUE || he == NULL) { @@ -137,22 +126,22 @@ static void __kmp_redirect_output(void) { #else #define __kmp_stderr (stderr) +#define __kmp_stdout (stdout) #endif /* KMP_OS_WINDOWS */ -void __kmp_vprintf(enum kmp_io __kmp_io, char const *format, va_list ap) { +void __kmp_vprintf(enum kmp_io out_stream, char const *format, va_list ap) { #if KMP_OS_WINDOWS if (!__kmp_console_exists) { __kmp_redirect_output(); } - if (!__kmp_stderr && __kmp_io == kmp_err) { + if (!__kmp_stderr && out_stream == kmp_err) { return; } -#ifdef KMP_DEBUG - if (!__kmp_stdout && __kmp_io == kmp_out) { + if (!__kmp_stdout && out_stream == kmp_out) { return; } -#endif #endif /* KMP_OS_WINDOWS */ + auto stream = ((out_stream == kmp_out) ? __kmp_stdout : __kmp_stderr); if (__kmp_debug_buf && __kmp_debug_buffer != NULL) { @@ -174,14 +163,14 @@ void __kmp_vprintf(enum kmp_io __kmp_io, char const *format, va_list ap) { "overflow; increase " "KMP_DEBUG_BUF_CHARS to %d\n", chars + 1); - WriteFile(__kmp_stderr, __kmp_console_buf.str, __kmp_console_buf.used, - &count, NULL); + WriteFile(stream, __kmp_console_buf.str, __kmp_console_buf.used, &count, + NULL); __kmp_str_buf_clear(&__kmp_console_buf); #else - fprintf(__kmp_stderr, "OMP warning: Debugging buffer overflow; " - "increase KMP_DEBUG_BUF_CHARS to %d\n", + fprintf(stream, "OMP warning: Debugging buffer overflow; " + "increase KMP_DEBUG_BUF_CHARS to %d\n", chars + 1); - fflush(__kmp_stderr); + fflush(stream); #endif __kmp_debug_buf_warn_chars = chars + 1; } @@ -196,15 +185,15 @@ void __kmp_vprintf(enum kmp_io __kmp_io, char const *format, va_list ap) { __kmp_str_buf_print(&__kmp_console_buf, "pid=%d: ", (kmp_int32)getpid()); #endif __kmp_str_buf_vprint(&__kmp_console_buf, format, ap); - WriteFile(__kmp_stderr, __kmp_console_buf.str, __kmp_console_buf.used, - &count, NULL); + WriteFile(stream, __kmp_console_buf.str, __kmp_console_buf.used, &count, + NULL); __kmp_str_buf_clear(&__kmp_console_buf); #else #ifdef KMP_DEBUG_PIDS - fprintf(__kmp_stderr, "pid=%d: ", (kmp_int32)getpid()); + fprintf(stream, "pid=%d: ", (kmp_int32)getpid()); #endif - vfprintf(__kmp_stderr, format, ap); - fflush(__kmp_stderr); + vfprintf(stream, format, ap); + fflush(stream); #endif } } @@ -228,3 +217,14 @@ void __kmp_printf_no_lock(char const *format, ...) { va_end(ap); } + +void __kmp_fprintf(enum kmp_io stream, char const *format, ...) { + va_list ap; + va_start(ap, format); + + __kmp_acquire_bootstrap_lock(&__kmp_stdio_lock); + __kmp_vprintf(stream, format, ap); + __kmp_release_bootstrap_lock(&__kmp_stdio_lock); + + va_end(ap); +} |