@@ -1651,11 +1651,11 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
1651
1651
}
1652
1652
1653
1653
#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) ;
1655
1655
if (tdg && __kmp_tdg_is_recording (tdg->tdg_status ) &&
1656
1656
(task_entry != (kmp_routine_entry_t )__kmp_taskloop_task)) {
1657
1657
taskdata->is_taskgraph = 1 ;
1658
- taskdata->tdg = tdg ;
1658
+ taskdata->tdg = __kmp_global_tdgs[__kmp_curr_tdg_idx] ;
1659
1659
taskdata->td_task_id = KMP_GEN_TASK_ID ();
1660
1660
taskdata->td_tdg_task_id = KMP_ATOMIC_INC (&__kmp_tdg_task_id);
1661
1661
}
@@ -2577,11 +2577,14 @@ without help of the runtime library.
2577
2577
*/
2578
2578
void *__kmpc_task_reduction_init (int gtid, int num, void *data) {
2579
2579
#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) ;
2581
2581
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);
2585
2588
}
2586
2589
#endif
2587
2590
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
2601
2604
*/
2602
2605
void *__kmpc_taskred_init (int gtid, int num, void *data) {
2603
2606
#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) ;
2605
2608
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);
2609
2615
}
2610
2616
#endif
2611
2617
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) {
2656
2662
2657
2663
#if OMPX_TASKGRAPH
2658
2664
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 ))) {
2660
2667
tg = thread->th .th_current_task ->td_taskgroup ;
2661
2668
KMP_ASSERT (tg != NULL );
2662
2669
KMP_ASSERT (tg->reduce_data != NULL );
@@ -5445,6 +5452,7 @@ bool __kmpc_omp_has_task_team(kmp_int32 gtid) {
5445
5452
5446
5453
#if OMPX_TASKGRAPH
5447
5454
// __kmp_find_tdg: identify a TDG through its ID
5455
+ // gtid: Global Thread ID
5448
5456
// tdg_id: ID of the TDG
5449
5457
// returns: If a TDG corresponding to this ID is found and not
5450
5458
// 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) {
5457
5465
__kmp_global_tdgs = (kmp_tdg_info_t **)__kmp_allocate (
5458
5466
sizeof (kmp_tdg_info_t *) * __kmp_max_tdgs);
5459
5467
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];
5468
5471
return res;
5469
5472
}
5470
5473
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
-
5525
5474
// __kmp_print_tdg_dot: prints the TDG to a dot file
5526
5475
// tdg: ID of the TDG
5527
5476
// gtid: Global Thread ID
@@ -5556,7 +5505,7 @@ void __kmp_print_tdg_dot(kmp_tdg_info_t *tdg, kmp_int32 gtid) {
5556
5505
KA_TRACE (10 , (" __kmp_print_tdg_dot(exit): T#%d tdg_id=%d \n " , gtid, tdg_id));
5557
5506
}
5558
5507
5559
- // __kmp_exec_tdg : launch the execution of a previous
5508
+ // __kmp_start_record : launch the execution of a previous
5560
5509
// recorded TDG
5561
5510
// gtid: Global Thread ID
5562
5511
// tdg: ID of the TDG
@@ -5616,7 +5565,9 @@ void __kmp_exec_tdg(kmp_int32 gtid, kmp_tdg_info_t *tdg) {
5616
5565
static inline void __kmp_start_record (kmp_int32 gtid,
5617
5566
kmp_taskgraph_flags_t *flags,
5618
5567
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;
5620
5571
// Initializing the TDG structure
5621
5572
tdg->tdg_id = tdg_id;
5622
5573
tdg->map_size = INIT_MAPSIZE;
@@ -5641,42 +5592,42 @@ static inline void __kmp_start_record(kmp_int32 gtid,
5641
5592
KMP_ATOMIC_ST_RLX (&this_record_map[i].npredecessors_counter , 0 );
5642
5593
}
5643
5594
5644
- tdg ->record_map = this_record_map;
5595
+ __kmp_global_tdgs[__kmp_curr_tdg_idx] ->record_map = this_record_map;
5645
5596
}
5646
5597
5647
5598
// __kmpc_start_record_task: Wrapper around __kmp_start_record to mark
5648
5599
// the beginning of the record process of a task region
5649
5600
// loc_ref: Location of TDG, not used yet
5650
5601
// gtid: Global Thread ID of the encountering thread
5651
5602
// 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
5653
5604
// returns: 1 if we record, otherwise, 0
5654
5605
kmp_int32 __kmpc_start_record_task (ident_t *loc_ref, kmp_int32 gtid,
5655
5606
kmp_int32 input_flags, kmp_int32 tdg_id) {
5607
+
5656
5608
kmp_int32 res;
5657
5609
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));
5661
5613
5662
5614
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));
5666
5620
return 1 ;
5667
5621
}
5668
5622
5669
5623
__kmpc_taskgroup (loc_ref, gtid);
5670
- if (flags->graph_reset ) {
5671
- __kmp_free_tdg (tdg_id);
5672
- __kmp_num_tdg--;
5673
- }
5674
5624
if (kmp_tdg_info_t *tdg = __kmp_find_tdg (tdg_id)) {
5675
5625
// TODO: use re_record flag
5676
5626
__kmp_exec_tdg (gtid, tdg);
5677
5627
res = 0 ;
5678
5628
} 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);
5680
5631
__kmp_start_record (gtid, flags, tdg_id);
5681
5632
__kmp_num_tdg++;
5682
5633
res = 1 ;
@@ -5739,11 +5690,10 @@ void __kmpc_end_record_task(ident_t *loc_ref, kmp_int32 gtid,
5739
5690
kmp_int32 input_flags, kmp_int32 tdg_id) {
5740
5691
kmp_tdg_info_t *tdg = __kmp_find_tdg (tdg_id);
5741
5692
5742
- KMP_DEBUG_ASSERT (tdg != NULL );
5743
5693
KA_TRACE (10 , (" __kmpc_end_record_task(enter): T#%d loc=%p finishes recording"
5744
5694
" tdg=%d with flags=%d\n " ,
5745
5695
gtid, loc_ref, tdg_id, input_flags));
5746
- if (__kmp_max_tdgs && tdg ) {
5696
+ if (__kmp_max_tdgs) {
5747
5697
// TODO: use input_flags->nowait
5748
5698
__kmpc_end_taskgroup (loc_ref, gtid);
5749
5699
if (__kmp_tdg_is_recording (tdg->tdg_status ))
0 commit comments