@@ -1651,11 +1651,11 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
16511651 }
16521652
16531653#if OMPX_TASKGRAPH
1654- kmp_tdg_info_t *tdg = __kmp_curr_tdg ;
1654+ kmp_tdg_info_t *tdg = __kmp_find_tdg (__kmp_curr_tdg_idx) ;
16551655 if (tdg && __kmp_tdg_is_recording (tdg->tdg_status ) &&
16561656 (task_entry != (kmp_routine_entry_t )__kmp_taskloop_task)) {
16571657 taskdata->is_taskgraph = 1 ;
1658- taskdata->tdg = tdg ;
1658+ taskdata->tdg = __kmp_global_tdgs[__kmp_curr_tdg_idx] ;
16591659 taskdata->td_task_id = KMP_GEN_TASK_ID ();
16601660 taskdata->td_tdg_task_id = KMP_ATOMIC_INC (&__kmp_tdg_task_id);
16611661 }
@@ -2577,11 +2577,14 @@ without help of the runtime library.
25772577*/
25782578void *__kmpc_task_reduction_init (int gtid, int num, void *data) {
25792579#if OMPX_TASKGRAPH
2580- kmp_tdg_info_t *tdg = __kmp_curr_tdg ;
2580+ kmp_tdg_info_t *tdg = __kmp_find_tdg (__kmp_curr_tdg_idx) ;
25812581 if (tdg && __kmp_tdg_is_recording (tdg->tdg_status )) {
2582- tdg->rec_taskred_data = __kmp_allocate (sizeof (kmp_task_red_input_t ) * num);
2583- tdg->rec_num_taskred = num;
2584- KMP_MEMCPY (tdg->rec_taskred_data , data, sizeof (kmp_task_red_input_t ) * num);
2582+ kmp_tdg_info_t *this_tdg = __kmp_global_tdgs[__kmp_curr_tdg_idx];
2583+ this_tdg->rec_taskred_data =
2584+ __kmp_allocate (sizeof (kmp_task_red_input_t ) * num);
2585+ this_tdg->rec_num_taskred = num;
2586+ KMP_MEMCPY (this_tdg->rec_taskred_data , data,
2587+ sizeof (kmp_task_red_input_t ) * num);
25852588 }
25862589#endif
25872590 return __kmp_task_reduction_init (gtid, num, (kmp_task_red_input_t *)data);
@@ -2601,11 +2604,14 @@ has two parameters, pointer to object to be initialized and pointer to omp_orig
26012604*/
26022605void *__kmpc_taskred_init (int gtid, int num, void *data) {
26032606#if OMPX_TASKGRAPH
2604- kmp_tdg_info_t *tdg = __kmp_curr_tdg ;
2607+ kmp_tdg_info_t *tdg = __kmp_find_tdg (__kmp_curr_tdg_idx) ;
26052608 if (tdg && __kmp_tdg_is_recording (tdg->tdg_status )) {
2606- tdg->rec_taskred_data = __kmp_allocate (sizeof (kmp_task_red_input_t ) * num);
2607- tdg->rec_num_taskred = num;
2608- KMP_MEMCPY (tdg->rec_taskred_data , data, sizeof (kmp_task_red_input_t ) * num);
2609+ kmp_tdg_info_t *this_tdg = __kmp_global_tdgs[__kmp_curr_tdg_idx];
2610+ this_tdg->rec_taskred_data =
2611+ __kmp_allocate (sizeof (kmp_task_red_input_t ) * num);
2612+ this_tdg->rec_num_taskred = num;
2613+ KMP_MEMCPY (this_tdg->rec_taskred_data , data,
2614+ sizeof (kmp_task_red_input_t ) * num);
26092615 }
26102616#endif
26112617 return __kmp_task_reduction_init (gtid, num, (kmp_taskred_input_t *)data);
@@ -2656,7 +2662,8 @@ void *__kmpc_task_reduction_get_th_data(int gtid, void *tskgrp, void *data) {
26562662
26572663#if OMPX_TASKGRAPH
26582664 if ((thread->th .th_current_task ->is_taskgraph ) &&
2659- (!__kmp_tdg_is_recording (__kmp_curr_tdg->tdg_status ))) {
2665+ (!__kmp_tdg_is_recording (
2666+ __kmp_global_tdgs[__kmp_curr_tdg_idx]->tdg_status ))) {
26602667 tg = thread->th .th_current_task ->td_taskgroup ;
26612668 KMP_ASSERT (tg != NULL );
26622669 KMP_ASSERT (tg->reduce_data != NULL );
@@ -5445,6 +5452,7 @@ bool __kmpc_omp_has_task_team(kmp_int32 gtid) {
54455452
54465453#if OMPX_TASKGRAPH
54475454// __kmp_find_tdg: identify a TDG through its ID
5455+ // gtid: Global Thread ID
54485456// tdg_id: ID of the TDG
54495457// returns: If a TDG corresponding to this ID is found and not
54505458// its initial state, return the pointer to it, otherwise nullptr
@@ -5457,71 +5465,12 @@ static kmp_tdg_info_t *__kmp_find_tdg(kmp_int32 tdg_id) {
54575465 __kmp_global_tdgs = (kmp_tdg_info_t **)__kmp_allocate (
54585466 sizeof (kmp_tdg_info_t *) * __kmp_max_tdgs);
54595467
5460- for (kmp_int32 tdg_idx = 0 ; tdg_idx < __kmp_max_tdgs; tdg_idx++) {
5461- if (__kmp_global_tdgs[tdg_idx] &&
5462- __kmp_global_tdgs[tdg_idx]->tdg_id == tdg_id) {
5463- if (__kmp_global_tdgs[tdg_idx]->tdg_status != KMP_TDG_NONE)
5464- res = __kmp_global_tdgs[tdg_idx];
5465- break ;
5466- }
5467- }
5468+ if ((__kmp_global_tdgs[tdg_id]) &&
5469+ (__kmp_global_tdgs[tdg_id]->tdg_status != KMP_TDG_NONE))
5470+ res = __kmp_global_tdgs[tdg_id];
54685471 return res;
54695472}
54705473
5471- // __kmp_alloc_tdg: Allocates a TDG if it doesn't already exist.
5472- // tdg_id: ID of the TDG.
5473- // returns: A pointer to the TDG if it already exists. Otherwise,
5474- // allocates a new TDG if the maximum limit has not been reached.
5475- // Returns nullptr if no TDG can be allocated.
5476- static kmp_tdg_info_t *__kmp_alloc_tdg (kmp_int32 tdg_id) {
5477- kmp_tdg_info_t *res = nullptr ;
5478- if ((res = __kmp_find_tdg (tdg_id)))
5479- return res;
5480-
5481- if (__kmp_num_tdg > __kmp_max_tdgs)
5482- return res;
5483-
5484- for (kmp_int32 tdg_idx = 0 ; tdg_idx < __kmp_max_tdgs; tdg_idx++) {
5485- if (!__kmp_global_tdgs[tdg_idx]) {
5486- kmp_tdg_info_t *tdg =
5487- (kmp_tdg_info_t *)__kmp_allocate (sizeof (kmp_tdg_info_t ));
5488- __kmp_global_tdgs[tdg_idx] = tdg;
5489- __kmp_curr_tdg = tdg;
5490- res = __kmp_global_tdgs[tdg_idx];
5491- break ;
5492- }
5493- }
5494- return res;
5495- }
5496-
5497- // __kmp_free_tdg: Frees a TDG if it exists.
5498- // tdg_id: ID of the TDG to be freed.
5499- // returns: true if a TDG with the given ID was found and successfully freed,
5500- // false if no such TDG exists.
5501- static bool __kmp_free_tdg (kmp_int32 tdg_id) {
5502- kmp_tdg_info_t *tdg = nullptr ;
5503- if (__kmp_global_tdgs == NULL )
5504- return false ;
5505-
5506- for (kmp_int32 tdg_idx = 0 ; tdg_idx < __kmp_max_tdgs; tdg_idx++) {
5507- if (__kmp_global_tdgs[tdg_idx] &&
5508- __kmp_global_tdgs[tdg_idx]->tdg_id == tdg_id) {
5509- tdg = __kmp_global_tdgs[tdg_idx];
5510- for (kmp_int map_idx = 0 ; map_idx < tdg->map_size ; map_idx++) {
5511- __kmp_free (tdg->record_map [map_idx].successors );
5512- }
5513- __kmp_free (tdg->record_map );
5514- if (tdg->root_tasks )
5515- __kmp_free (tdg->root_tasks );
5516-
5517- __kmp_free (tdg);
5518- __kmp_global_tdgs[tdg_idx] = NULL ;
5519- return true ;
5520- }
5521- }
5522- return false ;
5523- }
5524-
55255474// __kmp_print_tdg_dot: prints the TDG to a dot file
55265475// tdg: ID of the TDG
55275476// gtid: Global Thread ID
@@ -5556,7 +5505,7 @@ void __kmp_print_tdg_dot(kmp_tdg_info_t *tdg, kmp_int32 gtid) {
55565505 KA_TRACE (10 , (" __kmp_print_tdg_dot(exit): T#%d tdg_id=%d \n " , gtid, tdg_id));
55575506}
55585507
5559- // __kmp_exec_tdg : launch the execution of a previous
5508+ // __kmp_start_record : launch the execution of a previous
55605509// recorded TDG
55615510// gtid: Global Thread ID
55625511// tdg: ID of the TDG
@@ -5616,7 +5565,9 @@ void __kmp_exec_tdg(kmp_int32 gtid, kmp_tdg_info_t *tdg) {
56165565static inline void __kmp_start_record (kmp_int32 gtid,
56175566 kmp_taskgraph_flags_t *flags,
56185567 kmp_int32 tdg_id) {
5619- kmp_tdg_info_t *tdg = __kmp_alloc_tdg (tdg_id);
5568+ kmp_tdg_info_t *tdg =
5569+ (kmp_tdg_info_t *)__kmp_allocate (sizeof (kmp_tdg_info_t ));
5570+ __kmp_global_tdgs[__kmp_curr_tdg_idx] = tdg;
56205571 // Initializing the TDG structure
56215572 tdg->tdg_id = tdg_id;
56225573 tdg->map_size = INIT_MAPSIZE;
@@ -5641,42 +5592,42 @@ static inline void __kmp_start_record(kmp_int32 gtid,
56415592 KMP_ATOMIC_ST_RLX (&this_record_map[i].npredecessors_counter , 0 );
56425593 }
56435594
5644- tdg ->record_map = this_record_map;
5595+ __kmp_global_tdgs[__kmp_curr_tdg_idx] ->record_map = this_record_map;
56455596}
56465597
56475598// __kmpc_start_record_task: Wrapper around __kmp_start_record to mark
56485599// the beginning of the record process of a task region
56495600// loc_ref: Location of TDG, not used yet
56505601// gtid: Global Thread ID of the encountering thread
56515602// input_flags: Flags associated with the TDG
5652- // tdg_id: ID of the TDG to record
5603+ // tdg_id: ID of the TDG to record, for now, incremental integer
56535604// returns: 1 if we record, otherwise, 0
56545605kmp_int32 __kmpc_start_record_task (ident_t *loc_ref, kmp_int32 gtid,
56555606 kmp_int32 input_flags, kmp_int32 tdg_id) {
5607+
56565608 kmp_int32 res;
56575609 kmp_taskgraph_flags_t *flags = (kmp_taskgraph_flags_t *)&input_flags;
5658- KA_TRACE (10 , ( " __kmpc_start_record_task(enter): T#%d loc=%p flags=%d "
5659- " tdg_id=%d\n " ,
5660- gtid, loc_ref, input_flags, tdg_id));
5610+ KA_TRACE (10 ,
5611+ ( " __kmpc_start_record_task(enter): T#%d loc=%p flags=%d tdg_id=%d\n " ,
5612+ gtid, loc_ref, input_flags, tdg_id));
56615613
56625614 if (__kmp_max_tdgs == 0 ) {
5663- KA_TRACE (10 , (" __kmpc_start_record_task(abandon): T#%d loc=%p flags=%d "
5664- " tdg_id = %d, __kmp_max_tdgs = 0\n " ,
5665- gtid, loc_ref, input_flags, tdg_id));
5615+ KA_TRACE (
5616+ 10 ,
5617+ (" __kmpc_start_record_task(abandon): T#%d loc=%p flags=%d tdg_id = %d, "
5618+ " __kmp_max_tdgs = 0\n " ,
5619+ gtid, loc_ref, input_flags, tdg_id));
56665620 return 1 ;
56675621 }
56685622
56695623 __kmpc_taskgroup (loc_ref, gtid);
5670- if (flags->graph_reset ) {
5671- __kmp_free_tdg (tdg_id);
5672- __kmp_num_tdg--;
5673- }
56745624 if (kmp_tdg_info_t *tdg = __kmp_find_tdg (tdg_id)) {
56755625 // TODO: use re_record flag
56765626 __kmp_exec_tdg (gtid, tdg);
56775627 res = 0 ;
56785628 } else {
5679- KMP_DEBUG_ASSERT (__kmp_num_tdg < __kmp_max_tdgs);
5629+ __kmp_curr_tdg_idx = tdg_id;
5630+ KMP_DEBUG_ASSERT (__kmp_curr_tdg_idx < __kmp_max_tdgs);
56805631 __kmp_start_record (gtid, flags, tdg_id);
56815632 __kmp_num_tdg++;
56825633 res = 1 ;
@@ -5739,11 +5690,10 @@ void __kmpc_end_record_task(ident_t *loc_ref, kmp_int32 gtid,
57395690 kmp_int32 input_flags, kmp_int32 tdg_id) {
57405691 kmp_tdg_info_t *tdg = __kmp_find_tdg (tdg_id);
57415692
5742- KMP_DEBUG_ASSERT (tdg != NULL );
57435693 KA_TRACE (10 , (" __kmpc_end_record_task(enter): T#%d loc=%p finishes recording"
57445694 " tdg=%d with flags=%d\n " ,
57455695 gtid, loc_ref, tdg_id, input_flags));
5746- if (__kmp_max_tdgs && tdg ) {
5696+ if (__kmp_max_tdgs) {
57475697 // TODO: use input_flags->nowait
57485698 __kmpc_end_taskgroup (loc_ref, gtid);
57495699 if (__kmp_tdg_is_recording (tdg->tdg_status ))
0 commit comments