Concurrent programming

  • I've now crossed the international date line (giving up a big portion of my weekend, but that's life) and landed in Tokyo. Tomorrow I head on to Seoul and then to Beijing for the end of the week. In many ways a change of pace from the week in Vegas, but in other ways it's more of the same (fun, that is :-). In this previous post we looked at some code to retrieve and process RSS information from various blogs using an agent-based message passing architecture. The code wasn't completely asynchronous or parallelised, though, as we fired off each…

  • This is something I've been meaning to attempt for a while, and have finally been spurred to do it by next week's AU Virtual session on F#. Not that I expect to have time to present this during the session (60 minutes is already feeling way too short for the material I want to cover), but I at least wanted to have this working so I could present with a touch more authority. 🙂 In last year's session we used Asynchronous Workflows to improve the performance of IO-bound operations, such as retrieving multiple RSS feeds and displaying the results in…

  • As promised in the last post, we're now going to look at how to change the code to make the colour averaging routine work in parallel. The overall performance is marginally better on my dual-core machine, but I fully expect it to get quicker and quicker as the number of cores multiply. To start with, though, here's the modified "synchronous" version of the code - as I went through making the code work in parallel, I noticed a bunch of general enhancements that were applicable to both versions. Here's the updated F# code: // Use lightweight F# syntax   #light…

  • Well, I couldn't resist... as I mentioned in the last post - where we looked at creating a simple graph inside AutoCAD as an example of modifying objects inside nested transactions - the idea of graphing inside AutoCAD is a good fit for F#. This is for a number of reasons: F# is very mathematical in nature and excels at processing lists of data. I also spiced it up a bit by adding some code to parallelise some of the mathematical operations, but that didn't turn out to be especially compelling with my dual-core laptop. More on that later. Here's…

  • This post continues on from Part 1 of this series. You'll find much of this content has been used before in these previous posts, although post does include content updated for F# 1.9.6.2 (the September 2008 CTP). The first thing we need to do is – as with any AutoCAD .NET project – add project references to AutoCAD's managed assemblies, acmgd.dll and acdbmgd.dll. With F#'s integration into Visual Studio 2008 you do this in exactly the same way as you would for a C# or VB.NET project, by selecting Project -> Add Reference... from the pull-down menu or right-clicking the…

  • A question came up recently in an internal discussion and I thought I'd share it as it proved so illuminating. If I have an object of a type which implements IDisposable, is it good practice to explicitly dispose it (whether via the using statement or calling Dispose() explicitly)? The quick(ish) answer is: Yes it is, but sometimes you might choose not to as the increase in code simplicity outweighs the benefits derived from manually disposing of the objects. So, naturally, the devil is in the detail. Let's take a look at the three scenarios where you're likely to be working…

  • Someone asked me recently how I categorize different programming paradigms. I thought it was a very interesting question, so here's what I responded. Please bear in mind that this is very much the way I see things, and is neither an exhaustive nor a formally-ratified taxonomy. One way to look at languages is whether they're declarative or imperative: Declarative programming languages map the way things are by building up "truths": this category includes functional programming languages (such as Miranda, Haskell and Erlang) which tend to be mathematical in nature (you define equations) and start with lambda calculus as a foundation.…

  • In the last post we saw some code combining F# with C# to create a random "hatch" - a polyline path that bounces around within a boundary. This post extends the code to make use of Asynchronous Workflows in F# to parallelize the testing of points along a segment. In the initial design of the application I decided to test 10 points along each segment, to see whether it remained entirely within our boundary: the idea being that this granularity makes it very likely the segment will fail the test, should it happen to leave the boundary at any point.…

  • In the last post we saw some code that downloaded data - serially - from a number of websites via RSS and created AutoCAD entities linking to the various posts. As promised, in today's post we take that code and enable it to query the same data in parallel by using Asynchronous Workflows in F#. Asynchronous Workflows are an easy-to-use yet powerful mechanism for enabling concurrent programming in F#. Firstly, a little background as to why this type of technique is important. As many - if not all - of you are aware, the days of raw processor speed doubling…