computablee / DotMP

A collection of powerful abstractions for parallel programming in .NET with an OpenMP-like API.
https://computablee.github.io/DotMP/
GNU Lesser General Public License v2.1
29 stars 8 forks source link

Implement `master`/`single` Regions #7

Closed computablee closed 1 year ago

computablee commented 1 year ago

Now that Parallel.For has been separated into Parallel.ParallelRegion and Parallel.For (with the functionality of the original Parallel.For being renamed to Parallel.ParallelFor), I'd like to start implementing more structures. I went ahead and implemented a barrier (under Parallel.Barrier) because it simplified the blocking behavior of #pragma omp for. However, we should have an equivalent of #pragma omp single and #pragma omp master.

Parallel.Master(Action<>) should have the behavior where it is only ever run by the master thread (i.e., thread 0) in a parallel region, and all other threads should "ignore" it. Parallel.Single(Action<>) should have the behavior where it is only run by one thread. The behavior for Single is a little more nuanced. Only one thread should ever execute a Single region, and it should be the first thread that encounters it (so on subsequent runs, the same thread will be "assigned" to the region). All other threads should ignore it.

I suspect that we won't be able to implement Single as a static method (as I'm suspecting with Critical). If we can think of a way to do this, that would be excellent, but if not, I'm open to suggestions for an easy, user-friendly alternative.

computablee commented 1 year ago

With the Critical issue resolved, I think there's a framework in place for Single. Anyone who would like to be assigned, let me know.

computablee commented 1 year ago

Assigning myself to this.

computablee commented 1 year ago

Ah, not bad. All unit tests pass, closing this. Pushed to features branch.