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