ttinclude <stdio.h> ttinclude <pthreads.h>
ttdefine NUM_RECTS 100000 ttdefine NUM_THREADS 4
double gArea = 0.0; pthread_mutex_t gLock;
void *threadFunction(void *pArg) { int myNum = *((int *) pArg) ;
double partialHeight = 0.0, lWidth =1.0 / NUM_RECTS, x;
for (int i = myNum; i < NUM_RECTS; i += NUM_THREADS) {
X = (i + 0.5f) / NUM_RECTS;
partialHeight += 4.0f / (l.Of + x * x);
}
pthread_mutex_lock(SgLock) ;
gArea += partialHeigth * lWidth; pthread_mutex_unlock(&gLock);
>
/* cd. następny slajd */
T2-2 - Modele obliczeń rozproszonych Marek Nowak 8