Archive for computer science

Open sourcing old shit

I just made public under the terms of the GPLv3 a couple of old university projects hoping they will damn help someone. Here they are: ufs (micro file system, a fat-alike user space file system with some unix extensions) and Vespasiano (small movie theater manager, done when learning sockets in Java).

Please note that they both are so bugged to be broken. Be careful :-).

Comments

AMD backs OpenCL

Maybe you didn’t notice but AMD is now pushing the OpenCL standard. This is a really great news, the first step to a common GPGPU technology: who on Earth would want force himself to write the same program for three different architectures ?

Comments (2)

VMware Workstation 6.5 beta test drive

Let’s face it: when a Linux user wants to chill out for a little bit and play for a few minutes there is a good chance that the game he likes doesn’t like Linux at all. There is a very small number of commercial games working natively on Linux and making other Windows games run on top of Wine or Cedega isn’t straightforward everytime (especially if you try to run new games) so unless you really like FPSes like Quake, Unreal Tournament (up to the 2004 version) or the free Nexuiz or some other small game like SuperTux or TuxRacer you would probably want to try something else.

Before VMware Workstation 6.5 there were only two ways to do this: a gaming console or a dual boot with both Linux and Windows. Buying a console is too much for someone like me who doesn’t play more than 3 hours in a month and rebooting could really piss you off as it forces you to reset your working environment (unless you configure something like suspension to disk, but that’s quite another story).

This is where the new VMware come into play as it has a really working DirectX accelerated virtualization layer, I download and tested the version 6.5.0 build-110068 and found it to be quite stable on my computer with an NVIDIA 9600GT, an Intel Core2 Quad Q6600 clocked at 3.0Ghz and 2GB of RAM.

Of course don’t expect to get native hardware performances but the results are actually above my expectations, the major bottleneck is the low amount of RAM assigned to the virtual machine: please note that with only my 2GB I had to run my host operating system (x86_64 Debian Sid) and VMware itselft (which uses RAM other than the one assigned to the virtual machine) so in the end I was unable to assign more than 900MB to the guest Windows XP. This is the main reason behind the bad performances that you will see on the Unreal Tournament 3 test video, if you look carefully you will notice that it runs smoothly in complex scenes and then it suddently freezes: that’s where it has to swap data because of the low amount of RAM.

So, here we go, here the interesting part is…

OGRE 3D demos:

Unreal Tournament 3 (keep in mind the low RAM thing explained above):

Various screenshot in this gallery:

If you liked it why don’t digg it?

Comments (2)

What I don’t like in Ruby

I’m beginning to learn the well hyped Ruby language, in many ways it looks useful, elegant and pleasant, still it has something that, at least at a first glance, looks odd to me. I will use this post to take track of those odd things that I will meet when studying the language.

So, here we go:

1) Ends, take a look on this snippet:

if !r.nil? then
  rr = r.right
  if !rr.nil? then
    if ((r.color == RedBlackTree::RED)and(rr.color == RedBlackTree::RED)) then
      x = rot_left()
      copy(x) unless x.nil?
      @color = RedBlackTree::BLACK
      l = @left
      l.color = RedBlackTree::RED unless l.nil?
    end
  end
end

and here comes the Python equivalent:

if (right != None):
    rr = right.__right
    if (rr != None):
        if ((right.__color == RedBlackTree.red)and(rr.__color == RedBlackTree.red)):
            x = self.__rotLeft()
            if (x != None):
                self.__copy(x)
            self.__color = RedBlackTree.black
            left = self.__left
            if (left != None):
                left.__color = RedBlackTree.red

The Python way looks just the best way in my opinion. What’s the reason for the ends when you’ll indent the code anyway (and if you don’t then you deserve nothing else than suffering and pain)? Even the { C/C++/Java approach } appears way better or at least less intrusive.

2) “Fuzzy” expressions terminators. Try to compile and execute the following C++ code:

#include <iostream>
using namespace std;

class Foo {
    public:
    void bar() {
        int x = 3;
        int y = 2;
        cout << x
        +y;
        cout << endl;
    }
};

int main() {
    Foo *f = new Foo;
    f->bar();
    delete(f);
    return 0;
}

What do you expect it to print? Right, it will correctly print 5. Now Ruby’s turn:

class Foo
  def bar
    x,y = 3,2
    puts x
    +y
  end
end

f = Foo.new()
f.bar

Now what output do you expect? The answer is 3. This is because Ruby doesn’t use semicolons as C, C++, Java, PHP and many other languages do to terminate statements. It is still the better way to go, semicolons are redundants useless things almost everytime, still you have to pay attention: note that the above Ruby code isn’t wrong so the interpreter will not warn you, it will just print 3 instead of 5 and the method bar will return the value 2 (remember that in Ruby the last expression in a method or function is the actual return value of it so if you replace f.bar with puts f.bar it will print the “missing” 2).

3) No method overloading. The following code is self-explanatory:

class Foo
    def bar(a, b)
        puts b
    end
    
    def bar(a)
        puts a
    end
end

gh = Foo.new()
gh.bar("hello", "world")

if you try to execute it then you will get something like this:

asd.rb:12:in `bar’: wrong number of arguments (2 for 1) (ArgumentError)
from asd.rb:12

4) GIL (global interpreter lock). To me it’s nothing else than an alternative reading for “fake threading”. If you are on a multicore/multicpu system try to execute this snippet while monitoring the cpu activity, it will start 8 threads and compute fibonacci(40) on each thread:

class Fibonacci
    def fib(i)
        if (i <= 2)
            return 1
        else
            return fib(i - 1) + fib(i - 2)
        end
    end
end

threads = []
8.times { |i| threads[i] = Thread.new {Fibonacci.new().fib(30) } }
threads.each {|t| t.join}

If you come from C/C++ or Java you may expect this code to use up to 8 cores/cpus on your system at the same time… wrong! It will execute the code using only one core/cpu at once because the GIL prevents the threads from taking control of the interpreter at the same time. Cool, isn’t it?

5) Method invocation hooking. The following is the best way I found to intercept whenever a method is called:

class Foo
  def bar1(gh1)
    puts "bar1 #{gh1}"
  end
end

class Foo
  def bar1_hook(*args)
    puts "bar1 hooked!"
    bar1_asd(args)
  end

  alias_method(:bar1_asd, :bar1)
  alias_method(:bar1, :bar1_hook)
end

a = Foo.new
a.bar1("foobar")

So bar1 is the method to be hooked: you have to monkey patch the Foo class defining the hooking method and hack it all together with alias_method. Doing this you are ripping the original class apart: if someone will edit the bar1 method after your hook he/she will actually be editing the bar1_hook method without even noticing it (well, he will notice the unexpected behaviour and maybe try to debug his/her own code… have fun :-|), I really hope to be wrong about this point…

Comments

Khronos to standardize GPGPU, evaluting OpenCL

I was almost going to miss this press release from the Khronos Group (the industrial group behind standards like OpenGL), looks like they are finally getting serious with general purpose computing on GPUs with the launch of a working group to create open standards for it. This group is going to include names like AMD, Apple, ARM, Freescale, IBM, Intel, Nokia, NVIDIA and many others so we can expect something really big coming out of it. Apple has already proposed OpenCL, maybe it won’t take so long before we can put our hands on a cross platform GPGPU tool.

Comments