Use MPI inside a for loop

  • 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


0 Replies
418 Views

(page loaded in 0.024 seconds)

Similiar Articles:













7/23/2012 5:34:09 PM


Reply: