29.04.2014 Views

Presburger Arithmetic and Its Use in Verification

Presburger Arithmetic and Its Use in Verification

Presburger Arithmetic and Its Use in Verification

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.

Appendix A<br />

Examples of multicore parallelism <strong>in</strong> F#<br />

A.1 Source code of π calculation<br />

module PI<br />

open System<br />

open System.L<strong>in</strong>q<br />

open System.Thread<strong>in</strong>g.Tasks<br />

open System.Collections.Concurrent<br />

let NUM_STEPS =100000000<br />

let steps =1.0/(float NUM_STEPS)<br />

let compute1() =<br />

let rec computeUtil(i, acc) =<br />

if i =0then acc ∗ steps<br />

else<br />

let x =(float i +0.5)∗steps<br />

computeUtil (i−1, acc +4.0/(1.0+x ∗ x))<br />

computeUtil(NUM_STEPS, 0.0)<br />

let compute2() =<br />

let sum = ref 0.0<br />

for i <strong>in</strong> 1..NUM_STEPS do<br />

let x =(float i +0.5)∗steps<br />

sum := !sum +4.0/(1.0+x ∗ x)<br />

!sum ∗ steps<br />

module Parallel =<br />

let compute1() =<br />

let sum = ref 0.0<br />

let monitor = new Object()<br />

Parallel.For(<br />

0, NUM_STEPS, new ParallelOptions(),<br />

(fun () −> 0.0),<br />

67

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

Saved successfully!

Ooh no, something went wrong!