Saturday, 27 June 2009

Principle of Biggest Surprise

I've written an article about weird things in Python. You can find it here. Please leave your comments under this post or write an email.

Sunday, 21 June 2009

Braid

This blog isn't really meant to be about games, but this time it has to be.

I recently (on Friday) purchased the indie-game Braid on Steam. I am really excited by it, and have finished it by now. It features really clever gameplay, beautiful music and, in its own way, beautiful graphics. If you care about the storyline of a game, Braid has a very good, but also confusing story. The major downside it has is that it is incredibly short, I had finished it after about 8 hours. But well, I still have the speed-runs to do, and they will not be easy.

It was very well worth the 13 euros.

Wednesday, 10 June 2009

Parallel computing with Python

I've been writing a library that streamlines the process of parallelization. It is inspired by Cilk and thus has a really simple design. The name isn't yet decided, but I think I will call it pylk. I'm also trying to write a cluster-library, and once that is finished I will try to add a backend that executes the functions that were spawned on the cluster.

Below is some (commented) example code.
# Use multiprocessing backend.
backend = MPBackend()
# Start the thread that listens for I/O from the processes.
backend.iohandler.start()

# Do some calculations.
a = backend.spawn(reduce, operator.mul, xrange(1, 50000))
b = backend.spawn(reduce, operator.mul, xrange(1, 50000))

# When you need the results, sync them.
a, b = sync(a, b)
# When done, shut down the I/O thread so the application can exit.
backend.iohandler.stop()

Sunday, 24 May 2009

Blogger sucks

Look at the previous post, no more explanations needed.

Unnecessary explanation: That is the HTML I fed it with.

Python threading (and the GIL)

My shiny new Quad-Core Intel i7 has brought my attention to writing software that scales on multiple processors (the OS even considers the i7 a 8-core because of the HyperThreading technology it comes with).

I like Python, I like it a lot. Still, I have to admit that its threading sucks. It doesn't at all scale to multiple processors (this is due to the GIL). So what does GIL mean anyway? It means that the Python interpreter always only executes one piece of bytecode at a time. This means, that only one thread can execute python code at a time, thus rendering threads for scaleability useless.

Here are some benchmarks on how long it takes to add a lot of numbers (distributed on n threads or processes) on my i7.















































ThreadsTime (in Seconds)Difference
121.15 -
223.17+9.56%
324.83+7.16%
425.13+1.21%
523.67-5.81%
624.90+5.21%
724.74-0.64%
825.36+2.52%
















































ProcessesTime (in Seconds)Difference
1 20.36 -
2 10.43 -48.78%
3 6.91 -33.79%
4 5.32 -22.96%
5 5.90 +11.01%
6 5.13 -13.09%
7 4.86 -5.33%
8 4.59 -5.50%

Wednesday, 18 March 2009

asynchia

Today I re-wrote the whole library I deleted yesterday. Here I present: asynchia. It's a minimalistic asynchronous network library (it has about 600 lines of code of which about 100 are LGPL-Headers) licensed under the, you guess, GNU LGPL.

I hope you like it and am open for any constructive criticism.

What I learned from deleting: Always use a SCM and always push to a remote location. Plus, commit pretty often so you do not lose so much if you accidentally delete anything.

Monday, 16 March 2009

Always use SCM

... from the beginning on, or you will learn it the hard way.

I did.

I wrote, and deleted, a async networking library today. Hooray!