[software] Use atomics for omp's dynamic schedule
@@ -28,63 +28,52 @@ GOMP_loop_dynamic_start(int start, int end, int incr, int chunk_size,
gomp_loop_init(start, end, incr, chunk_size);
// printf("GOMP_parallel_loop_dynamic_start %d %d %d %d \n", start, end, incr, chunk_size);
}
+ gomp_hal_unlock(&works.lock);
+
+ chunk = chunk_size * incr;
- start = works.next;
+ start = __atomic_fetch_add(&works.next, chunk, __ATOMIC_SEQ_CST);
- if (start == works.end)
+ if (start >= works.end) {
ret = 0;
+ }
if(ret)
{
- chunk = chunk_size * incr;
-
left = works.end - start;
if (chunk > left) {
- chunk = left;
- }
-
-
+ end = works.end;
+ } else {
end = start + chunk;
- works.next = end;
+ }
}
*istart = start;
*iend = end;
- gomp_hal_unlock(&works.lock);
-
return ret;
}
int
GOMP_loop_dynamic_next (int *istart, int *iend)
{
- // printf("n\n");
int start, end, chunk, left;
- gomp_hal_lock(&works.lock);
+ chunk = works.chunk_size * works.incr;
+ start = __atomic_fetch_add(&works.next, chunk, __ATOMIC_SEQ_CST);
- start = works.next;
- if (start == works.end)
- {
- gomp_hal_unlock(&works.lock);
+ if (start >= works.end) {
return 0;
}
- chunk = works.chunk_size * works.incr;
-
left = works.end - start;
- if (chunk > left)
- chunk = left;
-
+ if (chunk > left) {
+ end = works.end;
+ } else {
end = start + chunk;
-
- works.next = end;
- // printf("%d %d \n", works.lock, end);
-
- gomp_hal_unlock(&works.lock);
+ }
*istart = start;
*iend = end;
