473,387 Members | 1,904 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,387 software developers and data experts.

parallel programming using MPI and C++

Hi everyone,

I started parallelizing some code that I had and for that I'm using
the mpich library. I was able to run simulations in my one processor
laptop as if it were a cluster of machines but now I have a problem
for which the solution might be trivial. I would like to use master-
slave parallelization to speed-up some computations but then I need
only a UNIQUE instantiation of a class (the master node) and then
communicate information of that class to other processes in remote
nodes.

I can do this by writing everything in the main function that I
compile:

int main(int argc,char *argv[]) {

MPI::Init(argc,argv);
int rank = MPI::COMM_WORLD.Get_rank();
int size = MPI::COMM_WORLD.Get_size();

if(rank == 0) {
ClassA ca;
ca.initialize;
ca.compute;
} else {
// wait for instructions from master node
// more code
}

MPI::Finalize();
}

However, I would like to abstract all this from the main() function
and I don't know how to do this. My first attempt was to call MPI
instructions from ClassA functions but of course this doesn't work
because there are already several instantiations of ClassA. My last
attempt was to provide a wrapper to ClassA, a class called
ParallelClassA that had a static member varible, an instantiation of
ClassA. This looks like follows:

template <class ClassA>
class ParallelClassA {
static ClassA instance_;
public:
// public member functions, including initialize() and compute()
};

However, I think this is not feasible either because I guess that the
same program will run in all the nodes so there won't be a unique
instantiation even if the variable was declared static, right?

Can anyone point me in the right direction to solve this problem? Does
the concept of singleton solve this problem?

Thank you,



Aug 28 '07 #1
1 2158
aaragon wrote:
I started parallelizing some code that I had and for that I'm using
the mpich library. I was able to run simulations in my one processor
laptop as if it were a cluster of machines but now I have a problem
for which the solution might be trivial. I would like to use master-
slave parallelization to speed-up some computations but then I need
only a UNIQUE instantiation of a class (the master node) and then
communicate information of that class to other processes in remote
nodes.

I can do this by writing everything in the main function that I
compile:

int main(int argc,char *argv[]) {

MPI::Init(argc,argv);
int rank = MPI::COMM_WORLD.Get_rank();
int size = MPI::COMM_WORLD.Get_size();

if(rank == 0) {
ClassA ca;
ca.initialize;
ca.compute;
} else {
// wait for instructions from master node
// more code
}

MPI::Finalize();
}

However, I would like to abstract all this from the main() function
and I don't know how to do this. My first attempt was to call MPI
instructions from ClassA functions but of course this doesn't work
because there are already several instantiations of ClassA. My last
attempt was to provide a wrapper to ClassA, a class called
ParallelClassA that had a static member varible, an instantiation of
ClassA. This looks like follows:

template <class ClassA>
class ParallelClassA {
static ClassA instance_;
public:
// public member functions, including initialize() and compute()
};

However, I think this is not feasible either because I guess that the
same program will run in all the nodes so there won't be a unique
instantiation even if the variable was declared static, right?
Nope, not right. Unique instantiation is only relevant inside the
bounds of one program. What you instantiate in other programs is
not relevant to this one.
>
Can anyone point me in the right direction to solve this problem? Does
the concept of singleton solve this problem?
I think you're on the right track.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 29 '07 #2

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

Similar topics

0
by: Yuancai \(Charlie\) Ye | last post by:
Hi, All: I am happy to annouce that we have formally released our latest SocketPro version 4 at www.udaparts.com, an advanced remoting framework written from batching/queue, asynchrony and...
10
by: Joshua Nussbaum | last post by:
I came up with what I think is a good idea for making multithreading programming easier in any .NET language. I dont know where else to post it, so I'll try here. ..NET 2.0 adds the capability...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
9
by: MNQ | last post by:
Hi All I want to use my parallel port of my PC to control some external devices. I am writing a program in ANSI C using the PacificC compiler. What I need to know is how to access the parallel...
3
by: paytam | last post by:
Hi all, Is it possible to write parallel programming in C? I mean for example a simple program like I have a clock on a program that show me current time and and at the same time another job like...
126
by: ramyach | last post by:
Hi friends, I need to write a parallel code in 'C' on the server that is running SGI Irix 6.5. This server supports MIPS Pro C compiler. I don't have any idea of parallel C languages. I looked...
11
by: Isaac T Alston | last post by:
Basically, I'm thinking about building a robot which can be controlled by programs which I write, I'm going to interface to the robot through the parallel port (like in this tutorial here:...
14
by: Dave Booker | last post by:
I'm doing some analysis that is readily broken up into many independent pieces, on a multicore machine. I thought it would be best to just queue like 1000 of these pieces in the ThreadPool, and...
3
by: divinginthesky | last post by:
My question is to know how sophisticated is C for programming in parallel, all what I know is that C is sequential until know. Do you know if there have been some attends or versions of C to program...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.