[Openmp-commits] [openmp] [OpenMP] Fix td_tdg_task_id underflow when taskloop and taskgraph (PR #150877)

Josep Pinot via Openmp-commits openmp-commits at lists.llvm.org
Fri Sep 19 06:14:40 PDT 2025


jpinot wrote:

> The `record_map` accesses in `__kmp_track_dependence` are not protected for a concurrent reallocation of the vector. I didn't check all the other accesses to the `record_map`, whether they might be concurrent to a reallocation.
> 
> I think there are two options:
> 
>     * lock any access to `record_map` that is possibly concurrent to a write/push (probably way too expensive)
> 
>     * store a pointer to the node_info in kmp_taskdata_t: `task->tdg_node_info = task->tdg->record_map[task->td_tdg_task_id]`

Yes, you're right. I agree that locking all read/write interactions with record_map would be too expensive.
The problem with your second suggestion (storing a pointer to the node in taskdata) is that record_map is an array of kmp_node_info_t. When the record_map vector is reallocated(resize), the old address is freed, and the pointer would point to a deleted memory location.

Two possible solutions come to mind:
 - Change the vector to a linked list. This would solve the pointer invalidation issue but could decrease efficiency during linear traversals, e.g: when executing a recorded TDG.
 - Use a multi-dimensional array or a similar data structure that avoids frequent reallocation, thus preventing the addresses from changing.
 
 @jprotze any thoughts?

https://github.com/llvm/llvm-project/pull/150877


More information about the Openmp-commits mailing list