buckyb
Posts: 15
Joined: Sun Mar 30, 2014 3:05 pm
Location: South Africa

RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 11:16 am

In 1981 and 1983 Byte Magazine ran two articles on computer and compiler speeds using a Sieve Of Erastosthenes program as a benchmark.

I thought it would be interesting to compare the speeds then obtained with those I can get on newly built PC and then on my model B RPi. To my surprise the RPi came out faster than the Cray 1 supercomputer of the time.

These were the timings obtained, in seconds, adjusted to the standard then used of 10 iterations:

Cray 1 supercomputer (Fortran) 0.110
RPi model B (C) 0.0205

The C code used on the RPi is below

Code: Select all


#include<stdio.h>
#include<stdlib.h>

#define TRUE 1
#define FALSE 0
#define SIZE 8190
#define SIZEPL 8191

char flags [SIZEPL];
int i, prime,k,count,iter;


int main()

{
	printf("\nHit ENTER to do 100 000 iterations:\n\n");
	getchar();


	for (iter=1; iter<100000; iter++) {
		count=0;
		for (i=0; i<= SIZE; i++)
			flags[i] = TRUE;
		for (i=0; i<= SIZE; i++) {

			if (flags[i]) {
				prime=i+i+3;
/*				printf ("\n%d",prime);*/
				k=i+prime;
				while(k<=SIZE) {
					flags [k]=FALSE;
					k+=prime;
				}
				count++;
			}
		}
	}

	printf("\7\n\n%d primes.\n",count);

return(0);

}

The program computes the first 1899 primes up to 16381. It does not display them unless the comments around the middle printf statement are removed as this slows the program down considerably. If you want to see the primes, reset the iterations to 1 only and remove the comments /* and */

It was compiled using the command
gcc -Wall -W -Werror sieve2.c -o sieve2
and run, in the same directory, with
./sieve2
Timing is started when
Hit ENTER to do 100 000 iterations:
appears and stopped when
1899 primes.
is seen.

My interest in this program goes back to a ZX Spectrum and Hisoft C but I no longer have data on the timings I got with these.

With acknowledgements to Jim and Gary Gilbreath and Byte

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 1:26 pm

buckyb wrote:It does not display them unless the comments around the middle printf statement are removed as this slows the program down considerably.
Does this count? How was their original test run - with the output piped to a file perhaps?

Interesting comparison though.

Heater
Posts: 11458
Joined: Tue Jul 17, 2012 3:02 pm

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 2:30 pm

@buckyb,

You might want to add some compiler optimizations to your compile command. -O3 for example.

Your code runs in about 8.8 seconds on this PC. Adding -O3 reduces that to about 3.1 seconds.

Not bad, about 350 times faster than the Cray apparently.

But be careful. Such optimizations can end up completely removing the code you are timing. If code has no output that is used anywhere else in the program the optimizer can just decide not include it. That makes things look very fast!

You can add the "volatile" keyword to things like the prime declaration to forc the compiler not optimize away the code.

It always pays to have a look at the assembler that is generated to see what is happening. Use the -S option to get an assembler output. Set the output to -o sieve.S or some such.

@Ravenous,
Does this count? How was their original test run - with the output piped to a file perhaps?
No need to pipe anything anywhere. The primes can be saved in memory, or perhaps even just the last one is saved. Then printed out when the timing is done.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 2:44 pm

Heater wrote:No need to pipe anything anywhere. The primes can be saved in memory, or perhaps even just the last one is saved. Then printed out when the timing is done.
That's not quite the point I was making. If the original 80s test didn't output results either, that's fine. But otherwise it's not a fair test, just running the fastest bits of the process and deliberately commenting out the the slower ones.

