Lombiq / Hastlayer-SDK

Turning .NET software into FPGA hardware for faster execution and lower power usage.

Home Page:https://hastlayer.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Parallel.For()

Piedone opened this issue · comments

So instead of e.g.:

for (int i = 0; i < MaxDegreeOfParallelism; i++)
{
    tasks[i] = Task.Factory.StartNew(
        indexObject =>
        {
            var index = (uint)indexObject;
            ...
        },
        i);
}

We'd write something like:

Parallel.For(0, MaxDegreeOfParallelism, index =>
{
    ...
});

This doesn't seem to be feasible. We somehow need to return results from the loop body: this is simple with Tasks but not with Parallel.For(). We'd need to either use shared state (and most possibly also add support for locks) or complicated constructs like the one explained here: https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-write-a-parallel-for-loop-with-thread-local-variables