Xman Blog Inside

Sunday, August 27, 2006

Concurrent BASH: Utilize your Dual-Core or Quad-Core processors

We can use batch command to send a series of tasks into a queue, and let it runs by itself. It monitors the load average and admit more tasks when it is low. However, the load average is not changing fast enough for many purposes. In addition, it lacks synchronization facility which is important when you want to make sure some concurrent operations complete before you proceed. Making it user-unfriendly, we have to write the script into a command stream for the batch command.

Hence, I'm trying to design a system to overcome problems as mentioned. Your BASH program can do like the following:
prun.bash:
#!/bin/bash
cd /tmp/xman
date
for i in *.ogg ; do
spawn oggdec *.ogg
done
synchronize
echo "Done"
date
exit 0

xman@sai xman $ time ./prun.bash
Sun Aug 27 21:44:13 SGT 2006
Done
Sun Aug 27 21:44:26 SGT 2006
real 0m13.279s
user 0m0.020s
sys 0m0.072s
Isnt that's cool? Multiple oggdec which decode ogg files will run in parallel on your dual-core or quad-core machine but with limited max number of threads at a time. The Dual-Core machine completes the decoding in merely 13.3s.

Now let me decode using serial script. The serial script:
xman@sai xman $ cat run
#!/bin/bash
date
for i in *.ogg ; do
oggdec "$i" &> /dev/null
done
echo "Done"
date
exit 0

xman@sai xman $ time ./run
Sun Aug 27 21:38:26 SGT 2006
Done
Sun Aug 27 21:38:46 SGT 2006
real 0m20.625s
user 0m19.273s
sys 0m1.004s
Serial script is unable to utilize two cores simultenously. Hence, it's important to use concurrent facility in order to fully utilize the processors that you are using.

Labels: ,

Sunday, August 20, 2006

Running slow using the Parallel version?

I recall that the Distributed Parallel Reversi, xversi-java-parallel-v0.8b, was able to achieve reasonable speedup when the level of evaluation is large enough. However, when I run it on my AMD Dual-Core machine, I realize the serial version, xversi-java-v0.7a, is much faster. :S (Jaw drops). I then went to check changes between the serial and parallel versions, what would cause this to happen? ...... after much struggling, I find that I'm using gcj package. Phew~~~~~ The serial version running on GCJ is reasonably fast, but the evaluation is extremely slow in the parallel version. I suppose, the RMI implementation in GCJ is causing delays. Finally, I simply install latest Java package from SUN, and it just runs fast. :) So, now I can increase the level of evaluation to improve the computer's reversi skill.
From my timing of the runs of computer vs computer, it took merely 30 seconds to 1 minute for the SUN Java to complete. However, it took more than 10 minutes for the GCJ Java to run. I dont know how long it will take, I just give up running. :p

Labels: , , , ,

Distributed Parallel Reversi in Java: You have Dual-Core? Quad-Core Processors?

Let's catch up with the technology trends on multi-core processors. If you have bought a dual-core, or quad-core, or a large shared memory parallel machine, or a cluster of computers, then you can run this Distributed Parallel Reversi, xversi-java-parallel-v0.8b.tgz, to make them busy.
Running Distributed Parallel Reversi: Step-by-step
  1. Launch a server in each of your machines that will provide reversi evaluation services.
    • xman@sai xversi-java-parallel-v0.8b # java -Djava.security.policy=xversi.policy XversiEval localhost 9394
      Registered XversiInterface
    • localhost: Machine name, or its IP.
    • 9394: Port number for the client to connect to. Remember to set your firewall to allow this port.
  2. Setup a machine info file called nodeinfo.txt.
    • xman@sai parallel # cat nodeinfo.txt
      2
      localhost:9394
      localhost:9394
    • 2: There are 2 entries about machine information.
    • localhost: Machine name or its IP. I include two identical lines because I'm running this on a dual-processor or dual-core processor machine. This will make the parallel reversi to utilize the two processors in the system.
  3. Launch the Java Applet.
    • xman@sai parallel # appletviewer -J-Djava.security.policy=xversi.policy test.html
      Number of Node : 2
      before lookup
      Node 0 localhost:9394
      name 0 //localhost:9394/xversiInterface
      Node 1 localhost:9394
      name 0 //localhost:9394/xversiInterface
      after lookup
    • I've forgotten how do you specify the policy to a browser to launch the Java applet. TELL ME IF YOU KNOW! ;)
Notice that in picture below, two processors in the system are running at full speed to evaluate different moves at the same time. :) Hence, if you bought a dual-core, quad-core, ... or even a cluster of computers, enjoy the benefit of parallel computing. :) Ideally it will run N times faster with N processors.

Click to see larger picture

Labels: , , , , , , , ,

Wednesday, August 16, 2006

Reversi in Java: The first presentable board game

I believe you'll not want to use command interface to play board game Reversi. Try this out, Reversi in Java xversi-java under GPL. The package includes both source codes and .class files. To play, simply extract files in the package and open the test.html using appletviewer or a browser with Java support. The implementation is lightweight, all the drawings are generated real-time, without using any picture files.
This had been further extended to use RMI (remote method invocation) to support parallel evaluation. However, it's troublesome to run and requires some security setting of the Java applet to be able to access host file. If you think it's interesting, stay tuned. :)

Labels: , , , , ,