By the way, 30+ years of Moore's Law (OK I know he wasn't talking about speed) is (I think?) 2^30 or a billion times faster for a modern equivalent computer. Wonder what a modern one would do with this code (I suppose we'd need a parallel version).

Heater
Posts: 11458
Joined: Tue Jul 17, 2012 3:02 pm

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 4:41 pm

Ravenous,

I know what you mean but it is traditional for benchmarks to be such that they exercise and measure the performance of some algorithm or other. Without regard to I/O speed. I/O speed is necessarily very platform specific. Think DHRYSONE, WHETSONE and a bunch of other famous benchmarks.

Unless of course the purpose of the benchmark is to gauge I/O performance.
By the way, 30+ years of Moore's Law (OK I know he wasn't talking about speed) is (I think?) 2^30 or a billion times faster for a modern equivalent computer.
Quite so Moore was not talking about speed but rather the number of transistor that can be integrated onto a chip. Of course more transistors means smaller size means faster speed so the "law" has applied to speed as well.

Moore talks about a doubling every 18 months I think, which people often round up to two years. So we might only expect a speed boost of 30 thousand or so.

We seem to have fallen short. Moore seems to suggest we should be clocking chips at about 2 to the power 16 hertz by now, Given that a PC was doing about 5MHz in 1982.

Sure enough processor speeds stopped rising some years ago and chip makers started moving to using those transistors for more cores and supper parallel GPUs etc.

Now, how fast could this sieve be made to run on the GPU of the Pi?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 21664
Joined: Sat Jul 30, 2011 7:41 pm

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 4:46 pm

The Cray was a parallel machine IIRC?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

User avatar
aTao
Posts: 1084
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 4:55 pm

jamesh wrote:The Cray was a parallel machine IIRC?
heavily pipelined.
>)))'><'(((<

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 5:01 pm

If any young things are interested, Moore's paper was reprinted and a copy is here:
http://www.cs.utexas.edu/~fussell/cours ... /moore.pdf
(The original printing was online somewhere too, but I can't find it right now.)

In his original he talks about "roughly a factor of two per year" (section IV of the paper). So it wasn't doubling every two years or 18 months or the other rubbish people misattribute, though that may be the current rate.

Also note he didn't claim it to be a "law". It was just extrapolating a graph at the time (fig. 3). Also he wasn't claiming it would be maintained for very long; of course, it wasn't.

Sorry to lecture. But I just have a bit of a hobby horse about people "rewriting" things and conveniently forgetting the original. Now you can all correct those people because YOU have read the original too :)

buckyb
Posts: 15
Joined: Sun Mar 30, 2014 3:05 pm
Location: South Africa

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 5:21 pm

Thanks for all the comments. I am glad you found it interesting.

The commented line was put in by Jim Gilbreath as a debugging aid and is not intended to be part of the benchmark. I included the remark in case others wanted to see some action.

On a PC with an i7-4770K processor running Ubuntu 14.04 the timing came to 0.00071 sec.

I am not a programmer, just an ageing hobbyist: the use of sophisticated compiler options is out of my scope! But thanks for the suggestion.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 5:29 pm

buckyb wrote:The commented line was put in by Jim Gilbreath as a debugging aid and is not intended to be part of the benchmark. I included the remark in case others wanted to see some action.
That answers my query, thanks.

Yes it is an interesting comparison. Especially with that equivalent number from the faster PC...

No idea how we'd do this with a modern, massively parallel supercomputer. Maybe assign each of the 100,000 iterations to one core...

Heater
Posts: 11458
Joined: Tue Jul 17, 2012 3:02 pm

Re: RPi Model B faster than Cray 1 supercomputer!?

Tue Nov 11, 2014 5:46 pm

Ravenous,

Quite so. Certainly Moore's law is no actual law. Just an observation.

Given that it was originally phrased, quite rightly, in vague terms ("roughly") I would not be so picky about people who have never seen that article using 18 months, two years or whatever. It's close enough. Certainly not "rubbish"

Thanks for the link to the article.

You might like this article about the end of Moore's law http://www.extremetech.com/computing/16 ... n-a-decade

A quick look at the graph there shows that in terms of Moore's law misapplied to clock speed we hit the wall a decade ago already.

On the other hand transistor count seems to still be soaring nicely.

Return to “General discussion”