This web mail archive is frozen.
This page is part of a frozen web archive of this mailing list.
You can still navigate around this archive, but know that no new mails
have been added to it since July of 2016.
Click here to be taken to the new web archives of this list; it includes all the mails that are in this frozen archive plus all new mails that have been sent to the list since it was migrated to the new archives.
>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:
I think I'm agreeing with Terry. But, to add more detail:
> int main(int argc, char ** argv)
> int size;
> double *feature = new double;
> // compute values of elements of "feature"
> // some operations
The array "feature" can be computed by the master and then broadcast, or
it could be computed redundantly by each process.
> 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
Similarly, coeff can be read in by the master and then broadcast, or it
could be read redundantly by each process, or each process could read
only the portion that it will need.
> 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
Each process loops only over the iterations that correspond to its
rank. Then, the master gathers all results.
> // some operations using all elements in array
> delete  array;
Once the slaves have finished their computations and sent their results
to the master, they may exit. The slaves will be launched at the same
time as the master, but presumably have less to do than the master does
before the "parallel loop" starts. If you don't want slaves consuming
excessive CPU time while they wait for the master, fix that problem
later once you have the basic code working.