Going atomic … or concurrency is hard


SVG Graph Illustrating Amdahl's Law
SVG Graph Illustrating Amdahl’s Law (Photo credit: Wikipedia)

In my PhD world a year’s worth of software experimentation has proved what we all knew already … that systems using traditional memory models struggle in the Network-on-Chip environment and so I am now trying something slightly different.

My “model” (it’s all in software) is of a 16 core system, with each core having a small amount of on-chip memory (32k), which are combined together to form a flat memory space. Memory in this space can be accessed quickly, memory outside it, in the next level up in the hierarchy, is roughly 100 times further away.

Using any form of traditional paging model (including Belady’s optimal page replacement algorithm) this system starts to thrash on even moderate loads – the cost of moving pages in and out of the local memory determines performance and so there is no benefit from adding additional processors (in fact it just slows the individual processors down).

Such an outcome makes any promise of improved performance from parallelism void – it does not really matter how efficiently you have parallelised the code (some corner cases excepted – eg if all chips were accessing the same memory at the same time), you are trapped by a memory I/O bound.

So now I want to look at alternatives beyond the usual 4k (or 2k) paging – but I have been struggling all week to get the locking semantics of my code right. Concurrency is hard.

The one thing that debugging parallel code and locks teaches you again and again is never to assume that some event will be so rare you don’t need to bother about it: because when you are executing millions of instructions a second, even rare events tend to happen.

It has also taught me to check return values – code that will “always” work in a single threaded environment may actually turn out to be quite a tricky customer when running in parallel with other instances of itself or when it is accessing shared memory.

But, finally, the main lesson this week has been about going atomic.

I have a tendency to think – if I can release that lock for a few lines of code that might improve overall performance and I can just lock it again a little later. Beware of that thought.

If you need to make a series of actions atomic you need to hold the same lock across them all – releasing it for even a few lines breaks atomicity and will quite likely break your code.

A probably entirely naïve question about the principle of relativity


English: M&M-experiment
English: M&M-experiment (Photo credit: Wikipedia)

Surely I can quite easily design an experiment that shows the relativity principle is false.

If turn around on the spot the principle, as I understand it, asserts that I cannot build an experiment that proves it was me that moved as opposed to everything else that moved while I stayed still.

But the rest of the universe is very massive – possibly of infinite mass – and so to move it through 2\pi radians takes a hell of a lot more energy than moving me.

The real reason why you haven’t been polled in #indyref


English: Graph showing support for political p...
English: Graph showing support for political parties in New Zealand since the 2008 election, according to various political polls. Data is obtained from the Wikipedia page, Opinion polling for the New Zealand general election, 2011 (Photo credit: Wikipedia)

Some people – Yes supporters essentially – are claiming that it is plain that the opinion polls – none of which (so far, at least – I hope I am not tempting fate) have reported a Yes lead – in the Scottish independence referendum are rigged is because they have never been asked.

Well, there is a simple reason for that: polls are small and the electorate is very large.

There are about 4 million electors able to vote in the Scottish independence referendum.

If we assume every elector has an equally random chance of being asked (which is not true for many cases: if you are not on an online panel it just won’t happen), and that each poll asks 1200 electors then the chances of you being asked in any given poll are 1200/4000000 or about 1 in 3,333: a bit better than winning the lottery jackpot I’d admit, but who bets on a 3332/1 chance?

Of course, though, there are multiple polls but to have just a 1 in 100 chance of being asked then 33 polls would have to be taken. To make it more likely than unlikely that you had been polled then 1667 polls would have to be taken.

What Scotland Thinks, at the time of writing, records 80 polls on the referendum question – so the chances of any individual elector being asked are (given all my approximations) about 1 in 42, or in bookies’ odds terms, it’s a 41/1 shot.

If you think a race is fixed because your 41/1 wager never comes home, I’d suggest you weren’t to be trusted in a betting shop.

Update: Should make it clear this is a pretty crude approximation to make a point – opinion poll sample sizes vary and if they are closer to 1000 in sample size then the odds of you being asked go up to about 49/1 (ie., it’s a fair bit less likely).

A further update: My intention on writing this was to demonstrate, in the broad brush terms why an argument based “I have never been polled so therefore the polls are wrong” didn’t hold any water. It seems the article now being touted around as an exact prediction of how likely it was you’d been asked: it’s not. As I say above much (most probably) polling these days is via online panel – if you are not on the panel you cannot be asked to begin with.

(Scottish) opinion polls – a reminder


