Parallel and Concurrent Programming with F# Slides and Code

Thank you to all who showed up at my talk last night.  As promissed, please find the slides and source code for the demos.  Special thanks to Mutaamba Maasha, who came up with a recursive solution that would process our list of 1 million 64 bit integers without running into a stack overflow error.   The solution is provided in the source code in "".  Mutaamba will be giving a presentation next month on January 4th, 2010, so please join us next month for his presentation.  Also, as a challenge to all, try to see if you can create a generic PSeq.sum function in the PSeqLib.fs file.  See you at the next meeting.


4 thoughts on “Parallel and Concurrent Programming with F# Slides and Code

  1. Sorry I wasn’t able to stay for the last part of your talk.Here’s an idiomatic way of converting something like your sumOfSquaresR into a fully tail recursive version. It doesn’t require the use of the List module. I believe one of the other attendees alluded to this technique of using an explicit accumulator. The compiler will optimize the tail call and it will execute in constant space. let sqr x = x * xlet sumOfSquaresTR num = let rec sumAux num acc = match num with | [] -> acc | hd::tl -> sumAux tl (acc + sqr hd) sumAux num 0LIn almost any case where the form of the naive recursive solution looks like(in ‘pseudo F#’)let rec someFunc list = match list with | [] -> constant | hd::tl -> doSomething(hd) op someFunc tlyou can morph this into a tail-recursive version:let someFuncTR list = let rec sumFuncAux list acc match list with | [] -> acc | hd::tl -> sumFuncAux tl (acc op doSomething hd) someFuncAux list constantThanks for presenting the talk. Perhaps we can get a more in-depth presentation on Asynchronous Workflows or Computational Expressions sometime soon.

  2. Thank you for the idiomatic version of recursively approaching this problem. Did you see Mutaamba’s version which I included in the file? It uses List.fold and although it uses an accumulator, I didn’t notice any significant memory consumption processing a list of 10 million int64 values. Maybe the compiler optimizations are in play in his version too. Here is Mutaamba’s version:let rec sumOfSquaresFold nums = List.fold (fun acc elem -> acc + sqr(elem)) 0L nums

  3. Also, I plan on working on more in depth talks in the future on using TPL and async workflows. If you have some material on the subject, please sign up to speak or we can do a joint presentation.

  4. (I see that the comment processor was kind enough to remove all the leading spaces from my previous post. Hopefully the intent (indent?) was obvious)The List.fold function uses the same idiom. Fold is essentially this (from Jon Harrop’s excellent "F# for Technical Computing")let rec fold f accu list = …..match list with …..| x:xs -> fold f (f accu x) xs…..| [] -> accureally the same thing just using a prefix function instead of infix operator.One thing that might be worth some further exploration at a future meeting is why Sequences are good for this sort of thing – i.e.the advantages of lazy evaluation. Since Sequences are the prototypical use of computational expressions in F# maybe that would bea good lead-in to a general discussion of computational expressions / monads. Waddya think?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s