Index: openmp/trunk/runtime/src/dllexports =================================================================== --- openmp/trunk/runtime/src/dllexports +++ openmp/trunk/runtime/src/dllexports @@ -498,6 +498,12 @@ omp_init_lock_with_hint 870 omp_init_nest_lock_with_hint 871 omp_get_max_task_priority 872 + omp_get_num_places 873 + omp_get_place_num_procs 874 + omp_get_place_proc_ids 875 + omp_get_place_num 876 + omp_get_partition_num_places 877 + omp_get_partition_place_nums 878 %endif # OMP_41 %ifndef stub Index: openmp/trunk/runtime/src/include/41/omp.h.var =================================================================== --- openmp/trunk/runtime/src/include/41/omp.h.var +++ openmp/trunk/runtime/src/include/41/omp.h.var @@ -153,6 +153,14 @@ extern omp_proc_bind_t __KAI_KMPC_CONVENTION omp_get_proc_bind (void); + /* OpenMP 4.5 affinity API */ + extern int __KAI_KMPC_CONVENTION omp_get_num_places (void); + extern int __KAI_KMPC_CONVENTION omp_get_place_num_procs (int); + extern void __KAI_KMPC_CONVENTION omp_get_place_proc_ids (int, int *); + extern int __KAI_KMPC_CONVENTION omp_get_place_num (void); + extern int __KAI_KMPC_CONVENTION omp_get_partition_num_places (void); + extern void __KAI_KMPC_CONVENTION omp_get_partition_place_nums (int *); + extern void * __KAI_KMPC_CONVENTION kmp_malloc (size_t); extern void * __KAI_KMPC_CONVENTION kmp_calloc (size_t, size_t); extern void * __KAI_KMPC_CONVENTION kmp_realloc (void *, size_t); Index: openmp/trunk/runtime/src/include/41/omp_lib.h.var =================================================================== --- openmp/trunk/runtime/src/include/41/omp_lib.h.var +++ openmp/trunk/runtime/src/include/41/omp_lib.h.var @@ -172,6 +172,38 @@ integer (kind=omp_proc_bind_kind) omp_get_proc_bind end function omp_get_proc_bind + function omp_get_num_places() bind(c) + import + integer (kind=omp_integer_kind) omp_get_num_places + end function omp_get_num_places + + function omp_get_place_num_procs(place_num) bind(c) + import + integer (kind=omp_integer_kind), value :: place_num + integer (kind=omp_integer_kind) omp_get_place_num_procs + end function omp_get_place_num_procs + + subroutine omp_get_place_proc_ids(place_num, ids) bind(c) + import + integer (kind=omp_integer_kind), value :: place_num + integer (kind=kmp_pointer_kind) ids + end subroutine omp_get_place_proc_ids + + function omp_get_place_num() bind(c) + import + integer (kind=omp_integer_kind) omp_get_place_num + end function omp_get_place_num + + function omp_get_partition_num_places() bind(c) + import + integer (kind=omp_integer_kind) omp_get_partition_num_places + end function omp_get_partition_num_places + + subroutine omp_get_partition_place_nums(place_nums) bind(c) + import + integer (kind=kmp_pointer_kind) place_nums + end subroutine omp_get_partition_place_nums + function omp_get_wtime() bind(c) double precision omp_get_wtime end function omp_get_wtime Index: openmp/trunk/runtime/src/include/41/omp_lib.f.var =================================================================== --- openmp/trunk/runtime/src/include/41/omp_lib.f.var +++ openmp/trunk/runtime/src/include/41/omp_lib.f.var @@ -180,6 +180,38 @@ integer (kind=omp_proc_bind_kind) omp_get_proc_bind end function omp_get_proc_bind + function omp_get_num_places() + use omp_lib_kinds + integer (kind=omp_integer_kind) omp_get_num_places + end function omp_get_num_places + + function omp_get_place_num_procs(place_num) + use omp_lib_kinds + integer (kind=omp_integer_kind) place_num + integer (kind=omp_integer_kind) omp_get_place_num_procs + end function omp_get_place_num_procs + + subroutine omp_get_place_proc_ids(place_num, ids) + use omp_lib_kinds + integer (kind=omp_integer_kind) place_num + integer (kind=kmp_pointer_kind) ids + end subroutine omp_get_place_proc_ids + + function omp_get_place_num() + use omp_lib_kinds + integer (kind=omp_integer_kind) omp_get_place_num + end function omp_get_place_num + + function omp_get_partition_num_places() + use omp_lib_kinds + integer (kind=omp_integer_kind) omp_get_partition_num_places + end function omp_get_partition_num_places + + subroutine omp_get_partition_place_nums(place_nums) + use omp_lib_kinds + integer (kind=kmp_pointer_kind) place_nums + end subroutine omp_get_partition_place_nums + function omp_get_wtime() double precision omp_get_wtime end function omp_get_wtime Index: openmp/trunk/runtime/src/include/41/omp_lib.f90.var =================================================================== --- openmp/trunk/runtime/src/include/41/omp_lib.f90.var +++ openmp/trunk/runtime/src/include/41/omp_lib.f90.var @@ -183,6 +183,38 @@ integer (kind=omp_proc_bind_kind) omp_get_proc_bind end function omp_get_proc_bind + function omp_get_num_places() bind(c) + use omp_lib_kinds + integer (kind=omp_integer_kind) omp_get_num_places + end function omp_get_num_places + + function omp_get_place_num_procs(place_num) bind(c) + use omp_lib_kinds + integer (kind=omp_integer_kind), value :: place_num + integer (kind=omp_integer_kind) omp_get_place_num_procs + end function omp_get_place_num_procs + + subroutine omp_get_place_proc_ids(place_num, ids) bind(c) + use omp_lib_kinds + integer (kind=omp_integer_kind), value :: place_num + integer (kind=kmp_pointer_kind) ids + end subroutine omp_get_place_proc_ids + + function omp_get_place_num() bind(c) + use omp_lib_kinds + integer (kind=omp_integer_kind) omp_get_place_num + end function omp_get_place_num + + function omp_get_partition_num_places() bind(c) + use omp_lib_kinds + integer (kind=omp_integer_kind) omp_get_partition_num_places + end function omp_get_partition_num_places + + subroutine omp_get_partition_place_nums(place_nums) bind(c) + use omp_lib_kinds + integer (kind=kmp_pointer_kind) place_nums + end subroutine omp_get_partition_place_nums + function omp_get_wtime() bind(c) use omp_lib_kinds real (kind=kmp_double_kind) omp_get_wtime Index: openmp/trunk/runtime/src/kmp_ftn_entry.h =================================================================== --- openmp/trunk/runtime/src/kmp_ftn_entry.h +++ openmp/trunk/runtime/src/kmp_ftn_entry.h @@ -676,6 +676,139 @@ #endif } +#if OMP_41_ENABLED +int FTN_STDCALL +FTN_GET_NUM_PLACES( void ) +{ + #if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED + return 0; + #else + if ( ! TCR_4(__kmp_init_middle) ) { + __kmp_middle_initialize(); + } + return __kmp_affinity_num_masks; + #endif +} + +int FTN_STDCALL +FTN_GET_PLACE_NUM_PROCS( int place_num ) +{ + #if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED + return 0; + #else + int i; + int retval = 0; + if ( ! TCR_4(__kmp_init_middle) ) { + __kmp_middle_initialize(); + } + if ( place_num < 0 || place_num >= (int)__kmp_affinity_num_masks ) + return 0; + kmp_affin_mask_t *mask = KMP_CPU_INDEX(__kmp_affinity_masks, place_num); + KMP_CPU_SET_ITERATE(i, mask) { + if ( !KMP_CPU_ISSET(i, mask) ) + continue; + ++retval; + } + return retval; + #endif +} + +void FTN_STDCALL +FTN_GET_PLACE_PROC_IDS( int place_num, int *ids ) +{ + #if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED + // Nothing. + #else + int i,j; + if ( ! TCR_4(__kmp_init_middle) ) { + __kmp_middle_initialize(); + } + if ( place_num < 0 || place_num >= (int)__kmp_affinity_num_masks ) + return; + kmp_affin_mask_t *mask = KMP_CPU_INDEX(__kmp_affinity_masks, place_num); + j = 0; + KMP_CPU_SET_ITERATE(i, mask) { + if ( !KMP_CPU_ISSET(i, mask) ) + continue; + ids[j++] = i; + } + #endif +} + +int FTN_STDCALL +FTN_GET_PLACE_NUM( void ) +{ + #if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED + return -1; + #else + int gtid; + kmp_info_t *thread; + if ( ! TCR_4(__kmp_init_middle) ) { + __kmp_middle_initialize(); + } + gtid = __kmp_entry_gtid(); + thread = __kmp_thread_from_gtid(gtid); + if ( thread->th.th_current_place < 0 ) + return -1; + return thread->th.th_current_place; + #endif +} + +int FTN_STDCALL +FTN_GET_PARTITION_NUM_PLACES( void ) +{ + #if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED + return 0; + #else + int gtid, num_places, first_place, last_place; + kmp_info_t *thread; + if ( ! TCR_4(__kmp_init_middle) ) { + __kmp_middle_initialize(); + } + gtid = __kmp_entry_gtid(); + thread = __kmp_thread_from_gtid(gtid); + first_place = thread->th.th_first_place; + last_place = thread->th.th_last_place; + if ( first_place < 0 || last_place < 0 ) + return 0; + if ( first_place <= last_place ) + num_places = last_place - first_place + 1; + else + num_places = __kmp_affinity_num_masks - first_place + last_place + 1; + return num_places; + #endif +} + +void FTN_STDCALL +FTN_GET_PARTITION_PLACE_NUMS( int *place_nums ) { + #if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED + // Nothing. + #else + int i, gtid, place_num, first_place, last_place, start, end; + kmp_info_t *thread; + if ( ! TCR_4(__kmp_init_middle) ) { + __kmp_middle_initialize(); + } + gtid = __kmp_entry_gtid(); + thread = __kmp_thread_from_gtid(gtid); + first_place = thread->th.th_first_place; + last_place = thread->th.th_last_place; + if ( first_place < 0 || last_place < 0 ) + return; + if ( first_place <= last_place ) { + start = first_place; + end = last_place; + } else { + start = last_place; + end = first_place; + } + for (i = 0, place_num = start; place_num <= end; ++place_num, ++i) { + place_nums[i] = place_num; + } + #endif +} +#endif + int FTN_STDCALL xexpand(FTN_GET_NUM_TEAMS)( void ) { Index: openmp/trunk/runtime/src/kmp_ftn_os.h =================================================================== --- openmp/trunk/runtime/src/kmp_ftn_os.h +++ openmp/trunk/runtime/src/kmp_ftn_os.h @@ -115,6 +115,12 @@ #if OMP_41_ENABLED #define FTN_GET_MAX_TASK_PRIORITY omp_get_max_task_priority + #define FTN_GET_NUM_PLACES omp_get_num_places + #define FTN_GET_PLACE_NUM_PROCS omp_get_place_num_procs + #define FTN_GET_PLACE_PROC_IDS omp_get_place_proc_ids + #define FTN_GET_PLACE_NUM omp_get_place_num + #define FTN_GET_PARTITION_NUM_PLACES omp_get_partition_num_places + #define FTN_GET_PARTITION_PLACE_NUMS omp_get_partition_place_nums #endif #endif /* KMP_FTN_PLAIN */ @@ -216,6 +222,12 @@ #if OMP_41_ENABLED #define FTN_GET_MAX_TASK_PRIORITY omp_get_max_task_priority_ + #define FTN_GET_NUM_PLACES omp_get_num_places_ + #define FTN_GET_PLACE_NUM_PROCS omp_get_place_num_procs_ + #define FTN_GET_PLACE_PROC_IDS omp_get_place_proc_ids_ + #define FTN_GET_PLACE_NUM omp_get_place_num_ + #define FTN_GET_PARTITION_NUM_PLACES omp_get_partition_num_places_ + #define FTN_GET_PARTITION_PLACE_NUMS omp_get_partition_place_nums_ #endif #endif /* KMP_FTN_APPEND */ @@ -317,6 +329,12 @@ #if OMP_41_ENABLED #define FTN_GET_MAX_TASK_PRIORITY OMP_GET_MAX_TASK_PRIORITY + #define FTN_GET_NUM_PLACES OMP_GET_NUM_PLACES + #define FTN_GET_PLACE_NUM_PROCS OMP_GET_PLACE_NUM_PROCS + #define FTN_GET_PLACE_PROC_IDS OMP_GET_PLACE_PROC_IDS + #define FTN_GET_PLACE_NUM OMP_GET_PLACE_NUM + #define FTN_GET_PARTITION_NUM_PLACES OMP_GET_PARTITION_NUM_PLACES + #define FTN_GET_PARTITION_PLACE_NUMS OMP_GET_PARTITION_PLACE_NUMS #endif #endif /* KMP_FTN_UPPER */ @@ -418,6 +436,12 @@ #if OMP_41_ENABLED #define FTN_GET_MAX_TASK_PRIORITY OMP_GET_MAX_TASK_PRIORITY_ + #define FTN_GET_NUM_PLACES OMP_GET_NUM_PLACES_ + #define FTN_GET_PLACE_NUM_PROCS OMP_GET_PLACE_NUM_PROCS_ + #define FTN_GET_PLACE_PROC_IDS OMP_GET_PLACE_PROC_IDS_ + #define FTN_GET_PLACE_NUM OMP_GET_PLACE_NUM_ + #define FTN_GET_PARTITION_NUM_PLACES OMP_GET_PARTITION_NUM_PLACES_ + #define FTN_GET_PARTITION_PLACE_NUMS OMP_GET_PARTITION_PLACE_NUMS_ #endif #endif /* KMP_FTN_UAPPEND */ Index: openmp/trunk/runtime/src/kmp_runtime.c =================================================================== --- openmp/trunk/runtime/src/kmp_runtime.c +++ openmp/trunk/runtime/src/kmp_runtime.c @@ -3834,6 +3834,13 @@ KMP_DEBUG_ASSERT( root->r.r_hot_team->t.t_bar[ bs_forkjoin_barrier ].b_arrived == KMP_INIT_BARRIER_STATE ); #if KMP_AFFINITY_SUPPORTED +# if OMP_40_ENABLED + root_thread->th.th_current_place = KMP_PLACE_UNDEFINED; + root_thread->th.th_new_place = KMP_PLACE_UNDEFINED; + root_thread->th.th_first_place = KMP_PLACE_UNDEFINED; + root_thread->th.th_last_place = KMP_PLACE_UNDEFINED; +# endif + if ( TCR_4(__kmp_init_middle) ) { __kmp_affinity_set_init_mask( gtid, TRUE ); }