English: Northern Ireland opinion poll on Prot...
English: Northern Ireland opinion poll on Protestant identity in Northern Ireland. Data from the Northern Ireland Life and Times Survey http://www.ark.ac.uk/nilt/. (Photo credit: Wikipedia)

This is not about which way you should use your vote if you have one – that is here.

Instead it’s reminder of the maths of opinion polling, because I suspect we are going to see great numbers of polls in the next few weeks.

So here are some things to remember:

1. The best an opinion poll can do is tell you what a good opinion poll would show. In other words, opinion polls cannot be thought of as reliable predictors of results. Simply put – if people systematically fail to tell the truth to opinion pollsters then no opinion poll is going to perfectly correct for that (the pollsters try but their work here is merely based on informed guessing). So when pollsters talk about “margins of error” they don’t mean in comparison to a real election result, but to what another – well taken – poll would show.

2. One in twenty opinion polls – no matter how well conducted – will be very wrong. This is the so-called “rogue” poll and it’s incorrectness is not because it has been conducted improperly but because sampling a small subset of a large population is inherently statistically risky.

3. Doubling the sample size does not mean your poll more twice as accurate. In fact it only makes it \sqrt2 more accurate. The important point here is that when you look at small samples – such as Scottish regions – you are looking through the other end of this telescope – so a smaple that contained \frac{1}{5}th of the poll sample would actually have a margin of error that was \sqrt 5 (or about 2.2) times bigger (and that assumes the sampling in that region actually matches the population in that region as opposed to Scotland as a whole – if it doesn’t, and the chances are that it won’t, then you are better off just ignoring the subsample).

4. “Margin of error” is really a measure of how likely other polls will give the similar results. We have already covered this – but here’s a longer explanation. If we say that the margin of error on a poll is plus or minus three per cent, then typically what we mean is that 95% (i.e., 19 out of 20) polls will give results where the figures do not differ by more than three per cent. This also means if you describe a 1 per cent change in a rating as in some way significant then you are very wrong – because actually your poll does not give you enough information to make that claim. To go from a 3% margin of error to a 1% margin requires you to increase the sample size by a factor of 9. To go to a margin of plus or minus 0.5% would require an increase in sample size by a factor of 36.

5. The margin of error actually depends on the score polled. The highest margin of error is at 50% – where for a 1000 sample poll it is:

2 \times \sqrt \frac{0.5 \times 0.5}{1000} = \pm3.4\%

For 40% the margin becomes 2 \times \sqrt \frac{0.6 \times 0.4}{1000} = \pm 3.1\%

(And these figures are for the numbers before the don’t knows are discounted.)

All in the mind?


Running the Hackney half marathonFor the last 14 months running has been a big thing in my life – with the pinnacle (in distance, if not speed) being my completion of the Hackney half marathon in June (the picture is of me struggling to get through the 10th mile).

The core run each week has been the Finsbury (or occasionally some other) parkrun – an approximate 5km timed run.

The Finsbury Park course is famously tough – two laps of one long, relatively  gentle climb and one short, relatively steep hill.

Back in June, in heavy training for the Hackney half, I got my PB down to 23 minutes and 17 seconds on that course. Since then I have run it three times – every time worst than the last and every time above 25 minutes (today’s was a very bad 25’59”).

Training runs, too, have not been distinguished by speed (though I am gradually returning to longer distances as I train for the Royal Parks half marathon in October – sponsor me (for Oxfam) here) and two 10k races have shown me post times that were slower than the first 10k race I ran (which was in May).

What’s gone wrong? Running performance is pretty much all in the mind or at least it is about the mind’s tolerance of pain and discomfort – and I just do not want it badly enough, I think. Today I did a pretty decent first lap – the GPS on the phone is a bit iffy, typically reporting too fast a time/over-reporting the distance run, but I managed the first 2.5km in about 11’50” – not brilliant but not a million miles from that PB time, but then I effectively decided I didn’t like the discomfort much and so the second lap was in around 14’08”.

The thing is, I had gone out this morning with the intention of ending my run of worsening performances, but in the end just didn’t want that enough. I can try again next week, I suppose.

 

Islamism is bad for your health – and not just in the obvious ways


Asura demonstration in freedom square, Tehran,...
Asura demonstration in freedom square, Tehran, during 1979 Iranian revolution (Photo credit: Wikipedia)

Thanks to the New Scientist I have discovered that Islamic fundamentalism can have more damaging effects than just its attack on science, reason, liberty and equality: it can also damage your health.

