[Omp] How can I parallel the "do-while" block with Openmp?
chbq chen
bangqian.chen at gmail.com
Wed Nov 8 23:49:27 PST 2006
The source code of this example is at the page of 144 of the OpenMP
Application Program Interface 2.5, there is a do-while block in the
parallel region in this example, I found that the two threads(if we have 2
CPU ) are not share the work of "do-while", each of them execute the
do-while block one time. I have some codes to parallel, the codes also
have a " do-while " block, it's very time-consuming,I also try to
parallel this code with the intel workqueuing model, but I am failed. so I
need some help from you,Can you give me some suggestions?
#include <stdio.h>
extern float average(float,float,float);
void a12( float* x, float* xold, int n, float tol )
{
int c, i, toobig;
float error, y;
c = 0;
#pragma omp parallel //here will create two threads if we have two CPU
{
do // I need only the master thread execute the " do ", another thread
will share to execute the code when a " pragma omp for " is appeared
{
#pragma omp for private(i) // another thread will share work with the master
thread
for( i = 1; i < n-1; ++i )
{
xold[i] = x[i];
}
#pragma omp single
{
toobig = 0;
}
#pragma omp for private(i,y,error) reduction(+:toobig) // another thread
will share work with the master thread
for( i = 1; i < n-1; ++i )
{
y = x[i];
x[i] = average( xold[i-1], x[i], xold[i+1] );
error = y - x[i];
if( error > tol || error < -tol )
++toobig;
}
#pragma omp master
{
++c;
printf( "iteration %d, toobig=%d\n", c, toobig );
}
}while( toobig > 0 ); // I also need the master thread execute " while
(toobig>0 ) " alone,however, I found that all of the two
threads will executing the code " while(toobig>0) ",
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.openmp.org/pipermail/omp/attachments/20061108/d768c8e8/attachment.html
More information about the Omp
mailing list