I made a ray-tracer in C#, but I can not get it to use more than one core (on my dual core its always at 50% CPU)
I use the following function that I wrote
Code:
public delegate void ParallelDelegate (int index);
public class Parallel
{
public static void ParallellFor (int start, int count, int increment, ParallelDelegate action)
{
ParallelDelegate [] deleg = new ParallelDelegate [count];
IAsyncResult [] results = new IAsyncResult [count];
for (int i = start; i <start + count; i + = increment)
{
deleg [i] = new ParallelDelegate (action);
results [i] = deleg [i]. BeginInvoke (i, null, null);
}
for (int i = 0; i <deleg.Length; i + +)
deleg [i]. EndInvoke (results [i]);
}
}
Which is then called to the code:
Code:
Parallell.ParallellFor (0, data.Length, 1, new ParallelDelegate (delegate (int i)
{
DoRender (data [i]);
}));
Are there any tricks that need to so that multiple cores will be used? I sat across from STA to MTA, and as expected it had obviously no effect (since this is the COM Interop to do)
Bookmarks