Skip to content

Commit 9f22d78

Browse files
author
valentin petrov
authored
SCHEDULE: fixes race on n_deps_satisfied (#618)
A task can depend on 2 other tasks (e.g. from another frag of of schedule and prev task in a given frag). In that case when those 2 frags a progressed by mutliple threads ucc_dependency_handler may be called concurrently which results in a race on n_deps_satisfied. (cherry picked from commit b8c78d8)
1 parent 97f8008 commit 9f22d78

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/schedule/ucc_schedule_pipelined.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,13 @@ ucc_status_t ucc_dependency_handler(ucc_coll_task_t *parent,
210210
ucc_coll_task_t *task)
211211
{
212212
ucc_status_t status;
213+
uint8_t n_deps_satisfied;
214+
215+
n_deps_satisfied = ucc_atomic_fadd8(&task->n_deps_satisfied, 1);
213216

214-
task->n_deps_satisfied++;
215217
ucc_trace_req("task %p, n_deps %d, satisfied %d", task, task->n_deps,
216-
task->n_deps_satisfied);
217-
if (task->n_deps == task->n_deps_satisfied) {
218+
n_deps_satisfied);
219+
if (task->n_deps == n_deps_satisfied + 1) {
218220
task->start_time = parent->start_time;
219221
status = task->post(task);
220222
if (status >= 0) {

src/utils/ucc_atomic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#define ucc_atomic_add32 ucs_atomic_add32
1313
#define ucc_atomic_fadd32 ucs_atomic_fadd32
14+
#define ucc_atomic_fadd8 ucs_atomic_fadd8
1415
#define ucc_atomic_sub32 ucs_atomic_sub32
1516
#define ucc_atomic_add64 ucs_atomic_add64
1617
#define ucc_atomic_sub64 ucs_atomic_sub64

0 commit comments

Comments
 (0)