Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] speed up this problem by MPI
From: Tim (timlee126_at_[hidden])
Date: 2010-01-28 20:48:18

Thanks Eugene!

My case, after simplified, is to speed up the time-consuming computation in the loop below by assigning iterations to several nodes in a cluster by MPI. Each iteration of the loop computes each element of an array. The computation of each element is independent of others in the array.
     int main(int argc, char ** argv)
     // some operations
     // some operations
     return 0;
     void f(int size)
     // some operations
     int i;
     double * array = new double [size];
     for (i = 0; i < size; i++) // need to speed up by MPI.
     array[i] = complicated_computation(); // time consuming
     // some operations using all elements in array
     delete [] array;

--- On Thu, 1/28/10, Eugene Loh <Eugene.Loh_at_[hidden]> wrote:

> From: Eugene Loh <Eugene.Loh_at_[hidden]>
> Subject: Re: [OMPI users] speed up this problem by MPI
> To: "Open MPI Users" <users_at_[hidden]>
> Date: Thursday, January 28, 2010, 8:31 PM
> Tim wrote:
> > Thanks, Eugene.
> >
> > I admit I am not that smart to understand well how to
> use MPI, but I did read some basic materials about it and
> understand how some simple problems are solved by MPI.
> > But dealing with an array in my case, I am not certain
> about how to apply MPI to it. Are you saying to use send and
> recieve to transfer the value computed for each element from
> child process to parent process?
> >
> You can, but typically that would entail too much
> communication overhead for each element.
> > Do you allocate a copy of the array for each process?
> > 
> You can, but typically that would entail excessive memory
> consumption.
> Typically, one allocates only a portion of the array on
> each process.  E.g., if the array has 10,000 elements
> and you have four processes, the first gets the first 2,500
> elements, the second the next 2,500, and so on.
> > Also I only need the loop that computes every element
> of the array to be parallelized.
> >
> If you only need the initial computation of array elements
> to be parallelized, perhaps any of the above strategies
> could work.  It depends on how expensive the
> computation of each element is.
> > Someone said that the parallel part begins with
> MPI_Init and ends with MPI_Finilize,
> >
> Well, usually all processes are launched in parallel. 
> So, the parallel begins "immediately."  Inter-process
> communications using MPI, however, must take place between
> the MPI_Init and MPI_Finalize calls.
> > and one can do any serial computations before and/or
> after these calls. But I have wrote some MPI programs, and
> found that the parallel part is not restricted between
> MPI_Init and MPI_Finilize, but instead the whole program. If
> the rest part of the code has to be wrapped for process with
> ID 0, I have little idea about how to apply that to my case
> since the rest part would be the parts before and after the
> loop in the function and the whole in main().
> >
> I don't understand your case very clearly.  I will
> take a guess.  You could have all processes start and
> call MPI_Init.  Then, slave processes can go to sleep,
> waking occasionally to check if the master has sent a signal
> to begin computation.  The master does what it has to
> do and then sends wake signals.  Each slave computes
> its portion and sends that portion back to the master. 
> Each slave exits.  The master gathers all the pieces
> and resumes its computation.  Does that sound right?
> _______________________________________________
> users mailing list
> users_at_[hidden]