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. EXAMPLES OF MULTICORE PARALLELISM IN F#<br />

(fun iloopState(local:float) −><br />

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

local +4.0/(1.0+x ∗ x)<br />

),<br />

(fun local −> lock (monitor) (fun () −> sum := !sum + local))) |><br />

ignore<br />

!sum ∗ steps<br />

// Overall best function<br />

let compute2() =<br />

let rangeSize = NUM_STEPS /(Environment.ProcessorCount ∗10)<br />

let partitions = Partitioner.Create(0, NUM_STEPS, if rangeSize >= 1 then<br />

rangeSize else 1)<br />

let sum = ref 0.0<br />

let monitor = new Object()<br />

Parallel.ForEach(<br />

partitions, new ParallelOptions(),<br />

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

(fun (m<strong>in</strong>, max) loopState l −><br />

let local = ref 0.0<br />

for i <strong>in</strong> m<strong>in</strong> .. max − 1 do<br />

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

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

l +!local),<br />

(fun local −> lock (monitor) (fun () −> sum := !sum + local))) |><br />

ignore<br />

!sum ∗ steps<br />

let sqr x = x ∗ x<br />

module L<strong>in</strong>q =<br />

// LINQ<br />

let compute1() =<br />

(Enumerable<br />

.Range(0, NUM_STEPS)<br />

.Select(fun i −> 4.0/(1.0+sqr ((float i +0.5)∗steps)))<br />

.Sum()) ∗ steps<br />

// PLINQ<br />

let compute2() =<br />

(ParallelEnumerable<br />

.Range(0, NUM_STEPS)<br />

.Select(fun i −> 4.0/(1.0+sqr ((float i +0.5)∗steps)))<br />

.Sum()) ∗ steps<br />

68

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

Saved successfully!

Ooh no, something went wrong!