© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
9 replies
InsertPi

✅ Replace enum with class name

I'm working on an API right now which, for those familiar with OpenMP, is a parallel programming API which aims to implement OpenMP functionality as faithfully as possible.

With that said, the current API has the following syntax for declaring a parallel-for loop:
DotMP.Parallel.ParallelFor(
    int start,
    int end,
    DotMP.Schedule schedule = DotMP.Schedule.Static, //enum
    uint? chunk_size = null, //defined by runtime if unset
    uint? num_threads = null, //defined by runtime if unset
    Action<int> action);
DotMP.Parallel.ParallelFor(
    int start,
    int end,
    DotMP.Schedule schedule = DotMP.Schedule.Static, //enum
    uint? chunk_size = null, //defined by runtime if unset
    uint? num_threads = null, //defined by runtime if unset
    Action<int> action);

I am looking at the possibility of implementing custom schedulers as defined by the user through some sort of consistent interface. I am not looking for API/ABI compatibility, but source code compatibility would be highly desired. What I would like is to be able to have the
DotMP.Schedule
DotMP.Schedule
enum be replaced with classes that implement the
IScheduler
IScheduler
interface. How would I incorporate this into the type signature to be source-compatible? For instance:
DotMP.Parallel.ParallelFor(0, N, schedule: DotMP.Schedule.Dynamic /* this is a class name */, action: i =>
{
    y[i] += a * x[i];
});
DotMP.Parallel.ParallelFor(0, N, schedule: DotMP.Schedule.Dynamic /* this is a class name */, action: i =>
{
    y[i] += a * x[i];
});


(Before you ask: yes, I know about the TPL. Yes, I have my reasons for not using it. No, I don't want to get into them in this thread, I want to focus on the issue at hand. The provided function is extremely similar to
System.Threading.Tasks.Parallel.For
System.Threading.Tasks.Parallel.For
on the surface, but it is implemented significantly different, and there's much more to my library besides this that the TPL is not flexible enough to do.)
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Class with same name as namespace
C#CC# / help
2y ago
Casting object to enum class
C#CC# / help
2y ago
Enum vs string const class
C#CC# / help
4y ago