






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Analysis Sequential complexity
! T ( n ) = O ( n ln ln n ) Analysis
! T ( n ) = O ( n ln ln n )
Initial sequential part for (i=0; i<=sqrt(n); i++) marked[i] = 0; k = index = 2; j=0; marked[0] = marked[1] = 1; while (kk<=sqrt(n)) { for (i=kk; i<=sqrt(n); i+= k) marked[i]=1; while (marked[++index]); primes[j++] = k = index; } /* loop through marked & store additional values into primes / numprimes = “total number of primes found”; Parallel part for (j=0; j<=numprimes; j++){ f = “first multiple of primes[j] in my section”; for (i=f; i<=mysize; i+= primes[j]) marked[i]=1; } / code to count the number of primes and MPI_Reduce it to processor 0 */
Locality Improvement Loop blocking/tiling/partitioning Typically applied to compute-intensive loops to optimize
Matrix multiplication (ideal) 3 O ( n ) Real machine 5 O ( n ) “The uniform Memory Hierarchy Model of Computation” B. Alpern, L. Carter, E. Feig, T. Selker (Algorithmica 1992) Tiling the sieve for (j=0; j<=numprimes; j++){ f = “first multiple of primes[j] in my section”; for (i=f; i<=mysize; i+= primes[j]) marked[i]=1; }
Pull the ii loop outside the j loop for (j=0; j<=numprimes; j++){ f = “first multiple of primes[j] in my section”; start = “largest multiple of BKSIZE leq f”; for (ii=start; ii <= mysize, ii += BKSIZE){ f’ = first multiple of primes[j] geq ii; for (i=f’; i<=min(ii+BKSIZE-1,mysize); i+=primes[j]){ marked[i]=1; } } } Pull the ii loop outside the j loop for (j=0; j<=numprimes; j++){ f = “first multiple of primes[j] in my section”; start = “largest multiple of BKSIZE leq f”; for (ii=start; ii <= mysize, ii += BKSIZE){ f’ = first multiple of primes[j] geq ii; for (i=f’; i<=min(ii+BKSIZE-1,mysize); i+=primes[j]){ marked[i]=1; } } }
But is this legal? That’s the trick You need to ensure that the code correctly does what the original one did. Performance
Summary More involved problem Reductions and Broadcasts Block Distribution Sequential Performance is crucial