Presburger Arithmetic and Its Use in Verification
Presburger Arithmetic and Its Use in Verification
Presburger Arithmetic and Its Use in Verification
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
2.2. MULTICORE PARALLELISM ON .NET FRAMEWORK<br />
provide a very f<strong>in</strong>e-gra<strong>in</strong>ed control over how parallelization is done. However, Parallel.For(Each)<br />
is designed for .NET itself. In order to use them conveniently <strong>in</strong><br />
afunctionalprogramm<strong>in</strong>glanguage,oneshouldwrapthem<strong>in</strong>functionalconstructs<br />
<strong>and</strong> provide parameters for tweak<strong>in</strong>g parallelism.<br />
Comparison of execution time is presented <strong>in</strong> Table 2.1, <strong>and</strong> detailed source code<br />
can be found <strong>in</strong> Appendix A.1.<br />
LINQ PLINQ Sequential Parallel.For Parallel.ForEach<br />
Speedup 1x 3-4x 2x 6-8x 14-16x<br />
Table 2.1. Speedup factors of π calculation compared to the slowest version.<br />
Besides those primitives which have been illustrated <strong>in</strong> the above examples, TPL<br />
also has some mechanisms to provide f<strong>in</strong>e-gra<strong>in</strong>ed parallel execution:<br />
• Degree of Parallelism<br />
In PLINQ, controll<strong>in</strong>gdegreeofparallelismisspecifiedbyWithDegreeOf<br />
Parallelism(Of TSource) operator, this operator determ<strong>in</strong>es the maximum<br />
number of processors used for the query. In Parallel.For(Each), wecanset<br />
the maximum number of threads for execut<strong>in</strong>g a parallel loop by ParallelOptions<br />
<strong>and</strong> MaxDegreeOfParallelism constructs. These primitives are <strong>in</strong>troduced to<br />
avoid spawn<strong>in</strong>g too many threads for computation, which leads to too many<br />
overheads <strong>and</strong> slows down computation.<br />
• End<strong>in</strong>g Parallel.For(Each) loop early<br />
With Parallel.For(Each), ifiterat<strong>in</strong>gthroughthewholeloopisnotneeded,<br />
we can use Stop() <strong>and</strong> Break() functions of ParallelLoopState to jump out<br />
of the loop earlier. While Stop() term<strong>in</strong>ates all <strong>in</strong>dices which are runn<strong>in</strong>g,<br />
Break() only term<strong>in</strong>ates other lower <strong>in</strong>dices so the loop will be stopped more<br />
slowly than the former case. This early loop-break<strong>in</strong>g mechanism is sometimes<br />
helpful to design parallel-exist or parallel-f<strong>in</strong>d functions which are difficult to<br />
do with PLINQ.<br />
To conclude, PLINQ <strong>and</strong> Parallel.For(Each) provide convenient ways to perform<br />
data parallelism <strong>in</strong> .NET platform. While PLINQ is declarative <strong>and</strong> natural<br />
to use, we only have little control to how parallelization is done there. With Parallel.For(Each),<br />
wehavemorecontroloverpartition<strong>in</strong>g<strong>and</strong>distribut<strong>in</strong>gworkloads<br />
on process<strong>in</strong>g units, however their paradigm is somehow imperative. One th<strong>in</strong>g to<br />
keep <strong>in</strong> m<strong>in</strong>d is that parallelism constructs are expensive, so data parallelism is<br />
worth perform<strong>in</strong>g only when workloads are large <strong>and</strong> the number of items is big<br />
enough.<br />
2.2.3 Task parallelism<br />
While data parallelism focuses on data <strong>and</strong> the way to distribute them over process<strong>in</strong>g<br />
units, task parallelism focuses on how to split tasks <strong>in</strong>to small subtasks<br />
13