![]() |
Platforms, Frameworks & Libraries »
Windows Communication Foundation »
General
Intermediate
License: The Code Project Open License (CPOL)
Implementing parallel programming using MPI and C#By Ali HamdarAn example of implementing a parallel program using the pure MPI .NET library, C#, and .NET Remoting. |
C#, Windows, .NET, WCF, WinForms, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Pure .NET MPI is a completely managed implementation of MPI. The object-oriented API is powerful, yet easy to use for parallel programming. It has been developed based on the .NET Framework 3.0, and ported to 3.5 using much of Windows Communication Foundation (WCF).
With the help of WCF, you can use the configuration file to declare the number of process that you are using, which process is the master process, and the locations of the process on your network as IP addresses and ports.
What is most fantastic in Pure MPI .NET is that you can launch all your parallel programs as threads in one single process for debugging and testing issues.
The .NET implementation of the Message Passing Interface (standard 2.0):
This example draws a MandelBrot set using more than one process.
The attachments constitute of three different projects:
The interface can work in sequential mode and in parallel mode.
When working in parallel mode, the interface will launch the MPI-enabled processes to calculate the MandelBrot set, and will use .NET Remoting to collect the result from the master process, as follows:
TcpChannel channel = new TcpChannel(8090);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Points),
"MandelBrot", WellKnownObjectMode.SingleCall);
Cache.Attach(observer);
The following is the implementation of the master process:
Console.WriteLine("Master Process: Working...");
int row = 0;
for (int i = 1; i < comm.Size; i++)
{
comm.Send<int>(i, "ROW_NUMBER", row);
row += processIncrement;
}
ArrayList list = new ArrayList();
int max = (int)Math.Floor((double)width * height / partition) + 1;
for (int i = 0; i <= max; i++)
{
ArrayList partList =
comm.Receive<ArrayList>(Constants.AnySource, "RESULT");
if (partList != null)
list.AddRange(partList);
}
Points points;
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan, false);
points = (Points)Activator.GetObject(typeof(Points),
"tcp://localhost:8090/MandelBrot");
points.SetMessage(list);
Console.WriteLine("Finished Calculating: " + list.Count + " points.");
The following is the implementation of the slave process:
Console.WriteLine("Slave Process: " + comm.Rank + ".Working...");
int row = comm.Receive<int>(0, "ROW_NUMBER");
decimal scaleX = (maxNumber.Real - minNumber.Real) / width;
decimal scaleY = (maxNumber.Imaginary - minNumber.Imaginary) / height;
ComplexNumber c = new ComplexNumber();
ArrayList list = new ArrayList();
c.Real = minNumber.Real;
for (int x = 0; x < width; x++)
{
c.Imaginary = minNumber.Imaginary + row * scaleY;
for (int y = row; y < (row + processIncrement); y++)
{
int count = CalculatePixel(c);
PointSet set = new PointSet();
set.W = x;
set.H = y;
set.Pixel = count;
list.Add(set);
c.Imaginary += scaleY;
if (list.Count == partition)
{
comm.Send<ArrayList>(0, "RESULT", list);
list.Clear();
}
}
c.Real += scaleX;
}
if (list.Count > 0)
{
comm.Send<ArrayList>(0, "RESULT", list);
}
Console.WriteLine("Done");
The configuration file should be set as necessary to determine the number of processes and where the processes will launch.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 15 Apr 2008 Editor: Smitha Vijayan |
Copyright 2008 by Ali Hamdar Everything else Copyright © CodeProject, 1999-2010 Web17 | Advertise on the Code Project |