473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Parallizing Loops with C#

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
Jan 10 '07 #1
3 3457

Martin Pöpping wrote:
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.

Jan 10 '07 #2
Martin Pöpping wrote:
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
Jan 10 '07 #3
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" <ma******@despammed.comwrote in message
news:eo**********@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
Jan 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Oleg Leschov | last post by:
Could there be means of exiting nested loops in python? something similar to labelled loops in perl.. I consider it irrating to have to make a flag for sole purpose of checking it after loop if...
15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
4
by: Dr. David Kirkby | last post by:
I have a program that loops through and changes all the elements on an array n times, so my code looks like this: for (n=1; n < n_max; ++n) for(i=imax; i >= 0; --i) { for(j=0 ; j < jmax; ++j) {...
6
by: Scott Brady Drummonds | last post by:
Hi, everyone, I was in a code review a couple of days ago and noticed one of my coworkers never used for() loops. Instead, he would use while() loops such as the following: i = 0; while (i...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
10
by: Putty | last post by:
In C and C++ and Java, the 'for' statement is a shortcut to make very concise loops. In python, 'for' iterates over elements in a sequence. Is there a way to do this in python that's more concise...
2
by: bitong | last post by:
I'm a little bit confuse with regard to our subject in C..We are now with the Loops..and I was just wondering if given a problem, can you use Do-while loops instead of a for loops or vise versa? are...
3
by: monomaniac21 | last post by:
hi all i have a script that retrieves rows from a single table, rows are related to eachother and are retrieved by doing a series of while loops within while loops. bcos each row contains a text...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.