Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > parallel programming using MPI and C++

Reply
Thread Tools

parallel programming using MPI and C++

 
 
aaragon
Guest
Posts: n/a
 
      08-28-2007
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,



 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-29-2007
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Parallel in, Parallel out shift register Vivek Menon VHDL 0 06-10-2011 10:15 PM
Parallel in, Parallel out shift register Vivek Menon VHDL 5 06-08-2011 03:56 PM
Parallel port control with USB->Parallel converter Soren Python 4 02-14-2008 03:18 PM
Parallel quicksort (MPI) simo C Programming 2 03-07-2007 07:25 PM
pyMPI and calling MPI functions using Boost.Python Natsu Mizutani Python 0 02-20-2004 10:17 PM



Advertisments