Archive for the ‘Linux’ Category

August 19th, 2008

If you are interested in gadgets then you will almost certainly have heard of the Asus EEE ultra portable (and ultra cheap) range of laptops. I have yet to get my grubby hands on one but I know one or two people who have already taken the plunge and one of them wanted to install Mathematica on his Asus EEE 900.

“No problem” said I “but would you mind running the Mathematica benchamark on it for me when you’re done”

He duly did so and the results are in. For reference, he un-installed the version of Linux that comes with the EEE and put Fedora Core 9 on it instead before installing Mathematica 6.0.0. The specs of the machine are

  • 900Mhz Intel Celeron M
  • 1GB RAM
  • 20GB Solid State Drive

To run the Mathematica Benchmark you use the following commands

Needs[“Benchmarking`”]
BenchmarkReport[]

The overall result for the Asus EEE 900 was 0.43

To give you an idea of what this might mean – here are some other results (Higher is better)

  • quad-core 3.0GHz Intel Xeon (Linux 64bit) 3.67
  • 2.4 GHz Pentium 4 (windows) – 1.00
  • AMD 2400XP (32bit Linux) – 0.67

The full list of timings (in seconds) for the Asus EEE were (lower is better)

  • Total – 200.9 (a 2.4Ghz Pentium 4 gives a total of 100)
  • Test 1 – 5.15
  • Test 2 – 2.41
  • Test 3 – 3.10
  • Test 4 – 15.90
  • Test 5 – 18.20
  • Test 6 – 1.81
  • Test 7- 3.33
  • Test 8 – 10.30
  • Test 9 – 50.00
  • Test 10 – 5.06
  • Test 11 – 8.44
  • Test 12 – 7.35
  • Test 13 – 7.38
  • Test 14 – 27.20
  • Test 15 – 35.30

I’m not going to explain what each of these tests actually does because this is a post for current Mathematica users who are curious about Asus’ machines rather than a post about the benchmark itself.

If you enjoyed this article, feel free to click here to subscribe to my RSS Feed.

August 12th, 2008

For some reason my keyboard started acting all American today – giving me a @ instead of ” for example. I genuinely have no idea what I had done to cause it but to fix it I did

sudo xmodmap /usr/share/xmodmap/xmodmap.uk

July 16th, 2008

Someone came to visit me today with a MATLAB mex problem and, among other things, I needed to install gcc for them. Now on a Linux machine this would have been trivial. Something like

yum install gcc

or

apt-get install gcc

would do the trick, depending on which flavour of Linux you are using. One command, a quick download and you’re done. Couldn’t be simpler.

I am as green as grass when it comes to Mac usage and so I assumed that there would be some Mac equivalent to these commands but it seems that this is not the case (please please correct me if I am wrong). As far as I can tell, one needs to install something called Xcode in order to get gcc which is 1 Gigabyte in size. You heard me right – 1GB….for gcc! Of course it isn’t just gcc taking up that 1GB – you get lots of other gubbins too – but I don’t want all of the other gubbins. I just want gcc.

But the size isn’t the worst bit. It turns out that you have to go through a registration process in order to get your hands on XCode – giving Apple information such as your email address, home address, what area you work in, what you are going to use XCode for etc etc

All this to get hold of one of the most fundamental open-source applications there is. There has to be a better way. If anyone can enlighten me as to what that better way might be I would be very grateful.

April 14th, 2008

Abaqus is an extremely powerful finite element analysis (FEA) package that is used by various departments at my university and it is an application that I provide some of the support for among our users. I am far from being an expert at using it but I do know a trick or two and am occasionally useful. Recently, someone emailed me because they were having trouble actually getting Abaqus 6.6 installed on a 64 bit CENTOS 5 machine. He was located on the other side of campus from me, but it was a nice day and I felt like a walk so, rather than giving the support via email, I popped over to see him face to face. I am glad I did too – because it was a tricky one!

I am aware that this is not the sort of thing my usual readers might be interested in so I will keep it as brief as possible – basically what I want to do is provide myself with a permanent record of what we discovered and how we fixed it in case I come across this problem again. In an ideal world it might also help a googler or two (do let me know in the comments if it does – it will make my day)

So…we log on as root, run the installation script and get the following error

Extracting temporary installation utilities to /opt/temp…
Executing the installation GUI…
Preparing to install…
Extracting the installation resources from the installer archive…
Configuring the installer for this system’s environment…
awk: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/bin/ls: error while loading shared libraries: librt.so.1: cannot open shared object file: No such file or directory
basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
hostname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

Launching installer…
grep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/opt/temp/TEMP_ABAQUS_utils_root/jre/bin/java: error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file or directory

As far as I can tell the reason for this is that the installer cannot identify your shiny new kernel so it assumes that an old one is being used and THIS is where the problems start. The problem occurs in the script /cdrom/lnx86_64/product/UNIX/Disk1/InstData/NoVM/install.bin

Look inside this file and you will see 2 lines that contain

export LD_ASSUME_KERNEL

I commented these out by adding a # (after copying the installation cd to a writable filesystem of course):

#export LD_ASSUME_KERNEL

BIG mistake. I now had a shiny new error

Exception in thread "main" java.lang.NoClassDefFoundError: com/zerog/lax/LAX

After a bit of googling, I discovered this post which gave an explanation of the problem along with a solution. The important part is this:

“make sure any line you put a comment on, you either edit in overwrite mode, or you make sure you delete a character for every # sign you add”

I deleted the Tab character before each of the # I had added and the error went away but I could have saved myself the grief by NOT manually commenting out each instance of LD_ASSUME_KERNEL and just running the following sed command on install.bin instead

cat install.bin | sed “s/export LD_ASSUME_KERNEL/#xport LD_ASSUME_KERNEL/” > /tmp/install.bin

Once this was taken care of, the installation proceeded without complaint and I was pretty confident that I was going to be out in time to meet my friend for coffee but, alas, it was not to be. When I tested the install by running the abaqus cae I received the following error message

/opt/abaqus/6.6-1/exec/ABQcaeK.exe: /opt/abaqus/6.6-1/External/libgcc_s.so.1: version `GCC_4.2.0′ not found (required by /usr/lib64/libstdc++.so.6)

I was starting to contemplate writing some FEA code for him rather than continue with this install as I felt that it might have been easier but it turned out that all we need to do is change the name of a couple of files (original source here). Do the following at your shell prompt (assuming the default installation location):

cd /opt/abaqus/6.6-1/External
mv libgcc_s.so libgcc_s.so.BACKUP
mv libgcc_s.so.1 libgcc_s.so.1.BACKUP

Job done! Finally! As always, if anyone finds this useful then please let me know.

March 28th, 2008

Say you have just joined an applied-maths research group* where you are expected to write a lot of numerical simulations – numerical simulations that are going to require the use of big computers in large, air conditioned rooms with a great deal of impressive looking flashenlightenblinken. Naturally, you would like to use Python for all of your programming needs as you have recently fallen in love with it and you are convinced that it’s the future.

Your boss, Bob, completely disagrees with your take on the future of programming. He thinks that Python is a passing fad that will soon be forgotten. He sneeringly refers to it as a ‘ mere scripting language’ and constantly refers to you as the script kiddie. He thinks that Fortran is the only programming language worth bothering with when it comes to numerical simulations. According to Bob, Fortran is the past, present and future of computer programming – everything else is just mucking about.

You argue constantly with Bob concerning the relative merits of the two languages because, although you respect Fortran, you don’t think that it’s going to be much fun to use. Eventually he pulls out his trump card – “You can’t use Python in this group because all of our screamingly fast, highly accurate, tested and debugged numerical routines are written in Fortran. We won’t use any other libraries because these are the best so – give up on Python and start learning Fortran or get another job.”

Defeated…or so you thought…

After a bit of googling you realize that there is light at the end of the tunnel, this problem has been solved before by making use of the Python ctypes module. First of all let’s install this module on Ubuntu:

sudo apt-get install python-ctypes

Taking our cue from this solution lets say that one of the functions in the Fortran library is called ADD_II and has the following source code (filename add.f)

SUBROUTINE ADD_II(A,B)
INTEGER*4 A,B

A = A+B
END

Compile it into a shared library using gfortran as follows:

gfortran add.f -ffree-form -shared -o libadd.so

Now, create a file called add.py and copy the source code from our friendly usenet poster:

from ctypes import *
libadd = cdll.LoadLibrary(“./libadd.so”)
#
# ADD_II becomes ADD_II_
# in Python, C and C++
#
method = libadd.ADD_II_
x = c_int(47)
y = c_int(11)
print “x = %d, y = %d” % (x.value, y.value)
#
# The byref() is necessary since
# FORTRAN does references,
# and not values (like e.g. C)
#
method( byref(x), byref(y) )
print “x = %d, y = %d” % (x.value, y.value)

run the script as follows:

python add.py

and get the following error message:

AttributeError: ./libadd.so: undefined symbol: ADD_II_

So, despite what we may have thought, it looks like our function has not been given the name ADD_II_ in the shared library. So what name has it been given? We could just keep guessing what the compiler might have called it or we could just ask the library itself using the nm comand:

nm libadd.so

00001468 a _DYNAMIC
00001554 a _GLOBAL_OFFSET_TABLE_
w _Jv_RegisterClasses
00001458 d __CTOR_END__
00001454 d __CTOR_LIST__
00001460 d __DTOR_END__
0000145c d __DTOR_LIST__
00000450 r __FRAME_END__
00001464 d __JCR_END__
00001464 d __JCR_LIST__
00001570 A __bss_start
w __cxa_finalize@@GLIBC_2.1.3
00000400 t __do_global_ctors_aux
00000340 t __do_global_dtors_aux
00001568 d __dso_handle
w __gmon_start__
000003d7 t __i686.get_pc_thunk.bx
00001570 A _edata
00001574 A _end
00000434 T _fini
000002d8 T _init
000003dc T add_ii_
00001570 b completed.6030
000003a0 t frame_dummy
0000156c d p.6028

Now I have no idea what most of that output means but it looks like the .so file contains something called add_ii_ so if I use this instead of ADD_II_ in my python script I bet it will work.

python add.py

x = 47, y = 11
x = 58, y = 11

The sweet smell of success. You go to Bob and tell him that you have just come up with a test script that demonstrates that you are going to be able to use the group’s Fortran libraries in your Python scripts.

“That’s very nice” says Bob “but all of the really useful routines in the library make use of callback functions. Can you handle those yet?”

“yes I can” you reply smugly “but this post has gone on long enough so I’ll leave the details until another time”

*Note – In case you are my boss – I haven’t joined a research group so I won’t be quitting my job any day soon. I was just in a story telling mood. Oh..and this stuff will be useful for what we do – I promise!

March 10th, 2008

Mathematica 6.0.2 was released back on February 25th but I have only just managed to find the time to install it. I tried to install it on a brand new Dell 755 with a very fresh install of Ubuntu but near the end of the install procedure I came across the following error

“The installer was unable to check for a valid password file. Your Mathematica installation may be incomplete or corrupted.”

I had not been given the opportunity to supply it with any licensing information so it looked like there was a problem with the installer itself. Cutting a long story sort, the solution is to use apt to install the package libstdc++5 as follows

sudo apt-get install libstdc++5

This is a very common package and I guess that I have not seen this error before because libstdc++5 is automatically installed as a prerequisite for many other Ubuntu applications. Hopefully this little note will be of use to a googler or two.

Anyway…I now have 6.0.2 installed and running so expect a breakdown of the new features soon.

February 5th, 2008

Every now and then I like to play a video game or two and one I discovered recently is Secret Mayro Chronicles, an open source (ie free) game based on Nintendo’s classic Super Mario World. It has received some very positive reviews so I thought I would give it a try. A quick look through synaptic showed me that the game is included in the standard Ubuntu Linux (windows version repositories under the packages ‘smc’ and ‘smc-data’ so I installed them and went to play.

The first thing I noticed was that the game was not included in Gnome’s ‘games’ menu which is not uncommon in the world of Linux games. No problem – just open a terminal and run the command

smc

and you will be up and running…normally. Unfortunately it seems that the supporting libraries for the game were not packaged correctly so when you try and run the game you will get the following error

CEGUI::Exception: DynamicModule::DynamicModule – Failed to load module: ‘libCEGUIDevILImageCodec.so’:libCEGUIDevILImageCodec.so: cannot open shared object file: No such file or directory
CEGUI Exception occurred : DynamicModule::DynamicModule – Failed to load module ‘libCEGUIDevILImageCodec.so’: libCEGUIDevILImageCodec.so: cannot open shared obj

which looks a little scary. This can be fixed by running the following commands in a terminal just once.

cd /usr/lib
sudo ln -s libCEGUIDevILImageCodec.so.0 libCEGUIDevILImageCodec.so
sudo ln -s libCEGUIFalagardWRBase.so.1 libCEGUIFalagardWRBase.so
sudo ln -s libCEGUIXercesParser.so.0 libCEGUIXercesParser.so

All this does is set up a few symbolic links so that the game can find the files it needs. The game still won’t appear in the menu but it will run just fine from the terminal.

The version in the standard Ubuntu repositories is a little out of date but I have been playing it for the last half an hour or so and its great fun. You could go over to the games official website to get the latest version if you wish but I am happy to wait for it to be upgraded in the repositories.

If you have any children then I imagine that they would love this game and you really can’t beat it at the price. There is a windows version available too from the official site but I haven’t tried it so have no idea how it compares to the Linux version.

January 21st, 2008

I have a couple of perl projects that make use of the GD::Graph module and I needed to set them up on a new machine. I was expecting to install the module without any problems but I was wrong. With a live internet connection I started off by starting the CPAN shell by typing the following in a bash shell

sudo perl -MCPAN -e shell

Since it was the first time I had run this command on this particular machine I had to answer a lot of questions but simply selected the defaults for everything as this usually works for me. Once in the CPAN shell I entered

install Bundle::CPAN

and selected all of the defaults again. Once the CPAN bundle had finished installing I tried to install GD::Graph by typing

install GD::Graph

but it failed with hundreds of errors – the first of which was

GD.xs:7:16: error: gd.h: No such file or directory

This was fixed with the following apt-get command (in the bash shell)

sudo apt-get install libgd2-xpm-dev

back in the CPAN shell I still couldn’t get GD::Graph to build and I guessed this was because of some left over files from the failed build. I don’t know the command to clean things up inside the CPAN shell and am too lazy to read the docs so I simply went into the .cpan/build directory in my home directory and deleted anything that started with GD – eg

rm -rf GD-2.35-HC_vkB

rm -rf GDGraph-1.44-Evfibe

and so on. Those strings at the end (VkB and so on) look random so they might be different on your machine. Then I went back into the CPAN shell and ran

install GD::Graph

again. There were a few dependencies which the script fetched and installed for me but everything worked smoothly. With a bit of luck these notes will be of use to someone else out there – please let me know if this is the case.

December 31st, 2007

While catching up on some news items that I missed over the festive period I noticed that version 3.0 of Octave was released on December 21st 2007. For those of you who have never heard of it before, Octave is an open-source project that attempts to emulate much of the core functionality of Matlab – an extremely popular commercial mathematics application centered around linear algebra and numerical analysis. Octave has been around for some time now – version 1.0 was released back in 1994 so it is certainly not just a flash in the pan.

Octave aims to be source compatible with Matlab wherever possible which means that in many cases you can take code written for Matlab, feed it to octave and it will just work. As you might expect this compatibility is far from perfect but it is good enough for many purposes. Some core Matlab functions have not yet been implemented in Octave and there are also some syntactic differences between the programming languages of the two packages but in many situations the compatibility is quite good and I used it myself very successfully back in the days before I had access to Matlab. A more detailed discussion of Octave-Matlab compatibility can be found on the Octave website.

You can read about some of the changes made to Octave for the version 3.0 release over at Octave’s news page. One of the most interesting updates seems to be that Octave now has increased compatibilty with Matlab’s Handle graphics system. It’s been a while since I used Octave myself so I will be having a play with it on my daily commute over the next few weeks to see what I can see.

If you hit this page from google while looking for open-source Matlab alternatives you might also want to check out Scilab, Freemat and Sage.

November 6th, 2007

A user on comp.soft-sys.math.mathematica had a query about MD5 hashes in Mathematica that caught my attention recently. Now I was playing with MD5 in php a few days ago and one thing that I discovered was that the MD5 of a string seemed to vary depending on which program you used to generate it. For example if we use the unix command md5sum to hash the string ‘hello’ (Note the quotes are not part of the string) as follows

echo ‘hello’ | md5sum

we will get

b1946ac92492d2347c6235b4d2611184

All well and good but if we use the php md5 function to hash ‘hello’ (using the script here for example) then we get

5d41402abc4b2a76b9719d911017c592

Clearly different which was enough to annoy at least one person. It turns out that the reason for this is quite straightforward. The php function is returning the hash of the string ‘hello’ as required but the standard unix example is returning the hash of the string ‘hello\n’ where \n stands for a newline. Initially I thought this was interesting but then it hit me that the output of

echo ‘hello’

is in fact ‘hello\n’ so no one should have been surprised really. I would have quickly forgotten about this but someone was having a similar problem in Mathematica. In Mathematica strings are enclosed in double quotes so we hash the word hello as follows:

Hash[“hello”, “MD5”] // BaseForm[#, 16] &

5deaee1c1332199e5b5bc7c5e4f7f0c2

Which is completely different from our two cases above so what on earth is going on? Again, it turns out that the solution is, in fact, rather dull. It seems that Mathematica includes the enclosing double quotes when it produces the hash – which is not what I would expect at all. You can confirm this by running the string (including quotes) “hello” through the php md5 function.

I know its not exactly earth shattering stuff but I thought that I would write it up just in case someone else wondered about this stuff and was googling for it.