COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Use MPI inside a for loop

• Email
• Follow

```Hello all,

I need to make below code MPI'ed.
Inside the "for" loop, there are 2 calls to function "solve" which is
very heavy. So I wanted to make use of MPI. What I wanted to do is:

1. Loop through 1 -> M
a. Solve w1 = solve(s1[m]) with process 1
b. Solve w2 = solve(s2[m]) with process 2
c. Send w1 to process 2
d. Send w2 to process 1
e. Calculte new s1[m+1], s2[m+1]

How can I do this? I know very basic of MPI, I know usage of
MPI_Send,MPI_Recv ... but dont know how to use them in this case.

Any help is appreciated!

/*************************************/

double s1[M], s2[M];
double w1, w2;

s1[0] = 1;
s2[0] = 2;

for( m = 0; m < M; m++)
{
/* do this with process 1 */
w1 = solve(s1[m]);
/* ...
then send s1[m] to process 2
*/

/* do this with process 2 */
w2 = solve(s2[m]);
/*
then send s2[m] to process 1
*/

/ * Gather s1[m], s2[m] from Process 1, 2 */
/* Calculate new s1[m+1], s2[m+1]
s1[m+1] = f1(w1, w2);
s2[m+1] = f2(w1, w2);
}

....

double solve(x)
{
//solve an equation and get x
}

double f1(double s1, double s2)
{
}

double f2(double s1, double s2)
{
}
/***************************************************/
```
 0
Reply vuhung16mpi 1/16/2004 11:14:44 AM

See related articles to this posting

0 Replies
500 Views

Similar Articles

12/8/2013 10:46:30 PM
[PageSpeed]