Skip to content
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

Bugfix/exception handling method #87

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions DotMP/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,29 @@ public CannotPerformNestedWorksharingException(string msg) : base(msg) { }
/// <param name="ex">The inner exception.</param>
public CannotPerformNestedWorksharingException(string msg, Exception ex) : base(msg, ex) { }
}


/// <summary>
/// Exception thrown if a Parallel.Ordered is called outside of Parallel.For or Parallel.ForReduction.
/// </summary>
public class NotInForException: Exception
{
/// <summary>
/// Default constructor.
/// </summary>
public NotInForException() { }

/// <summary>
/// Constructor with a message.
/// </summary>
/// <param name="msg">The message to associate with the exception.</param>
public NotInForException(string msg): base(msg) { }

/// <summary>
/// Constructor with a message and inner exception.
/// </summary>
/// <param name="msg">The message to associate with the exception.</param>
/// <param name="ex">The inner exception.</param>
public NotInForException(string msg, Exception ex): base(msg, ex) { }
}
}
53 changes: 53 additions & 0 deletions DotMP/Parallel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@
/// <exception cref="NotInParallelRegionException">Thrown when not in a parallel region.</exception>
private static void For<T>(int start, int end, ForAction<T> forAction, Schedule schedule = Schedule.Static, uint? chunk_size = null, Operations? op = null)
{
ValidateParameters(start, end, chunk_size: chunk_size);

var freg = new ForkedRegion();

if (!freg.in_parallel)
Expand Down Expand Up @@ -496,6 +498,8 @@
/// <exception cref="CannotPerformNestedParallelismException">Thrown if ParallelRegion is called from within another ParallelRegion.</exception>
public static void ParallelRegion(Action action, uint? num_threads = null)
{
ValidateParameters(0, 0, num_threads: num_threads);

if (InParallel())
throw new CannotPerformNestedParallelismException();

Expand Down Expand Up @@ -819,6 +823,8 @@
/// <returns>List of tasks generated by taskloop for use as future dependencies.</returns>
public static TaskUUID[] Taskloop(int start, int end, Action<int> action, uint? grainsize = null, uint? num_tasks = null, bool only_if = true, params TaskUUID[] depends)
{
ValidateParameters(start, end, num_tasks: num_tasks, grainsize: grainsize);

if (only_if)
{
ForkedRegion fr = new ForkedRegion();
Expand Down Expand Up @@ -1081,6 +1087,11 @@

WorkShare ws = new WorkShare();

if (!ws.in_for)
{
throw new NotInForException();
}

while (ordered[id] != ws.thread.working_iter)
{
freg.reg.spin[tid].SpinOnce();
Expand All @@ -1092,6 +1103,8 @@
{
ordered[id]++;
}

Barrier();
}

/// <summary>
Expand Down Expand Up @@ -1222,5 +1235,45 @@
{
return new WorkShare().chunk_size;
}



/// <summary>
/// Validates the input parameters for a specific operation.
/// </summary>
/// <param name="start">The starting index.</param>
/// <param name="end">The ending index.</param>
/// <param name="numThreads">Number of threads (optional, set to null if not applicable).</param>

Check warning on line 1246 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment has a param tag for 'numThreads', but there is no parameter by that name

Check warning on line 1246 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment has a param tag for 'numThreads', but there is no parameter by that name
/// <param name="chunkSize">Chunk size (optional, set to null if not applicable).</param>

Check warning on line 1247 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment has a param tag for 'chunkSize', but there is no parameter by that name

Check warning on line 1247 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment has a param tag for 'chunkSize', but there is no parameter by that name
/// <param name="numTasks">Number of tasks (optional, set to null if not applicable).</param>

Check warning on line 1248 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment has a param tag for 'numTasks', but there is no parameter by that name

Check warning on line 1248 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment has a param tag for 'numTasks', but there is no parameter by that name
/// <param name="grainSize">Grain size (optional, set to null if not applicable).</param>

Check warning on line 1249 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment has a param tag for 'grainSize', but there is no parameter by that name

Check warning on line 1249 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment has a param tag for 'grainSize', but there is no parameter by that name
/// <exception cref="ArgumentException">Thrown when input parameters are invalid:
/// <para>- <paramref name="end"/> is less than <paramref name="start"/>.</para>
/// <para>- <paramref name="start"/> or <paramref name="end"/> is less than 0.</para>
/// <para>- <paramref name="numThreads"/> is 0.</para>

Check warning on line 1253 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment on 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' has a paramref tag for 'numThreads', but there is no parameter by that name

Check warning on line 1253 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment on 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' has a paramref tag for 'numThreads', but there is no parameter by that name
/// <para>- <paramref name="chunkSize"/> is 0.</para>

Check warning on line 1254 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment on 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' has a paramref tag for 'chunkSize', but there is no parameter by that name

Check warning on line 1254 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment on 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' has a paramref tag for 'chunkSize', but there is no parameter by that name
/// <para>- Either <paramref name="numTasks"/> or <paramref name="grainSize"/> is 0.</para>

Check warning on line 1255 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment on 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' has a paramref tag for 'numTasks', but there is no parameter by that name

Check warning on line 1255 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment on 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' has a paramref tag for 'grainSize', but there is no parameter by that name

Check warning on line 1255 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment on 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' has a paramref tag for 'numTasks', but there is no parameter by that name

Check warning on line 1255 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

XML comment on 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' has a paramref tag for 'grainSize', but there is no parameter by that name
/// </exception>
private static void ValidateParameters(
int start,
int end,
uint? num_threads = null,

Check warning on line 1260 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

Parameter 'num_threads' has no matching param tag in the XML comment for 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' (but other parameters do)

Check warning on line 1260 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

Parameter 'num_threads' has no matching param tag in the XML comment for 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' (but other parameters do)
uint? chunk_size = null,

Check warning on line 1261 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

Parameter 'chunk_size' has no matching param tag in the XML comment for 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' (but other parameters do)

Check warning on line 1261 in DotMP/Parallel.cs

View workflow job for this annotation

GitHub Actions / check-compile

Parameter 'chunk_size' has no matching param tag in the XML comment for 'Parallel.ValidateParameters(int, int, uint?, uint?, uint?, uint?)' (but other parameters do)
uint? num_tasks = null,
uint? grainsize = null)
{
if (end < start) throw new ArgumentException("End index cannot be less than start index.");

if (start < 0 || end < 0) throw new ArgumentException("Start and end indices cannot be less than 0.");

if (num_threads is not null && num_threads == 0) throw new ArgumentException("Number of threads cannot be 0.");

if (chunk_size is not null && chunk_size == 0) throw new ArgumentException("Chunk size cannot be 0.");

if (num_tasks is not null
&& grainsize is not null
&& (num_tasks == 0 || grainsize == 0)) throw new ArgumentException("Number of tasks and grainsize cannot be 0.");

}
}
}
Loading