void Solve (void)
{
int i , j, pid , done = 0;
float temp, local_diff ;
GET_PID ( pid );
while (!done) {
local_diff = 0.0;
if (! pid ) gm->diff = 0.0;
BARRIER (gm->barrier, P);/*why?*/
for ( i = pid *(n/P); i < (pid+1)*(n/P); i ++) {
for (j = 0; j < n; j++) {
temp = gm->A[ i ] [j];
gm->A[ i ] [j] = 0.2*(gm->A[ i ] [j] + gm->A[ i ] [j-1] ) +
gm->A[ i ] [j+1] + gm->A[i+1] [j] + gm->A[i-1] [j]; |
local_diff += fabs (gm->A[ i ] [j] – temp);
} /* end for */
} /* end for */
LOCK (gm-> diff_lock );
gm->diff += local_diff ;
UNLOCK (gm-> diff_lock );
BARRIER (gm->barrier, P);
if (gm->diff/(n*n) < TOL) done = 1;
BARRIER (gm->barrier, P); /* why? */
} /* end while */
} |