diff --git a/runtime/src/include/30/omp.h.var b/runtime/src/include/30/omp.h.var index 10bd890cab01b0438f50745fd4b81303727e9987..c05c2e5761e857f043346fa0cbaefd74e2bdb715 100644 --- a/runtime/src/include/30/omp.h.var +++ b/runtime/src/include/30/omp.h.var @@ -113,6 +113,9 @@ extern double __KAI_KMPC_CONVENTION omp_get_wtime (void); extern double __KAI_KMPC_CONVENTION omp_get_wtick (void); + /* OpenMP 3.0 extension */ + extern void __KAI_KMPC_CONVENTION omp_set_task_priority (int priority); + # include <stdlib.h> /* kmp API functions */ extern int __KAI_KMPC_CONVENTION kmp_get_stacksize (void); diff --git a/runtime/src/include/40/omp.h.var b/runtime/src/include/40/omp.h.var index a8257367bc14178af8e5aeed910f49c6155b2e0c..e0b1984d0445262bd3cb28f40c957eb874c0dd17 100644 --- a/runtime/src/include/40/omp.h.var +++ b/runtime/src/include/40/omp.h.var @@ -105,6 +105,9 @@ extern double __KAI_KMPC_CONVENTION omp_get_wtime (void); extern double __KAI_KMPC_CONVENTION omp_get_wtick (void); + /* OpenMP 3.0 extension */ + extern void __KAI_KMPC_CONVENTION omp_set_task_priority (int priority); + /* OpenMP 4.0 extension */ #if OMP_EXTENSION_AFFINITY typedef enum omp_affinity_kind_t { diff --git a/runtime/src/include/45/omp.h.var b/runtime/src/include/45/omp.h.var index 8448821d9038fbae81d7557c74e3b657c4368483..746b486f0299cfe9f4ead217291b4a848ac5e1c0 100644 --- a/runtime/src/include/45/omp.h.var +++ b/runtime/src/include/45/omp.h.var @@ -123,6 +123,9 @@ extern double __KAI_KMPC_CONVENTION omp_get_wtick (void); + /* OpenMP 3.0 extension */ + extern void __KAI_KMPC_CONVENTION omp_set_task_priority (int priority); + /* OpenMP 4.0 extension */ #if OMP_EXTENSION_AFFINITY typedef enum omp_affinity_kind_t { diff --git a/runtime/src/include/50/omp.h.var b/runtime/src/include/50/omp.h.var index 9d9f0bb02a13a5a86654af8f864524e8269cc0e1..765e7fe6ed39f1f955d9d0b28f28768567db4ebd 100644 --- a/runtime/src/include/50/omp.h.var +++ b/runtime/src/include/50/omp.h.var @@ -123,6 +123,9 @@ extern double __KAI_KMPC_CONVENTION omp_get_wtime (void); extern double __KAI_KMPC_CONVENTION omp_get_wtick (void); + /* OpenMP 3.0 extension */ + extern void __KAI_KMPC_CONVENTION omp_set_task_priority (int priority); + /* OpenMP 4.0 extension */ #if OMP_EXTENSION_AFFINITY typedef enum omp_affinity_kind_t { diff --git a/runtime/src/kmp.h b/runtime/src/kmp.h index 82ccda31ae0b0b63704414327808837862991514..ee35b33b273d09e8976bede61ab54848dc62342f 100644 --- a/runtime/src/kmp.h +++ b/runtime/src/kmp.h @@ -2063,6 +2063,11 @@ typedef struct kmp_local { #define set__sched(xthread, xval) \ (((xthread)->th.th_current_task->td_icvs.sched) = (xval)) +#define set__priority( xthread, xval ) \ + ( ( (xthread)->th.th_task_priority ) = (xval) ) +#define get__priority( xthread ) \ + ( (xthread)->th.th_task_priority ) + #if OMP_40_ENABLED #define set__proc_bind(xthread, xval) \ @@ -2667,6 +2672,7 @@ typedef struct KMP_ALIGN_CACHE kmp_base_info { kmp_extra_depinfo_th_t th_edeps[2]; // [alias/noalias] kmp_extra_depinfo_th_t* th_edeps_tail[2]; // TG: tail pointers #endif + kmp_int32 th_task_priority; // #if OMPT_SUPPORT const char* th_task_name; // intptr_t th_task_key[2]; // @@ -3887,6 +3893,7 @@ void __kmpc_omp_task_complete(ident_t *loc_ref, kmp_int32 gtid, KMP_EXPORT void __kmpc_omp_set_task_affinity(kmp_uint32 kind, kmp_uint64 affinity, kmp_uint32 strict); KMP_EXPORT void __kmpc_omp_set_task_name(char *name); +KMP_EXPORT void __kmpc_omp_set_task_priority(int priority); KMP_EXPORT void __kmpc_omp_set_task_attr(char key, long int value); KMP_EXPORT void* __kmpc_omp_begin_sched_graph(int flag); KMP_EXPORT void __kmpc_omp_end_sched_graph(void* handle, int flag ); diff --git a/runtime/src/kmp_ftn_entry.h b/runtime/src/kmp_ftn_entry.h index e22dfa1620cb2477c3b4ddf84c58affb7b6081d4..cd96c7c696b33c1eeb1942f296665d3fe8545fe1 100644 --- a/runtime/src/kmp_ftn_entry.h +++ b/runtime/src/kmp_ftn_entry.h @@ -636,6 +636,16 @@ FTN_SET_TASK_NAME(char *name) #endif } +void FTN_STDCALL +FTN_SET_TASK_PRIORITY(int priority) +{ + #ifdef KMP_STUB + // nothing + #else + __kmpc_omp_set_task_priority(priority); + #endif +} + void FTN_STDCALL FTN_SET_TASK_ATTR(char key, long int value) { diff --git a/runtime/src/kmp_ftn_os.h b/runtime/src/kmp_ftn_os.h index 68de62145a9bb9520b429e728894dfe309145ce0..c3058159fa4501985c22a3e4ec90d6071cfeb643 100644 --- a/runtime/src/kmp_ftn_os.h +++ b/runtime/src/kmp_ftn_os.h @@ -85,6 +85,7 @@ #define FTN_INFO_ALLOC_SIZE omp_info_alloc_memory #define FTN_INFO_FREE_SIZE omp_info_free_memory #define FTN_SET_MEMORY_LIMIT omp_set_memory_limit +#define FTN_SET_TASK_PRIORITY omp_set_task_priority #if OMP_40_ENABLED #if LIBOMP_USE_VARDEP #define FN_TASK_DECLDEPS omp_task_declare_dependencies @@ -220,6 +221,7 @@ #define FTN_INFO_ALLOC_SIZE omp_info_alloc_memory_ #define FTN_INFO_FREE_SIZE omp_info_free_memory_ #define FTN_SET_MEMORY_LIMIT omp_set_memory_limit_ +#define FTN_SET_TASK_PRIORITY omp_set_task_priority_ #if OMP_40_ENABLED #if LIBOMP_USE_VARDEP #define FN_TASK_DECLDEPS omp_task_declare_dependencies_ @@ -356,6 +358,7 @@ #define FTN_INFO_ALLOC_SIZE OMP_INFO_ALLOC_MEMORY #define FTN_INFO_FREE_SIZE OMP_INFO_FREE_MEMORY #define FTN_SET_MEMORY_LIMIT OMP_SET_MEMORY_LIMIT +#define FTN_SET_TASK_PRIORITY OMP_SET_TASK_PRIORITY #if OMP_40_ENABLED #if LIBOMP_USE_VARDEP #define FN_TASK_DECLDEPS OMP_TASK_DECLARE_DEPENDENCIES @@ -492,6 +495,7 @@ #define FTN_INFO_ALLOC_SIZE OMP_INFO_ALLOC_MEMORY_ #define FTN_INFO_FREE_SIZE OMP_INFO_FREE_MEMORY_ #define FTN_SET_MEMORY_LIMIT OMP_SET_MEMORY_LIMIT_ +#define FTN_SET_TASK_PRIORITY OMP_SET_TASK_PRIORITY_ #if OMP_40_ENABLED #if LIBOMP_USE_VARDEP #define FN_TASK_DECLDEPS OMP_TASK_DECLARE_DEPENDENCIES_ diff --git a/runtime/src/kmp_tasking.cpp b/runtime/src/kmp_tasking.cpp index 60e19efd2d405297bfc9d73a051ab95193f1431a..06d47736d0740b527404c5122ab7a4c47f55afec 100644 --- a/runtime/src/kmp_tasking.cpp +++ b/runtime/src/kmp_tasking.cpp @@ -354,14 +354,18 @@ __kmp_push_task(kmp_int32 gtid, kmp_task_t * task ) #endif #if OMP_45_ENABLED + kmp_int32 priority; if (taskdata->td_flags.priority_specified) { - kmp_int32 priority = task->data2.priority; - if (priority < 0) priority = 0; - else if (priority > __kmp_max_task_priority) - priority = __kmp_max_task_priority; - taskdata->priority = priority; +//printf("Priority\n"); + priority = task->data2.priority; } + else priority = taskdata->priority; + + if (priority < 0) priority = 0; + else if (priority > __kmp_max_task_priority) + priority = __kmp_max_task_priority; + taskdata->priority = priority; #endif #if LIBOMP_USE_AFFINITY @@ -1502,6 +1506,10 @@ kmp_task_t* __kmp_task_alloc( ident_t *loc_ref, kmp_int32 gtid, kmp_tasking_flag #endif copy_icvs(&taskdata->td_icvs, &taskdata->td_parent->td_icvs); + // for ICC 2017,2018 -> pass through OMP extension + taskdata->priority = thread->th.th_task_priority; + thread->th.th_task_priority = 0; + #if OMPT_SUPPORT /* reset task name after creation */ taskdata->td_icvs.name = thread->th.th_task_name; @@ -2260,6 +2268,17 @@ __kmpc_end_push_init() { } + +//------------------------------------------------------------------------------------- +// __kmpc_omp_set_task_priority: set the priority for the next task to create +void +__kmpc_omp_set_task_priority(int priority) +{ + kmp_info_t * thread = __kmp_threads[ __kmp_entry_gtid() ]; + set__priority(thread, priority); +} + + //------------------------------------------------------------------------------------- // __kmpc_omp_set_task_name: set the name for the next task to create @@ -2875,8 +2894,26 @@ __kmp_steal_task( kmp_info_t *victim, kmp_int32 cpu, kmp_int32 node, // GEH: why would this happen? return 0; } + +#if OMP_45_ENABLED + /* look at task priority set before my local queue */ + for (kmp_int32 i = __kmp_max_task_priority-1; i>=0; --i) + { + if (task_team->tt.tt_task_queues_priority && + !kaapi_wsqueue_empty( &(task_team->tt.tt_task_queues_priority[i]->qd.td_wsdeque))) + { + taskdata = kaapi_wsqueue_locked_pop_task( &(task_team->tt.tt_task_queues_priority[i]->qd.td_wsdeque) ); + if (taskdata !=0) + { + task = KMP_TASKDATA_TO_TASK( taskdata ); + return task; + } + } + } #endif +#endif // LIBOMP_USE_THEQUEUE||LIBOMP_USE_LINKED_DEQUEUE + threads_data = task_team->tt.tt_threads_data; KMP_DEBUG_ASSERT(threads_data != NULL); // Caller should check this condition