In rank 0 main broadcast feature to all processes.
In f calculate a slice of array based on rank, then either send/recv
back to rank 0 or maybe gather.
Only rank 0 does everything else.  (Other ranks must call f after
recv'ing feature.)


On Thu, 2010-01-28 at 21:23 -0800, Tim wrote:
> Sorry, complicated_computation() and f() are simplified too much. They do 
> take more inputs. 
> 
> Among the inputs to complicated_computation(), some is passed from the main() 
> to f() by address since it is a big array, some is passed by value, some are 
> created inside f() before the call to complicated_computation(). 
> 
> so actually (although not exactly) the code is like:
> 
>      int main(int argc, char ** argv)   
>      {   
>       int size;
>       double *feature = new double[1000];
>      // compute values of elements of "feature"
>      // some operations  
>      f(size, feature);           
>      // some operations  
>      delete [] feature;       
>      return 0;   
>      }   
>        
>      void f(int size, double *feature)   
>      {           
>      vector<double> coeff;      
>      // read from a file into elements of coeff        
>      MyClass myobj;
>      double * array =  new double [coeff.size()];           
>      for (int i = 0; i < coeff.size(); i++) // need to speed up by MPI.
>      {        
>      array[i] = myobj.complicated_computation(size, coeff[i], feature); // 
> time consuming   
>      }           
>      // some operations using all elements in array         
>      delete [] array;
>      }
> 
> --- On Thu, 1/28/10, Eugene Loh <eugene....@sun.com> wrote:
> 
> > From: Eugene Loh <eugene....@sun.com>
> > Subject: Re: [OMPI users] speed up this problem by MPI
> > To: "Open MPI Users" <us...@open-mpi.org>
> > Date: Thursday, January 28, 2010, 11:40 PM
> > Tim wrote:
> > 
> > > 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     
> >          f(size);   
> >            // 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     
> > What are the inputs to complicated_computation()? 
> > Does each process know what the inputs are?  Or, do
> > they need to come from the master process?  Are there
> > many inputs?
> > 
> > >     }       
> >        // some operations using all
> > elements in array           
> >    delete [] array; 
> >    }
> > >  
> > _______________________________________________
> > users mailing list
> > us...@open-mpi.org
> > http://www.open-mpi.org/mailman/listinfo.cgi/users
> > 
> 
> 
>       
> 
> _______________________________________________
> users mailing list
> us...@open-mpi.org
> http://www.open-mpi.org/mailman/listinfo.cgi/users

Reply via email to