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.

2.2. MULTICORE PARALLELISM ON .NET FRAMEWORK<br />

algorithms. Us<strong>in</strong>g Task is rather simple; however, to achieve good efficiency, tasks<br />

should be created only when computation is heavier than overheads of creat<strong>in</strong>g <strong>and</strong><br />

coord<strong>in</strong>at<strong>in</strong>g tasks.<br />

2.2.4 Asynchronous computation as parallelization<br />

F# has very good support of asynchronous computation by the notion of Asynchronous<br />

Workflow. ThiscomponentisbuiltforF#only<strong>and</strong>hasconvenientuseby<br />

the syntax of async{...}. Certa<strong>in</strong>ly, Asynchronous Workflow best fits IO-bound<br />

computation where tasks are executed <strong>and</strong> are not blocked to wait for the f<strong>in</strong>al result.<br />

Us<strong>in</strong>g asynchronous computation, operations are go<strong>in</strong>g to run asynchronously,<br />

<strong>and</strong> resources will not be wasted. In some cases, asynchronous computation could<br />

br<strong>in</strong>g benefits to CPU-bound tasks as the follow<strong>in</strong>g example of comput<strong>in</strong>g first 46<br />

Fibonacci numbers:<br />

let rec fib x = if x fib(i)) [|0..45|];;<br />

let pfibs =<br />

Async.Parallel [| for i <strong>in</strong> 0..45 −> async { return fib(i) }|]<br />

|> Async.RunSynchronously;;<br />

In this example, functions are turned to be asynchronous by us<strong>in</strong>g async keyword.<br />

While these functions are marked for parallel execution by Async.Parallel<br />

<strong>and</strong> Async.RunSynchronously, .NETframeworkwilldothejobofdistribut<strong>in</strong>g<br />

them to available cores <strong>and</strong> runn<strong>in</strong>g them effectively. Our benchmark shows that<br />

the asynchronous variant is 2.5× faster than the sequential one. A better speedup<br />

can be achieved by us<strong>in</strong>g Task <strong>in</strong>stead of Asynchronous Workflow, however,itisa<br />

good idea to use Asynchronous Workflow if the computation consists of both CPUbound<br />

tasks <strong>and</strong> IO-bound tasks where us<strong>in</strong>g Task only could be bad due to the<br />

block<strong>in</strong>g property of IO operations. With the presence of Asynchronous Workflow,<br />

we show that F# has very rich support of parallel constructs. There are many<br />

primitives to employ for each algorithm, choos<strong>in</strong>g constructs really depends on the<br />

nature of problem <strong>and</strong> operations required.<br />

2.2.5 Other parallel constructs<br />

The Array.Parallel <strong>and</strong> PSeq Module<br />

The Array.Parallel module is a th<strong>in</strong> wrapper around Parallel.For(Each) constructs,<br />

the purpose is provid<strong>in</strong>g a convenient <strong>in</strong>terface for parallel operations on<br />

Array. Array.Parallel is easy to use because its signature is exactly the same<br />

as Array correspondent. Employ<strong>in</strong>g this module, we can clearly see the benefit of<br />

wrapp<strong>in</strong>g imperative parallel constructs by high order functions to hide side effects.<br />

Similar to above module, the PSeq module based on PLINQ constructs to provide<br />

high order functions for parallel process<strong>in</strong>g on sequences. Input for this mod-<br />

17

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

Saved successfully!

Ooh no, something went wrong!