Skip to content

[OpenMP] Fix nested parallel with tasking #87309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

jpeyton52
Copy link
Contributor

When a nested parallel region ends, the runtime calls __kmp_join_call(). During this call, the primary thread of the nested parallel region will reset its tid (retval of omp_get_thread_num()) to what it was in the outer parallel region. A data race occurs with the current code when another worker thread from the nested inner parallel region tries to steal tasks from the primary thread's task deque. The worker thread reads the tid value directly from the primary thread's data structure and may read the wrong value.

This change just uses the calculated victim_tid from execute_tasks() directly in the steal_task() routine rather than reading tid from the data structure.

Fixes: #87307

When a nested parallel region ends it calls __kmp_join_call(). During
this call, the primary thread of the nested parallel region will reset
its tid (retval of omp_get_thread_num()) to what it was in the outer
parallel region. A data race occurs with the current code when another
worker thread from the nested parallel region tries to steal tasks from
the primary thread's task deque. The worker thread reads the tid value
directly from the primary thread's data structure and may read the wrong
value.

Fixes: llvm#87307
Copy link
Contributor

@shiltian shiltian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jpeyton52 jpeyton52 merged commit 4ea2494 into llvm:main Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openmp:libomp OpenMP host runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OpenMP] Nested parallel with tasking contains data race
3 participants