10.07.2015 Views

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

E.3. PROMELA EXAMPLE: ATOMIC INCREMENT 245(as expected given the non-atomic increment!). Thesecond line that a trail file was written describinghow the assertion was violated. The “Warning” linereiterates that all was not well with our model. Thesecond paragraph describes the type of state-searchbeing carried out, in this case for assertion violationsand invalid end states. The third paragraph givesstate-size statistics: this small model had only 45states. The final line shows memory usage.The trail file may be rendered human-readableas follows:spin -t -p increment.spinThis gives the output shown in Figure E.3. Ascan be seen, the first portion of the init block createdboth incrementer processes, both of which firstfetched the counter, then both incremented andstored it, losing a count. The assertion then triggered,after which the global state is displayed.E.3 Promela Example: AtomicIncrement(Spin Version 4.2.5 -- 2 April 2005)+ Partial Order ReductionFull statespace search for:never claim - (none specified)assertion violations +cycle checks - (disabled by -DSAFETY)invalid end states +State-vector 40 byte, depth reached 20, errors: 052 states, stored21 states, matched73 transitions (= stored+matched)66 atomic stepshash conflicts: 0 (resolved)2.622 memory usage (Mbyte)unreached in proctype incrementer(0 of 5 states)unreached in proctype :init:(0 of 24 states)Figure E.5: Atomic Increment spin Output1 proctype incrementer(byte me)2 {3 int temp;45 atomic {6 temp = counter;7 counter = temp + 1;8 }9 progress[me] = 1;10 }Figure E.4: Promela Code for Atomic Increment<strong>It</strong> is easy to fix this example by placing the bodyof the incrementer processes in an atomic blocksas shown in Figure E.4. One could also have simplyreplaced the pair of statements with counter= counter + 1, because Promela statements areatomic. Either way, running this modified modelgives us an error-free traversal of the state space, asshown in Figure E.5.E.3.1 Combinatorial ExplosionTable E.1 shows the number of states and memoryconsumed as a function of number of incrementersmodeled (by redefining NUMPROCS):Running unnecessarily large models is thus subtlydiscouraged, although 652MB is well within thelimits of modern desktop and laptop machines.# incrementers # states megabytes1 11 2.62 52 2.63 372 2.64 3,496 2.75 40,221 5.06 545,720 40.57 8,521,450 652.7Table E.1: Memory Usage of Increment Model

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!