Skip to content

Commit 7b8130c

Browse files
authored
[OpenMP][VE] Limit the number of threads to create (#66729)
VE supports up to 64 threads per a VE process. So, we limit the number of threads defined by KMP_MAX_NTH. We also modify the __kmp_sys_max_nth initialization to use KMP_MAX_NTH as a limit.
1 parent 1446e3c commit 7b8130c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

openmp/runtime/src/kmp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,8 +1153,15 @@ extern void __kmp_init_target_task();
11531153
#if defined(PTHREAD_THREADS_MAX) && PTHREAD_THREADS_MAX < INT_MAX
11541154
#define KMP_MAX_NTH PTHREAD_THREADS_MAX
11551155
#else
1156+
#ifdef __ve__
1157+
// VE's pthread supports only up to 64 threads per a VE process.
1158+
// Please check p. 14 of following documentation for more details.
1159+
// https://sxauroratsubasa.sakura.ne.jp/documents/veos/en/VEOS_high_level_design.pdf
1160+
#define KMP_MAX_NTH 64
1161+
#else
11561162
#define KMP_MAX_NTH INT_MAX
11571163
#endif
1164+
#endif
11581165
#endif /* KMP_MAX_NTH */
11591166

11601167
#ifdef PTHREAD_STACK_MIN

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,13 +1894,21 @@ void __kmp_runtime_initialize(void) {
18941894

18951895
/* Query the maximum number of threads */
18961896
__kmp_type_convert(sysconf(_SC_THREAD_THREADS_MAX), &(__kmp_sys_max_nth));
1897+
#ifdef __ve__
1898+
if (__kmp_sys_max_nth == -1) {
1899+
// VE's pthread supports only up to 64 threads per a VE process.
1900+
// So we use that KMP_MAX_NTH (predefined as 64) here.
1901+
__kmp_sys_max_nth = KMP_MAX_NTH;
1902+
}
1903+
#else
18971904
if (__kmp_sys_max_nth == -1) {
18981905
/* Unlimited threads for NPTL */
18991906
__kmp_sys_max_nth = INT_MAX;
19001907
} else if (__kmp_sys_max_nth <= 1) {
19011908
/* Can't tell, just use PTHREAD_THREADS_MAX */
19021909
__kmp_sys_max_nth = KMP_MAX_NTH;
19031910
}
1911+
#endif
19041912

19051913
/* Query the minimum stack size */
19061914
__kmp_sys_min_stksize = sysconf(_SC_THREAD_STACK_MIN);

0 commit comments

Comments
 (0)