Carnegie Mellon Parralel Computing Notes on Lecture 6

Cmu 15 418 spring 2014 rule of thumb useful to have

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: while (1) { int i; lock(counter_lock); i = counter++; unlock(counter_lock); if (i >= N) break; is_prime[i] = test_primality(x[i]); } Time in task 0 Time in critical section This is overhead that does not exist in serial program And.. it’s serial execution Recall Amdahl’s law: What is S here? Fine granularity partitioning: Here: 1 “task” = 1 element Likely good workload balance (many small tasks) Potential for high synchronization cost (serialization at critical section) So... IS this a problem? CMU 15-418, Spring 2014 Increasing task granularity LOCK counter_lock; int counter = 0; // shared variable (assume // initialization to 0) const int N = 1024; const int GRANULARITY = 10; float* x = new float[N]; bool* prime = new bool[N]; Time in task 0 Time in critical section What is S now? // initialize elements of x while (1) { int i; lock(counter_lock); i = counter; counter += GRANULARITY; unlock(counter_lock); if (i >= N) break; int end = min(i + GRANULARITY, N); for (int j=i; j<end; j++) is_prime[i] = test_pr...
View Full Document

This document was uploaded on 03/19/2014 for the course CMP 15-418 at Carnegie Mellon.

Ask a homework question - tutors are online