Evidence from Iran, where the 1979 revolution led to both men and women adopting far more conservative modes of dress, is that the incidence of multiple sclerosis also began to increase – in fact ,according to this paper in the British Medical Journal, the incidence of MS increased eightfold between 1989 and 2006.

Scientists think the most likely reason is that the skin of Iranians was much less exposed to the Sun and consequently vitamin D production (as the New Scientist notes technically “vitamin D” produced in this way is not a vitamin at all, but that’s a different story) fell. The evidence that vitamin D production is closely linked to a variety of autoimmune diseases, including MS, is also growing.

The Scottish referendum: taking a stand


I am not Scottish. I lived there, once, a long time ago but I have no vote in the referendum next month.

I do have a pretty direct personal stake in the outcome though. My partner is Scottish and a yes vote would, to some extent (and I think a greater extent as the years went on) make her a foreigner in what is now her own country. My two children certainly have as much claim to be Scottish through her as they do to be Irish through me. And, of course, the eldest is actually resident in Glasgow, at least while the University is in term time.

But, actually, my personal stake is much bigger than any of that. I fear a yes vote on September 18 will lead to a nasty, and possibly permanent, disfigurement of politics both north and south of the Tweed. And I am drawn to that conclusion by both the character of the campaign for a yes vote and the inevitable changes in political calculus a yes victory would bring – both short- and long-term to the politics of the remainder of the UK. It worries me enough to break my self-denying ordinance about politics here and to, in a way, make my stand. I can do no other.

It is common for those campaigning for a “Yes” vote to say it’s not about Alex Salmond or his Scottish National Party (SNP). But, of course, it very much is. The SNP are the only party of real significance in Scotland campaigning for a “yes” (I really do wonder how many Green voters are pro-independence as opposed to just anti-politics), they have a majority in the Scottish Parliament, they will negotiate the terms of any independence settlement and they will form the first government of an independent Scotland if that happens according to their timetable. They control all the levers on the Scottish side of this nightmare equation – and it will be their Scotland we will get if the vote is yes.

They say that people like me (if I lived in Scotland) should not worry about that. After all, they say, they – like me – are social democrats. Indeed many of their supporters go further and say that people like me – bought and sold by English gold – have no longer any real claim to be on the left, content as I appear to me, to ask the Scots to continue to suffer under Tory rule.

But then, I do not believe them. I am sure there are people in the SNP who genuinely believe themselves to be social democrats or even socialists – but their actions convince me that they are above all nationalists and, in a way that is fundamentally alien to social democrats, are seeking to divide people.

Scotland is no colony, it is not a victim of imperial divide and rule or exploitation and so its nationalism cannot claim to be anything other than a desire to separate, to negate the claim that Die Arbeiter haben kein Vaterland.

And I want no part of that. More than that, my internationalism, my compunction to solidarity, makes me want to do all that I can to stop it happening and to urge my readers here to join me.

The rationalist wing of the SNP would no doubt respond that: no, Scotland is not a colony but my judgement is blinded by tribalism. The reason the Labour Party detests the SNP is not, they might claim, because they are so different, but because they are so alike. Not so. Not so at all.

On 10 March 1998 I had been the Labour Party’s Chief Press and Broadcasting Officer (for the first time) for about a week. That morning I was phoned by Jim Murphy, an MP for not yet a year but already clearly one of the brightest hopes in an exceptionally strong Scottish Parliamentary Labour Party.

Jim had been up all night but he was fizzing with energy. That night the House of Commons had heard the report stage of the National Minimum Wage Bill and the Tories had kept the House up all night debating and voting on amendments. And instead of taking part in the defence of the Bill, the SNP had gone to bed.

These were the early, and heroic, days of Labour government. Everything, or almost everything, the government did was as loaded with symbolism as content – but in the National Minimum Wage we were surely – alongside the Good Friday Agreement and devolution – talking of an epoch-making policy. This stuff really mattered and would do for decades to come. The livelihoods of millions of people were being debated.

The SNP said their vote didn’t matter because Labour had such a large majority. And, mathematically, they were right, but politically they revealed the huge gulf between them and us.

The hundreds of Labour MPs who went through the lobbies were proud and not angry at having stayed up all night to see off the Tories. A minimum wage was the antithesis of the Thatcherite vision for the economy: in the previous 18 years the Tories had actively removed what little protection for wages had existed when they came into office and revelled in the idea of growing low waged employment – boasting that the future of work for millions would be “no so much low-skill as no-skill”.

(The idea was also an example of the influence of the feminised New Left on New Labour – no previous Labour government had legislated for a minimum wage because it had been actively opposed by the big craft unions.)

The SNP just did not see any of that. Because, in the end, they just didn’t care about social progress in the same way as we did. Like Trotskyists considering the politics of social democracy they saw, and see, their principal task as being to destroy the credibility of the reformer, not to secure the reform.

That morning Jim and I agreed a text that later got us both into a bit of trouble:

“Thousands of low paid Scots were on the night shift working to support their families.

“Labour MP’s were at work too – beating off the Tories’ attempts to preserve low pay.

“Where were the Nats?

“Their absence was an insult to those Scots who have campaigned long and hard against low pay.

“I never want to hear another Nat say they stand up for Scottish values. Last night they were not standing up at all – they were down in the gutter with the sweat shop sewer rats.”

The SNP used this for the next year to say Jim had said they were sewer rats. Of course, he hadn’t – but, carried away, we had let emotion over-ride judgement.

The words were a mistake yet, looking back, I can still see why we did what we did. And I have seen nothing to make me think the SNP have changed their approach to social progress – indeed they have spent the last two years telling us, in effect, that social progress is impossible in the UK context, they have rubbished every piece of progress that has been made or issued promises of jam tomorrow under independence using phrasing that indicated they had neither thought about, nor cared about, the issue but were focused entirely on what they saw as its vote winning potential.

(A recent statement on the minimum wage was one example – they said they would consider a “Scottish minimum wage” that would always rise by at least inflation after independence. But today’s minimum wage is meant to be set on the basis that it should grow without increasing unemployment: are the SNP really pledging they would enshrine in law that a minimum wage would grow even if it increased unemployment? Or are they just trying to find a sound bite that makes them look “progressive” while actually pledging to do nothing at all?)

To cap it all, they effectively offer up daily prayers for a Tory victory at the next election: the worse, the better is their approach.

What evidence is there that an SNP-run independent Scotland would be any more progressive? Little or none from the SNP government in Edinburgh. Their flagship policies include a freeze on council tax (which is starving Social Work departments of money and leaving teachers on the dole queues) and paying for free university tuition for the middle class by cutting bursaries for working class entrants. Their flagship economic policy is to cut corporation tax in the hope that Scotland might emulate Ireland as a home for profit recycling (though these days they no longer mention Ireland even if they have kept the policy).

https://twitter.com/StephenNoon/status/499861574627381248

In response I will be told that the SNP need not govern an independent Scotland. As I have already set out that is a false claim (assuming that the SNP manage to keep to their timetable) and in any case Alex Salmond has already stated that independence will mean “Labour no more” – and I fear he is right.

https://twitter.com/MisssyM/status/499672963101106178

An independent Scotland will surely be dominated by populist nationalism while those who campaigned and voted to stay in the UK will be slammed as traitors and quislings and worse.

https://twitter.com/ScottishWulver/status/498210088092700673

The online pro-independence campaign is deeply nasty and intolerant – and infected with the usual internet paranoia of the online far-right/far-left alliance (no campaigners are part of a “new world order” conspiracy, are in the pay of a secret higher power, the broadcasters and the pollsters are all knowingly telling lies and so on).

https://twitter.com/ratelmel/status/496676261381820416

 

Of course these days the Nationalists know that a direct attack on “the English” generates revulsion amongst most people in Scotland, so they have found a new way of blowing that dog whistle by talking of “Westminster” and “Westminster elites”: the whole thing reminds me of the way anti-Semites think that saying they are only against “Zionists” gets them off the hook (I am making a comparison of tactics here – not saying the Yes campaign is a haven of anti-Semites.)

Even the SNP’s argument about nuclear weapons is empty – voting Yes won’t lead to any nuclear disarmament – it will merely see the nuclear weapons move (eventually) from one base to another. Indeed voting yes is to consciously opt-out of any effort to secure nuclear disarmament by simply handing your nuclear weapons off to someone else. I cannot see how anyone serious about nuclear disarmament could see this as any sort of progress.

People will be voting yes for many reasons, and the vast majority of them will do so for what they see as progressive reasons. But I think they are wrong, I intend to keep saying so and I hope that more and more people on the left throughout the UK, Europe and wider yet will join me in making that argument.

Follow

Get every new post delivered to your Inbox.

Join 1,004 other followers

%d bloggers like this: