The 'qsort a list' example is often trotted out for its functional elegance, but it's a downright abysmal piece of code when it comes to performance. Lists are immutable; appending two lists with @ is O(N) in the left argument, and you allocate all over the place, bottlenecking the whole process in the garbage collector. There's no use trying to parallelize this code.

For sorting, you have to use arrays and mutation.

If you're looking for an elegant functional algorithm to parallelize, well, I can't think of one offhand, though there may be some. My personal philosophy is that "if you want fast, use arrays and mutation", but I bet there are some good functional data structures and algorithms that are less than O(N^2) in time and space and those may be amenable to parallelism... I just can't think of any right now. Be sure to do time and space big-oh analysis first, since there's typically no sense trying to parallelize an O(N^2) algorithm when an O(NlogN) algorithm exists.

By on 4/8/2010 9:24 AM ()

Hi again,

From what I understand, Quicksort can be parallelized either using Task Parallel manner (new Task for each sub-sort call) or the Data Parallel one (parallel list filtering).

So the attempt based on Tasks ended like this:

I have also tried Data Parallelism with PSeq.filter, but there were those Seq.toList calls, so it all ended up miserable.

Anyway, can anyone point me in the good direction here? Where to look for speedups?

By on 4/8/2010 7:59 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper