Freesteel Blog » 2008 » May

Friday, May 30th, 2008 at 5:04 pm - - Machining

Suppose you have a function called process() which you want to apply to the members of an array, like so:

ProcessAllSingleThread(array<A> a)
    for (i = 0; i < a.size(); i++)

If it’s okay to execute the process() function simultaneously on entries of the array, the computation can be distributed across several processing cores using multiple threads, like so:

global ndone = 0;
global inext = 0;
bool ProcessAllMultiThread(array<A> a)    // several threads can enter this function
    while (true)
            if (inext == a.size())
                return ndone == a.size();   // false means other threads are working
            i = inext; 



… or some other more complex and correct form that involves the ability to chunk up groups of elements in the array a if the individual process() functions are so trivial that the synchronizing events would overwhelm them individually.

The important thing is it’s not be important to the daily programmer how it is done. All we need to learn is learn how to encapsulate the simple single threaded version in a way that makes it possible to engage the whole multithreaded system.

To do this effectively it helps to have a framework that is general enough to apply to most places you want to.

We can remove the dependency on using an array, and base it on a class T that can return pointers of type A to make a loop like so:

while (true)
        b = T.getnext()
    if (b == 0)
        return T.alldone()

The above ProcessAllMultiThread() fits exactly into this system, which is now flexible enough to handle when the process elements are not quite independent of each other.

For example, if it’s unsafe to process a[i] and a[i + 1] at the same time, but a[i] and a[j] are safe for all abs(i - j) >= 2, then by including a variable processstate in the class A initially set to NOT_DONE, we can implement the two functions, like so:

    for (i = 0; i < a.size(); i++)
        if ((a[i].processstate == NOT_DONE) && 
            (a[i+1].processstate != PROCESSING) && 
            (a[i-1].processstate != PROCESSING))
            a[i].processstate = PROCESSING;
            return a[i];

    b.processstate = DONE;

These functions, subject to some obvious debugging and efficiency improvements, should fit into the parallelizing machinery and make it move forwards when you finally get your shiny new eight core computer and need to prove that the investment was worth it.

Now this framework isn’t quite good enough for cases where there is an aggregation of a result. It needs to be taken further.

Suppose the process function returns a value, and you need the sum of these values. For example, you are measuring the area of a surface composed of a billion triangles with a loop of the form:

sum = 0
for (i = 0; i < a.size(); i++)
    sum += a[i].calcarea();

Let’s assume it’s okay to chunk this sum up into sub-sums, so you don’t need to lock the sum variable a billion times. The framework we might use is:

    w = T.getworkspace()
while (synchronized: w.loadnext()):


I’ve actually got no knowledge of parallel processing, and I don’t want to know anything about it. What’s important to me is the idea I can deliver my algorithm within a set of brick-like (ie small enough to hold in your hand, but large enough to make things with) building blocks so that someone who does have the time and inclination can put them together.

It’s very much like the sort routine. I’ve no interest in the quick-sort, shell-sort or bubble-sort at all. What I do know is if I prepare an array and an operator<() function on its elements, then I can take whatever is the state of the art at the time.

The sort function is something that can be obviously parallelized by virtue of breaking the array up into large chunks and merging the sorted pieces. This only works when your operator<() is thread safe, which it almost always is.

In our code we’ve created the new function called sortMT() that will automatically engages all this machinery if it finds that the array has over a thousand elements, say. Now we have to go through the code everywhere, changing sort() to sortMT(), because the non-threadable case is the default, even though it’s likely to be a very rare exception.

So why don’t we just make sort() to use multi-threads, and establish a sortNonMT() function for these exceptional cases? Why is the default case the exceptional one, and not what we want to apply in the overwhelming situation?

Good question. Maybe we’re not very confident that this multithreading thing is right yet, and this is how it shows.

Tuesday, May 27th, 2008 at 11:19 am - - Machining

The morning ride from Copenhagen to Lyngby was very wet and too fast. I was on Peter’s good bike — the one which had been kept in the store-room for the last three years until we hack-sawed through the spoke lock — rather than the cheap Chinese super-market bought folding bike that had been rescued from the store the day before because it wasn’t locked, so I didn’t have a good excuse for falling so far behind.

It rained heavily all day. In the afternoon a 5-axis machining expert came round to give us the tour of the capabilities of hypermill, delcam, and moduleworks, and it all looked completely straightforward to replicate and improve on from where we stood in relation to our software — which means there’s probably some pitfall on the development path we don’t know about yet. As the Danish say, we don’t know where the dead dog is buried. They also tell you that you can’t blow air and have flour in your mouth.

I got away at 6pm after the rain had stopped and cycled all the way south across Copenhagen where Pelle, one of the players from last Thursday’s game, had invited me dinner before today’s session of underwater rugby. I was late to get there, then stuffed myself on four very large spring rolls and rice, and then we cycled together to the pool. I was assured that the advice against doing violent excercise in the water immediately after a meal was out of date.

The pool was a bit shallower than the one before, and there was only one woman out of the twelve of us. Consequently, the game seemed more violent than before. The bigger guys are harder to tackle because you can’t get your arms halfway around their circumference to hold them down. Surprisingly, I never got kicked in the face, though I did get a nasty muscle cramp in both my legs at the same time. It was a good game. I wish it was played in England instead of underwater hockey all the time.

I had time to eat dessert afterwards when Pelle told me a story from his period in Greenland when an english couple showed up to tow a cycle rickshaw across the ice-cap and left it behind on the glacier. This sounded ridiculous. But some diligent searching on the internet produced a corroboration on this page:

In the summer of 2002 I resumed the journey, heading further north to Aberdeen and then on to the Faroe Islands, Iceland, and Greenland, where “mush mush”, huskies will became involved. Things did not go well on the first attempt to cross the Greenland Icecap and We turned back leaving the rickshaw on the icecap. The following spring, We attempted to re-locate it but there was no trace. Later that year with metal detectors and a glaciologist, we made a second foray up there but without result. At this point I officially declared it lost. This summer I am off to Madras to get a replacement rickshaw and have it shipped to Greenland. After much heart ache, I realize I cannot stop now!

The whole project, (photos here) is about establishing a Cyclerickshawallah Day and giving petrol (or electric) motors to the cyclerickshaws so that the drivers don’t die so young. The health implications of the job are not mentioned on the wikipedia cyclerickshaw page. If they are true, it should be reported there, with links to the medical papers.

Sunday, May 25th, 2008 at 10:11 am - - Machining 1 Comment »

We’re back here again in Denmark via the Harwich to Esbjerg ferry and slow train to Copenhagen having a look at some old machining algorithms and trying to learn what 5-axis strategies are going to be all about.

Interestingly, after years of complaints about the speed of the calculation, we’re now getting total silence on the issue, which is funny as one of the things we came here to do was sort out the parallelizing on multicore machines. Apparently, the calculations are now faster than with the competition, so it’s not a problem. The plan would be to leave it for a while for everyone else to catch up, and then put some work into it. I think it’s better to keep the advantage and push much further ahead while we’re here.

Last night we went out to see Billy Cross play guitar. The songs were all American rock-and-roll, with a lot of incomprehensible Danish chit-chat in between. Last Thursday I got to play Underwater Rugby for the second time in five years. Some time ago I had a session (reported in here) with what I think was the national squad, so I didn’t learn very much. This time it was with these guys who were very friendly and taught me the necessary tricks to know, such as keeping the ball in tucked in your armpit and adding a little spin when trying to throw it.

Friday, May 23rd, 2008 at 1:37 pm - - Machining

Julian noticed a lot of spam showing up in the html sources of the side bar, as hidden text. So finally there was a good reason to give in and update to the latest version of WordPress. We also threw in a few more plugins to protect us from further spam bot attacks (or whoever spammed this site).

Monday, May 19th, 2008 at 3:30 pm - - Whipping 1 Comment »

Following our escapades on Tuesday in relation to the critical by-election nearby, Aidan and I went down again on Saturday with a new colour leaflet because it was the right thing to do — even if nobody else bothered to join us.

I’d say it’s because we’re stepping into the no-man’s land on the border between totally ineffective on-line democratic activism, and the physical world where the game of political reality actually takes place.

Here are the links:

So what next?

The main lesson is there is a lot to learn. What we have done here in the capacity of a non-party generic-selected issue-based election campaigning centred around on-line tools was Version 0.1.

Someone had to do it.

The parties have been doing it for decades, and have learned the ropes and the tricks of the trade over generations. The actual policies held by the parties are often ephemeral, like the players on a city football team. What seems to matter is that your side wins, even if every player was purchased from the opposing side during the previous year. If voters were actually aware of and cared about the policies they were choosing between, then elections would matter. Until then, it’s only about who has the best manager and commands the most money.

We need to think about what to do for the next by-election. This may be in Henley if Boris Johnson resigns his seat. That’s how one learns what to do for the next General Election, so that what you come out with isn’t some crumby web operation you hurriedly slapped together in the first week. Things need to get going now. Stuff to do includes:

Website design – I don’t want something pretty. I want something that works. The design must be data-driven. I have gathered quite a lot of data from the website I currently have. I am inclined to add more monitoring tools and participate in more street-level demonstrations. Anyone who wants to contribute should have ideas about sending different versions of the webpage to users in an effort to find out what works best.

Leaflet and poster design – This is where the political parties have a lot of experience. I’m not a designer at all, but things improved with time. For example, the first leaflet had:

Energy – Alan Simpson MP proposed a renewable energy tariff to pay household consumers for electricity they generate and exported back into the national grid.
On 30 April 2008, 125 Conservative MPs, 37 Labour MPs and 35 LibDem MPs voted for this; however 252 Labour MPs voted against it.

In the second leaflet, this became:

* A law to create a renewable energy tariff to pay household consumers for electricity generated from solar power and put back into the national grid – 30/4/2008

The party-policy chart is interesting. It was made as a paper version of the website in case people didn’t want to type in the URL which we were going to be handing out. People were actually able to fill it in, although they didn’t necessarily know how to read it properly.

As with the web-page, multiple versions are necessary to see what comes out as effective. Poster design would also be quite a challenge. What does it tell people you stand for?

Leaflet distribution – Aidan quipped half in jest that we could run a half-day course in delivering leaflets through letter boxes. I got quite a few cuts on the middle finger of my left hand. Coordinating a leaflet distribution is quite a job, as you can imagine. It’s easy to spec out a really killer application built on top of Open Street Map data where it could calculate optimal distribution routes, and where volunteers could log on and pick them, and report that they have done that area.

Once house numbers have been incorporated into the system, they could be cross-referenced with the electoral role, and the correct number of leaflets could be allocated in the wards where the complete set of data has been gathered. There’s no point in delivering to addresses where nobody can vote, or where they’ve registered for a postal vote which they’ve already sent off.

A tight list of instructions derived from these data-sources and the map could make even a novice delivery person perform as effectively as a pro who has been beating the same ward for years.

Further action and ideas needed

A public whip by-election pledge has been created!
Go sign it

Friday, May 16th, 2008 at 4:29 pm - - Machining 4 Comments »

The power of letting python call OpenGL directly. I thought it wasn’t practicable, but it seems to be okay. Here I’m testing out the toolholder collision detection; showing a series of points where the cutter gets lifted to when there is a wide conical tool-holder in place.

The colour is according to how long the calculation takes (red for slower). It varies by where the sample is taken and will help tune where I need to make the speed improvements.

Friday, May 16th, 2008 at 12:08 pm - - Adaptive

I’m working today. But there is time between compilations of code. I avoided surfing the internet onto anything democracy-related, because then I’d’ve got lost in something interesting and would still be at it at 3am. No chance of that happening when you restrict yourself to the webpages of CADCAM companies.

It’s good to see some of them realizing that the correct format for showing off machining features is the video. Although the quality and content — let alone the lack of sound — is very poor, Delcam has produced a selection to be getting started with. The top one repeatedly shows their user interface interchanging between loops or blobs as it area clearing path goes around corners. Now I know they’ve got a whole machine shop in their building, so why don’t we see how it cuts metal?

MasterCAM has a much better set of videos, although the user interface to them is questionable, and the image is too big. They do give narration and fade nicely between the scenes. Choose Peel Mill in the selection of videos to find a description of their limited trachoidal milling solution, otherwise only mentioned in this press release.

Obviously, both companies haven’t yet reached the state of the art for horizontal trachoidal machining embodied in our four-year-old Adaptive Clearing strategy. If they want to save a lot of time and hassle developing it, they only need to ask. Our rates have been quite reasonable.

