Connecting Tech Pros Worldwide Forums | Help | Site Map

Parallizing Loops with C#

=?UTF-8?B?TWFydGluIFDDtnBwaW5n?=
Guest
 
Posts: n/a
#1: Jan 10 '07
Hello,

I´m having several loops with independent operations.
Now I want to parallelize these loops for my two test-machines
(a 4xXeon Server and a DualCore 2 Notebook).

Does anybody know a good tutorial about parallizing with C#?

Which solutions are possible?

At the moment I only can imagine to do it with several threads.
Are there other ways?

Is it for example possible to run the OpenMP library
in an unmanaged code area of C#?


Regards,

Martin

Bruce Wood
Guest
 
Posts: n/a
#2: Jan 10 '07

re: Parallizing Loops with C#



Martin Pöpping wrote:
Quote:
Hello,
>
I´m having several loops with independent operations.
Now I want to parallelize these loops for my two test-machines
(a 4xXeon Server and a DualCore 2 Notebook).
>
Does anybody know a good tutorial about parallizing with C#?
>
Which solutions are possible?
>
At the moment I only can imagine to do it with several threads.
Are there other ways?
>
Is it for example possible to run the OpenMP library
in an unmanaged code area of C#?
Multithreading would be the way to go.

Jon Shemitz
Guest
 
Posts: n/a
#3: Jan 10 '07

re: Parallizing Loops with C#


Martin Pöpping wrote:
Quote:
I´m having several loops with independent operations.
Now I want to parallelize these loops for my two test-machines
(a 4xXeon Server and a DualCore 2 Notebook).
>
Does anybody know a good tutorial about parallizing with C#?
<http://www.devsource.com/article2/0,1895,1966478,00.aspis not
exactly a tutorial, but may help.

--

..NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
William Stacey [C# MVP]
Guest
 
Posts: n/a
#4: Jan 11 '07

re: Parallizing Loops with C#


Not sure of exact needs, but you could try my Port Concurrency Runtime
library at www.codeplex.com/PCR. The library is tiny and open source.
It allows various kinds of continuations and arbitrations such as:

private static void ParallelCalcTest()
{
Port<intinPort = new Port<int>();

// Register a handler that is both persistent and concurrent
(i.e. true, true).
Selector.SelectOne(true, true, inPort,
delegate(int num)
{
Console.WriteLine("Result:{0} ThreadID:{1}",num*2,
Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(10); // Force a sleep to help kick-in
multiple threads for demo.
}).Run();

for (int i = 0; i < 20; i++)
{
inPort.Push(i);
}
}

The current default is using the .Net ThreadPool as the dispatcher so actual
number of concurrent threads running will depend on ThreadPool Min settings,
cpus, and what is going on in the system and if you block at all (i.e. Sleep
above) in your code.

Output on my single proc system:
Result:0 ThreadID:7
Result:2 ThreadID:11
Result:4 ThreadID:12
Result:6 ThreadID:13
Result:8 ThreadID:7
Result:10 ThreadID:11
Result:12 ThreadID:12
Result:14 ThreadID:13
Result:16 ThreadID:7
Result:18 ThreadID:11
Result:20 ThreadID:12
Result:22 ThreadID:13
Result:24 ThreadID:7
Result:26 ThreadID:11
Result:28 ThreadID:12
Result:30 ThreadID:13
Result:32 ThreadID:7
Result:34 ThreadID:11
Result:36 ThreadID:12
Result:38 ThreadID:13
--
William Stacey [C# MVP]

"Martin Pöpping" <martin_p@despammed.comwrote in message
news:eo3a34$q3e$1@newsreader3.netcologne.de...
| Hello,
|
| I´m having several loops with independent operations.
| Now I want to parallelize these loops for my two test-machines
| (a 4xXeon Server and a DualCore 2 Notebook).
|
| Does anybody know a good tutorial about parallizing with C#?
|
| Which solutions are possible?
|
| At the moment I only can imagine to do it with several threads.
| Are there other ways?
|
| Is it for example possible to run the OpenMP library
| in an unmanaged code area of C#?
|
|
| Regards,
|
| Martin


Closed Thread


Similar C# / C Sharp bytes