Skip to content

Commit

Permalink
remove unnecessary data passing with thread IDs in the core workshari…
Browse files Browse the repository at this point in the history
…ng schedulers
  • Loading branch information
computablee committed Sep 13, 2023
1 parent 3ffacc8 commit 88c0b58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
17 changes: 6 additions & 11 deletions DotMP/Iter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ internal static class Iter
/// <param name="omp_fn">The function to be executed.</param>
/// <param name="omp_fn_red">The function to be executed for reductions.</param>
/// <param name="is_reduction">Whether or not the loop is a reduction loop.</param>
internal static void StaticLoop<T>(WorkShare ws, object thread_id, Action<int> omp_fn, ActionRef<T> omp_fn_red, bool is_reduction)
internal static void StaticLoop<T>(WorkShare ws, int thread_id, Action<int> omp_fn, ActionRef<T> omp_fn_red, bool is_reduction)
{
int tid = (int)thread_id;
int tid = thread_id;
Thr thr = ws.thread;

thr.curr_iter = (int)(ws.start + tid * ws.chunk_size);
Expand All @@ -45,7 +45,7 @@ internal static void StaticLoop<T>(WorkShare ws, object thread_id, Action<int> o
ws.SetLocal(ref local);

while (thr.curr_iter < end)
StaticNext(ws, thr, tid, ws.chunk_size, omp_fn, omp_fn_red, is_reduction, ref local);
StaticNext(ws, thr, ws.chunk_size, omp_fn, omp_fn_red, is_reduction, ref local);

ws.Finished();

Expand All @@ -59,13 +59,12 @@ internal static void StaticLoop<T>(WorkShare ws, object thread_id, Action<int> o
/// <typeparam name="T">The type of the local variable for reductions.</typeparam>
/// <param name="ws">The WorkShare object for state.</param>
/// <param name="thr">The Thr object for the current thread.</param>
/// <param name="thread_id">The thread ID.</param>
/// <param name="chunk_size">The chunk size.</param>
/// <param name="omp_fn">The function to be executed.</param>
/// <param name="omp_fn_red">The function to be executed for reductions.</param>
/// <param name="is_reduction">Whether or not the loop is a reduction loop.</param>
/// <param name="local">The local variable for reductions.</param>
private static void StaticNext<T>(WorkShare ws, Thr thr, int thread_id, uint chunk_size, Action<int> omp_fn, ActionRef<T> omp_fn_red, bool is_reduction, ref T local)
private static void StaticNext<T>(WorkShare ws, Thr thr, uint chunk_size, Action<int> omp_fn, ActionRef<T> omp_fn_red, bool is_reduction, ref T local)
{
int start = thr.curr_iter;
int end = (int)Math.Min(thr.curr_iter + chunk_size, ws.end);
Expand Down Expand Up @@ -98,13 +97,11 @@ private static void StaticNext<T>(WorkShare ws, Thr thr, int thread_id, uint chu
/// </summary>
/// <typeparam name="T">The type of the local variable for reductions.</typeparam>
/// <param name="ws">The WorkShare object for state.</param>
/// <param name="thread_id">The thread ID.</param>
/// <param name="omp_fn">The function to be executed.</param>
/// <param name="omp_fn_red">The function to be executed for reductions.</param>
/// <param name="is_reduction">Whether or not the loop is a reduction loop.</param>
internal static void DynamicLoop<T>(WorkShare ws, object thread_id, Action<int> omp_fn, ActionRef<T> omp_fn_red, bool is_reduction)
internal static void DynamicLoop<T>(WorkShare ws, Action<int> omp_fn, ActionRef<T> omp_fn_red, bool is_reduction)
{
int tid = (int)thread_id;
Thr thr = ws.thread;
int end = ws.end;

Expand Down Expand Up @@ -173,13 +170,11 @@ private static void DynamicNext<T>(WorkShare ws, Thr thr, Action<int> omp_fn, Ac
/// </summary>
/// <typeparam name="T">The type of the local variable for reductions.</typeparam>
/// <param name="ws">The WorkShare object for state.</param>
/// <param name="thread_id">The thread ID.</param>
/// <param name="omp_fn">The function to be executed.</param>
/// <param name="omp_fn_red">The function to be executed for reductions.</param>
/// <param name="is_reduction">Whether or not the loop is a reduction loop.</param>
internal static void GuidedLoop<T>(WorkShare ws, object thread_id, Action<int> omp_fn, ActionRef<T> omp_fn_red, bool is_reduction)
internal static void GuidedLoop<T>(WorkShare ws, Action<int> omp_fn, ActionRef<T> omp_fn_red, bool is_reduction)
{
int tid = (int)thread_id;
Thr thr = ws.thread;
int end = ws.end;

Expand Down
8 changes: 4 additions & 4 deletions DotMP/Parallel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ public static void For(int start, int end, Action<int> action, Schedule schedule
Iter.StaticLoop<object>(ws, GetThreadNum(), action, null, false);
break;
case Schedule.Dynamic:
Iter.DynamicLoop<object>(ws, GetThreadNum(), action, null, false);
Iter.DynamicLoop<object>(ws, action, null, false);
break;
case Schedule.Guided:
Iter.GuidedLoop<object>(ws, GetThreadNum(), action, null, false);
Iter.GuidedLoop<object>(ws, action, null, false);
break;
}

Expand Down Expand Up @@ -219,10 +219,10 @@ public static void ForReduction<T>(int start, int end, Operations op, ref T redu
Iter.StaticLoop(ws, GetThreadNum(), null, action, true);
break;
case Schedule.Dynamic:
Iter.DynamicLoop(ws, GetThreadNum(), null, action, true);
Iter.DynamicLoop(ws, null, action, true);
break;
case Schedule.Guided:
Iter.GuidedLoop(ws, GetThreadNum(), null, action, true);
Iter.GuidedLoop(ws, null, action, true);
break;
}

Expand Down

0 comments on commit 88c0b58

Please sign in to comment.