WorkNC has 3 videos showing their old Adaptive Trachoidal Roughing. This looks like a retrofit of trachoidalism on a standard offset area clearing algorithm, truncated in the case of a core. At least, like the MasterCAM feature, it shows the capability of this way of machining deeply and cutting with the side of the tool.

I’ve checked out cimatron, solidcam, Tebis, esprit, vero, edgecam, and what became of nc graphics, and none of them seem to have any videos.

There are some on surfware, but the funny thing about it is you can find a far better video of surfcam on youtube, because it’s got music. Just say No to that grinding metal noise. OncCNC has some videos too.

Here is a video of Adaptive Clearing in graphite. And here is a page on HSMWorks where they tell you about Netviewer — a programme that allows someone in Denmark to demo the software remotely on your computer. Why not video one of those demonstrations to make it easier to show up?

Wednesday, May 14th, 2008 at 7:54 pm - - Whipping

Sometimes the campaign managers need their heads banging together.

I haven’t forgotten the time that Tom Watson MP was sent packing after smearing a LibDem candidate for being “soft on criminals and drugs” for having been employed as a barrister and represented such clients in court in her legal capacity.

Politicians, many of whom have worked in the legal system, knew this was totally unfair because (a) all criminals are entitled to legal representation, and (b) barristers are obliged to take the cases given to them.

And so we come to this press release which appeared yesterday at, which they probably think is fair:

Edward Timpson simply hasn’t got what it takes to make our streets safer and stand up for people in Crewe and Nantwich.


Opposed tougher sentences for dangerous sex offenders.

Opposed 5 year minimum sentences for unauthorised possesion of a gun.

Opposed more powers to crack down on underage drinking.

Local residents are saying they want someone with a track record of action getting tough on yobs to represent them – not some Tory Boy who clearly isn’t up to the job.

It is not good enough to just talk about getting tough on crime, the people of Crewe and Nantwich deserve action.

Tamsin Dunwoody knows what is takes to make our streets safer. She has come forward with a plan of action to cut crime and crackdown on anti-social behaviour. Tamsin Dunwoody wants the police to harass yobs, and get in their faces.

She said: “There’s a lot of talk about human rights, for me the most important human right is to feel safe in your home and community.”

Crewe and Nantwich need a fighter who bangs heads together and gets things done.

Tamsin Dunwoody will always stand up for you and your family, she’s a Dunwoody after all.

Now, there’s no email on the site, and they probably wouldn’t answer my requests for particulars. But the source of the allegation is crucial in order to verify the interpretation.

After all, while LibDems can be branded as woolly-minded and soft on crime (according to brain dead wisdom), it seems peculiar to argue that Tories would refrain from the concept of locking people up and throwing away the key — in cases where that would be a good idea.

You’re supposed to count on the designated right wing party to demand punishments for violent crime on the more extreme side of reasonableness, so to call for something that goes beyond their policies is probably going to be unreasonable.

Therefore, such a one-line allegation that Tories are not being tough enough on crime shouldn’t even hold water.

And anyway, it might not even be their policy, because the evidence could be completely circumstantial.

So, to the particulars. There’s a 22 January 2004 press release by the Home Office: Crime Remains Stable – New Five Year Minimum Gun Sentence.

This is a good start. It leads me to the Criminal Justice Act 2003, more specifically Section 287 of the Criminal Justice Act 2003.

Really handy that. It looks like it was thrown in with this raft of measures as New Clause 46. The vote on that raft is here, and the Tories in fact abstained. If you read the debate, it just seems like chaos, with all the debates truncated, and it just doesn’t look good. Anyways, there’s a very strong case against minimum sentencing, which obviously went over the head of our berzerk Home Secretary David Blunkett at the time.

We are talking about such cases as multiple and sadistic killings, and when terrorists take the lives of others. In more traditional terms, before suicide bombing occurred, there was at least a way of sending signals to and getting retribution from terrorists. We are talking about incidents of child murder, which I have described, and the way in which people abused others before committing such a crime…

I am motivated, as is indicated by the sentencing framework and the new purposes of sentencing, by the desire to show those who are engaged in such actions that there will be clear and unequivocal consequences.

What a mess. There’s no evidence that harsh publishment reduces crime. It’s an ill-informed and ignorant thing to believe, and highly irresponsibly to use a position of authority to tell people it’s true.

