Skip to content

Commit

Permalink
Merge pull request #98 from computablee/features
Browse files Browse the repository at this point in the history
Validate DotMP input parameters
  • Loading branch information
computablee authored Oct 25, 2023
2 parents 6461494 + 9cf9f31 commit 578e8d6
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 7 deletions.
96 changes: 89 additions & 7 deletions DotMP-Tests/ParallelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ namespace DotMPTests
/// </summary>
public class ParallelTests
{
private readonly ITestOutputHelper writer;
public ParallelTests(ITestOutputHelper outputwriter)
{
writer = outputwriter;
}


/// <summary>
/// Tests to make sure that parallel performance is higher than sequential performance.
/// </summary>
Expand Down Expand Up @@ -1355,6 +1348,95 @@ public void Non_parallel_GetThreadNum_should_except()
});
}

/// <summary>
/// Verifies that absent parameters shouldn't throw exceptions.
/// </summary>
[Fact]
public void Absent_params_shouldnt_except()
{
var exception = Record.Exception(() =>
{
DotMP.Parallel.ParallelFor(0, 10, i => { });
});

Assert.Null(exception);

exception = Record.Exception(() =>
{
DotMP.Parallel.ParallelMasterTaskloop(0, 10, i => { });
});

Assert.Null(exception);
}

/// <summary>
/// Verifies that invalid parameters throw exceptions.
/// </summary>
[Fact]
public void Invalid_params_should_except()
{
DotMP.Parallel.ParallelRegion(() =>
{
Assert.Throws<DotMP.InvalidArgumentsException>(() =>
{
DotMP.Parallel.For(10, 0, i => { });
});
});

DotMP.Parallel.ParallelRegion(() =>
{
Assert.Throws<DotMP.InvalidArgumentsException>(() =>
{
DotMP.Parallel.For(-1, 10, i => { });
});
});

DotMP.Parallel.ParallelRegion(() =>
{
Assert.Throws<DotMP.InvalidArgumentsException>(() =>
{
DotMP.Parallel.For(10, -5, i => { });
});
});

DotMP.Parallel.ParallelRegion(() =>
{
Assert.Throws<DotMP.InvalidArgumentsException>(() =>
{
DotMP.Parallel.For(0, 10, chunk_size: 0, action: i => { });
});
});

Assert.Throws<DotMP.InvalidArgumentsException>(() =>
{
DotMP.Parallel.ParallelRegion(num_threads: 0, action: () => { });
});

DotMP.Parallel.ParallelMaster(() =>
{
Assert.Throws<DotMP.InvalidArgumentsException>(() =>
{
DotMP.Parallel.Taskloop(10, 0, i => { });
});
});

DotMP.Parallel.ParallelMaster(() =>
{
Assert.Throws<DotMP.InvalidArgumentsException>(() =>
{
DotMP.Parallel.Taskloop(0, 10, grainsize: 0, action: i => { });
});
});

DotMP.Parallel.ParallelMaster(() =>
{
Assert.Throws<DotMP.InvalidArgumentsException>(() =>
{
DotMP.Parallel.Taskloop(0, 10, num_tasks: 0, action: i => { });
});
});
}

/// <summary>
/// A sample workload for DotMP.Parallel.ParallelFor().
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions DotMP/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ public class CannotPerformNestedWorksharingException : Exception
/// <param name="msg">The message to associate with the exception.</param>
public CannotPerformNestedWorksharingException(string msg) : base(msg) { }
}

/// <summary>
/// Exception thrown if invalid arguments are specified to DotMP functions.
/// </summary>
public class InvalidArgumentsException : Exception
{
/// <summary>
/// Constructor with a message.
/// </summary>
/// <param name="msg">The message to associate with the exception.</param>
public InvalidArgumentsException(string msg) : base(msg) { }
}
}
Loading

0 comments on commit 578e8d6

Please sign in to comment.