I just don’t want to think that this was done for the benefit of one line in an election leaflet, and that there’s a whole tranche of other misleading crap stored up waiting to be shovelled out onto the pages of all the campaign materials. It shouldn’t be done. And more importantly, it shouldn’t succeed. If this was London or Edinburgh, they’d probably be throwing around the “T” word for good measure.

Wednesday, May 14th, 2008 at 8:47 am - - Whipping 2 Comments »

Press Release – Immediate Release
14 May 2008
The Public Whip

While activists are descending from all corners of the country to Crewe & Nantwich to help with their partys’ by-election campaigns, volunteers from the Public Whip today launched an online questionnaire to help people make up their minds about who to vote for. The webpage:

compares people’s opinions to the way each party has voted in Parliament on a selection of important issues that have been in the news in the last five years. It uses the web-site as a source of data.

As Julian Todd of Public Whip explained “An election is the one time people have a direct say in what the politicians do. Unfortunately, with slick sound-bites and colourful leaflets focussing on one or two key points, it’s easy to forget the bigger issues that will be decided by the MP who eventually wins the seat.”

Aidan McGuire said “The national issues which our MPs have control over are not being discussed with the candidates during this campaign. People are easily distracted by smaller matters like car parking charges, when what is actually decided by those who are elected include compulsory ID Cards, nuclear power plants, freedom of information laws, and the strategic supply of fuel and electricity.”

“We want people to remember the bigger issues and ask hard questions of the candidates about how they would vote after they are elected. People have become used to not being told what the policies are and not insisting on their right to know.”

Here in Crewe & Nantwich, the Labour candidate, Tamsin Dunwoody, is running on her mother’s name. Gwyneth Dunwoody was a popular MP partly because she had a mind of her own and did not vote the government line on every issue. How many people have looked up which were the issues she rebelled on, and has anyone asked Tamsin whether she would take the same position on those issues?

Julian said: “We want people to start using the internet more effectively to understand what their MPs are doing and to keep a close watch. Who knows, they might start doing more of what people want them to do, rather than their own thing all the time. That’s our idea of what democracy would look like.

“That’s why we’ve brought the Public Whip website to the voters of this city. It’s our tiny contribution to democracy. We hope to inspire other people with our example so they bring their own democracy projects to places where it matters, like this by-election and other elections in the future, to help voters make an informed choice. Democracy is too important to be left to the political parties alone.

About the Public Whip
Public Whip is a website that scans Hansard, the official Parliamentary record, for all the votes by MPs and sorts them into a database for further analysis. It was originally written by Francis Irving and Julian Todd in 2003. All the software is free and open source and is completely self-funded and maintained by volunteer work.


Thursday, May 8th, 2008 at 5:11 pm - - Whipping

The leaflet has now been passed in front of a few sharp eyes. I’ve got to recheck all the numbers on it before I take it to the printers.

We do things properly around here. I’m emailing all the candidates campaign emails with a copy of the leaflet, asking for any comments, and stating my interest as a recent member of the Green Party, for which I will be doing no campaigning.

The Labour candidate webpage is up. Have emailed them through their crappy webform which required me to give my postcode.

I’d already emailed UKIP and given them an earlier copy. They told me I couldn’t use Bob Spink’s voting record as a basis for UKIP, so I deleted the column in the table, which is fine by me as it freed up space. I tried. They didn’t bite.

I don’t feel like contacting the English Democrats.

I’ve emailed a copy to the LibDem campaign. I happen to know somebody whose wife is going down on Friday to help them campaign. He asked if she could take a copy. But I am being strictly non-partisan here. If she reaches their office and tells them not to bin my email — as all the other candidates are most likely going to do — they’ll have the advantage. Such as it is. Interestingly, when I take the test on the webpage the LibDems score 128/140, the Tories get 59/140, and Labour gets 38/140. So it could only go downhill from that.

I really can’t face emailing Mr. Cut Tax on Petrol and Diesel.

No need to email the Greens. They know who I am, and I happen to know the candidate who was an emergency last-minute parachute from Liverpool. It’s chaos out there. I will get someone in the Party to make me a voting chart for the Public Whip to stand in place of their lack of MPs if it is the last thing I ever do.

Now to print out some maps. We go away to some geology course in North Wales over the weekend. Then back to this game.