Archive for the ‘Linux’ Category

November 20th, 2010

I thought I’d try out the new image capturing functionality in Mathematica 8 on my Linux based laptop with built in webcam but…

In[1]:= ImageCapture[]
During evaluation of In[1]:= ImageCapture::notsupported: Image acquisition is not supported on Unix. >>
Out[1]= ImageCapture[]

That makes me a sad panda!

November 13th, 2010

Christmas isn’t all that far away so I thought that it was high time that I wrote my Christmas list for mathematical software developers and vendors.  All I want for christmas is….

Mathematica

MATLAB

  • Merge the parallel computing toolbox with core MATLAB.  Everyone uses multicore these days but only a few can feel the full benefit in MATLAB.   The rest are essentially second class MATLAB citizens muddling by with a single core (most of the time)
  • Make the mex interface thread safe so I can more easily write parallel mex files

Maple

  • More CUDA accelerated functions please.  I was initially excited by your CUDA package but then discovered that it only accelerated one function (Matrix Multiply).  CUDA accelerated Random Number Generators would be nice along with fast Fourier transforms and a bit more linear algebra.

MathCAD

  • Release Mathcad Prime.
  • Mac and Linux versions of Mathcad.  Maple,Mathematica and MATLAB have versions for all 3 platforms so why don’t you?

NAG Library

  • Produce vector versions of functions like g01bk (poisson distribution function).  They might not be needed in Fortran or C code but your MATLAB toolbox desperately needs them
  • A Mac version of the MATLAB toolbox.  I’ve got users practically begging for it :)
  • A NAG version of the MATLAB gamfit command

Octave

SAGE Math

  • A Locator control for the interact function.  I still have a bounty outstanding for the person who implements this.
  • A fully featured, native windows version.  I know about the VM solution and it isn’t suitable for what I want to do (which is to deploy it on around 5000 University windows machines to introduce students to one of the best open source maths packages)

SMath Studio

  • An Android version please.  Don’t make it free – you deserve some money for this awesome Mathcad alternative.

SpaceTime Mathematics

  • The fact that you give the Windows version away for free is awesome but registration is a pain when you are dealing with mass deployment.  I’d love to deploy this to my University’s Windows desktop image but the per-machine registration requirement makes it difficult.  Most large developers who require registration usually come up with an alternative mechanism for enterprise-wide deployment.  You ask schools with more than 5 machines to link back to you.  I want tot put it on a few thousand machines and I would happily link back to you from several locations if you’ll help me with some sort of volume license.  I’ll also give internal (and external if anyone is interested) seminars at Manchester on why I think Spacetime is useful for teaching mathematics.  Finally, I’d encourage other UK University applications specialists to evaluate the software too.
  • An Android version please.

How about you?  What would you ask for Christmas from your favourite mathematical software developers?

September 2nd, 2010

I recently had a set of files that were named as follows

frame1.png
frame2.png
frame3.png
frame4.png
frame5.png
frame6.png
frame7.png
frame8.png
frame9.png
frame10.png

and so on, right up to frame750.png. The plan was to turn these .png files into an uncompressed movie using mencoder via the following command (original source)

mencoder mf://*.png -mf w=720:h=720:fps=25:type=png -ovc raw -oac copy -o output.avi

but I ended up with a movie that jumped all over the place since the frames were in an odd order. In the following order in fact

frame0.csv
frame100.csv
frame101.csv
frame102.csv
frame103.csv
frame104.csv
frame105.csv
frame106.csv
frame107.csv
frame108.csv
frame109.csv
frame10.csv
frame110.csv

This is because globbing expansion (the *.png bit) is alphabetical in bash rather than numerical.

One way to get the frames in the order that I want is to zero-pad them. In other words I replace file1.png with file001.png and file20.png with file020.png and so on. Here’s how to do that in bash

#!/bin/bash
num=`expr match "$1" '[^0-9]*\([0-9]\+\).*'`
paddednum=`printf "%03d" $num`
echo ${1/$num/$paddednum}

Save the above to a file called zeropad.sh and then do the following command to make it executable

chmod +x ./zeropad.sh

You can then use the zeropad.sh script as follows

./zeropad.sh frame1.png

which will return the result

frame001.png

All that remains is to use this script to rename all of the .png files in the current directory such that they are zeropadded.

for i in *.png;do mv $i `./zeropad.sh $i`; done

You may want to change the number of digits used in each filename from 3 to 5 (say). To do this just change %03d in zeropad.sh to %05d

Let me know if you find this useful or have an alternative solution you’d like to share (in another language maybe?)

July 7th, 2010

I was recently asked to install 32bit Gaussian 03 binaries on an Ubuntu 9.10 machine and when I tried to run a test job I got the following error message

Erroneous write during file extend. write -1 instead of 4096
Probably out of disk space.
Erroneous write during file extend. write -1 instead of 4096
Probably out of disk space.
Write error in NtrExt1
Write error in NtrExt1: Bad address
Segmentation fault

A bit of googling suggested that the following might work

sudo echo 0 > /proc/sys/kernel/randomize_va_space

but this will result in permission denied (explanation here). The command you really want to use is

sudo bash -c "echo 0 > /proc/sys/kernel/randomize_va_space"

Once this was done, Gaussian worked as advertised. Maybe this post will help a googler sometime in the future.

April 19th, 2010

I was recently playing with some parallel code that used gfortran and OpenMP to parallelise a calculation over 4 threads and was getting some seriously odd timing results.  The first time I ran the code it completed in 4.8 seconds, the next run took 4.8 seconds but the third run took 84 seconds (No, I haven’t missed off the decimal point).  Subsequent timings were all over the place – 12 seconds, 4.8 seconds again, 14 seconds….something weird was going on.

I wouldn’t mind but all of these calculations had exactly the same input/output and yet sometimes this parallel code took significantly longer to execute than the serial version.

On drilling down I discovered that two of the threads had 100% CPU utilisation and the other two only had 50%.  On a hunch I wondered if the CPU frequency ‘on demand’ scaling thing was messing things (It has done so in the past) up so I did

sudo cpufreq-selector -c 0 -f 3000
sudo cpufreq-selector -c 1 -f 3000
sudo cpufreq-selector -c 2 -f 3000
sudo cpufreq-selector -c 3 -f 3000

to set the cpu-frequency of all 4 cores to the maxium 3Ghz.  This switched off the ‘on demand’ setting that is standard in Ubuntu.

Lo! it worked! 4.8 seconds every time.  When I turned the governor back on

sudo cpufreq-selector --governor ondemand

I got back the ‘sometimes it’s fast, sometimes it’s slow’ behaviour. Oddly, one week and several reboots later I can’t get back the slow behaviour no matter what I set the governor to.

Perhaps this was just a temporary glitch in my system but, as I said earlier, I have seen this sort of behaviour before so, just to be on the safe side, it might be worth switching off the automatic governor whenever you do parallel calculations in Linux.

Does anyone have any insight into this? Comments welcomed.

December 3rd, 2009

The student version of MATLAB is a bargain since it only costs $99 (or less than £50 for those of us in the UK) and it comes complete with several toolboxes including symbolic maths, statistics and optimisation.  Most of it is identical to the full academic version which would cost well over a thousand pounds if you bought all of the toolboxes included in the student version.  The only place where it is ‘crippled’ is within Simulink since your Simulink models are limited to 1000 blocks.  There are one or two other differences too and I refer you to the amazon page for full details (Amazon is also the cheapest place I could find for Student MATLAB by the way).

One problem with the student version of MATLAB though is the fact that they only supply a 32 bit version.  This was potentially a big problem for a friend of mine since he has a 64bit Linux machine with 4Gb of RAM.  Fortunately, the 32bit version installs OK on 64bit Linux but the result is completely unsupported by Mathworks.  Fair enough….It works and he is (mostly) happy since he gets a lot of functionality for his money.

One thing that definitely didn’t work though was compiling mex files.  No matter how hard we tried we simply could not get it to work which made me look bad because I am supposed to be ‘The MATLAB guy’ around here.  Well, sometimes it’s not what you know but who you know that counts and I know a LOT of MATLAB users.  One of them has provided a fix but doesn’t want his name plastered all over Walking Randomly.  So, thanks to Mr Anonymous we got mex files working on Student MATLAB 2009a running on 64bit Linux and this is how we did it.

Get a simple mex file and try to compile it.  You’ll probably get this error.

/usr/bin/ld: cannot find -lmx

The way to get around that is to run the following command in MATLAB just before you try to compile a mex file

setenv('MATLAB_ARCH', 'glnx86')   (IN MATLAB)

That gets you a little further but you’ll next be hit by

/usr/bin/ld: cannot find -lstdc++

To fix this you need to find your mexopts.sh file and change the line

CLIBS="$CLIBS -lstdc++"

to

CLIBS="$CLIBS -L/home/paul/matlab/R2009a-student/sys/os/glnx86 -lstdc++"

obviously, you’ll need to change /home/paul/matlab to wherever you actually installed MATLAB.

Your next step is to do the following in a bash prompt

ln -s /home/paul/matlab/R2009a-student/sys/os/glnx86/libstdc++.so.6 \
/home/paul/matlab/R2009a-student/sys/os/glnx86/libstdc++.so

again – substituting wherever you installed MATLAB for /home/paul/matlab

Paul was running Ubuntu 9.04 and he got the following error at some point (I can’t remember where)

/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory

which was fixed by

sudo apt-get install libc6-dev-i386

That’s pretty much it. You should now be able to compile mex files. Hope this helps someone out there.

November 24th, 2009

One of the problems with the Linux MATLAB installer is that it doesn’t add any items to the menu in windows managers such as GNOME or KDE so you have to do it manually.  Now, there are several ways to do this but one of the easiest is to use the GUI tools provided with Ubuntu (assuming you are using Ubuntu of course).  For the record I am using Ubuntu 9.10 (Karmic Koala) with the default GNOME windows manager along with  MATLAB 2009b but I imagine that these instructions will work for a few other configurations too.

First things first, you’ll want to download a nice, scalable MATLAB icon since the ones included with MATLAB itself are a bit crude to say the least.  I tried to create one directly from MATLAB using the logo command and the Scalable Vector Graphics (SVG) Export of Figures package on The File Exchange but the result wasn’t very good (see below).

SVG preview

Fortunately someone called malte has created a much nicer .svg file (using inkscape) that looks just like the MATLAB logo and made it available via his blog.

Once you have the svg file you can start creating the shortcut as follows:

  • On the GNOME Desktop click on System->Preferences->Main Menu
  • Once the Main Menu program has started choose where you want your MATLAB icon to go and click on New Item.  In the screenshot below I have started to put it in the Programming submenu.

MATLAB GNOME integration 1

  • Give your shortcut a name and put matlab -desktop in the command field. If you didn’t create a shortcut to the matlab executable when you installed the program then you may need to put the full path in instead (i.e. something like /opt/MATLAB/2009b/bin/matlab )

MATLAB GNOME integration 2

  • Now let’s sort out the icon. Click on the spring on the left hand side of the above window to get the window below.

MATLAB GNOME integration 3

  • Click on Browse and then select the folder that contains the .svg file you downloaded from malte’s blog.  I put it in my Desktop folder for the screenshot below.  Note that the svg file doesn’t appear in the preview pane.  Click on Open.

MATLAB GNOME integration 4

  • Choose your icon.

MATLAB GNOME integration 5

  • Click on Close and you are done

MATLAB GNOME integration 6

If you are using the Student version of MATLAB then the process is slightly different and has been covered by my friend Paul Brabban over at CrossedStreams.com.

November 3rd, 2009

I’ve just installed Ubuntu version 9.10 (Karmic Koala) from scratch on my new work machine and noticed that you can no longer right click on a file to encrypt it. The functionality is still there – it just isn’t available by default. To get it just install the seahorse-plugins package as follows

sudo apt-get install seahorse-plugins

I did a reboot to get the changes to take but there is probably a less drastic way of getting the job done.

July 31st, 2009

It won’t be long before I give up Windows Mobile for good in favour of the HTC Hero and the Android operating system but before I do I thought I would take one last look at what’s out there in terms of mathematical software for the Windows Mobile platform.  I last looked at this back in early 2008 but one or two things have changed since then.

SMath running on Windows Mobile

SMath studio is a very nice free maths application that is being developed by Andrey Ivashov for Windows and Linux (via Mono) desktops  as well as Windows Mobile handhelds.  It installed perfectly on my HTC TyTn II and offers an experience very similar to a simplified version of PTC’s Mathcad and can even handle Mathcad’s .xmcd file format in some cases.  One cool feature to consider is that you can develop calculations on the desktop version (screen shot below) and then carry them around, edit and run them on your Windows Mobile phone (screenshot above).

SMath running on Linux

Andrey has recently released version 0.82 of the software and there are some active forums over at his website in both English and Russian where you can discuss it.  This software is well worth watching in my opinion.  Although I won’t be able to follow the Windows Mobile versions after next week, I’ll definitely be keeping an eye on SMath for Linux and Windows and hope to bring a more detailed review to you at some point in the future.

April 29th, 2009

OK, so with today’s release of Maple version 13, this blog post is a little late but I started so I’ll finish! My original install of Maple was 12.01 on Ubuntu Linux and a little while ago an update was released to take this to version 12.02.

Installation

In theory I should be able to install this automagically by clicking on Tools->Check for Updates inside Maple. However, when I did this I was told that ‘no updates were currently available‘ so I had to download the update manually from here. I was very pleased to note that this update was offered free of charge to all Maple 12 users. This is exactly as it should be and other software vendors should take note here – users don’t like paying for bug-fix updates! Well done to Maplesoft for doing it right. Once I had downloaded the 12.02 update installer, the installation itself was pretty straightforward. The following incantations did the trick for me

chmod +x ./Maple1202Linux32Upgrade.bin
sudo ./Maple1202Linux32Upgrade.bin

A graphical installer fired up and all I had to do was click Next a couple of times and point it to my Maple 12.01 installation. A few seconds later it was all over.  It’s a shame that the automatic checker didn’t work but all in all this was a very painless experience!

Now since this update only increments the version number by 0.01 you shouldn’t be expecting any marvellous new features.  What you should be expecting is some tidying up and bug fixing and that is exactly what you get.  Maplesoft’s own description of the bug-fixes weren’t detailed enough for my tastes and so I appealed to my informants at Maplesoft for something more explicit.

Happily, they delivered and most of what follows is from them.  Thanks Maplesoft :)

Since 12.02 was released along with the launch of MapleSim, many of the updates were geared towards symbolic manipulation and simplification, which is always beneficial for any advanced computations, but very important for MapleSim. As such, the best examples to illustrate the updates are in MapleSim, and are not easily shown with a Maple example alone. More specifically though, there were other enhancements and fixes that were added to Maple 12.02 to help improve it, which are not tied directly to MapleSim:

Updates to dsolve

There were two significant issues present in Maple 12.01 and earlier that are not present in Maple 12.02. One of these deals with a certain class of singularities that are transparent to explicit rk-pair based numerical solvers.

As the simplest example in this class, the differential system:

dsys := {diff(x(t),t)=x(t)/(1-t),x(0)=1};

having the exact solution:

dsolve(dsys);

has a singularity at t=1, and exactly ‘0’ error according to explicit rk-pair error estimation.

This, and other related singularities (such as jump discontinuities) are now detected to provide an accurate numerical solution. Compare this output from 12.01

dsn := dsolve(dsys, numeric);
 dsn := proc(x_rkf45)  ...  end proc
dsn(0.999);
[t = .999, x(t) = -48.3295522342053872]
dsn(1.001);
[t = 1.001, x(t) = -48.4646844943701609]

with the improved output from 12.02

dsn := dsolve(dsys, numeric);
 dsn := proc(x_rkf45)  ...  end proc
dsn(0.999);
 [t = 0.999, x(t) = 1000.00023834227034]
dsn(1.001);
Error, (in dsn) cannot evaluate the solution further right of
.99999999, probably a singularity

The second fix deals with error control on index-1 (non-differential) variables in the problem. This can be seen if you take a trivial problem coupled with a non-trivial index-1 variable. For example: In Maple 12.01:

dsys := {diff(x(t),t)=1, y(t)=sin(t), x(0)=0}:
 dsn := dsolve(dsys, numeric):
 dsn(Pi);

[t = 3.14159265358979, x(t) = 3.14159265358978956,
     y(t) = -0.00206731654642018647]

dsn(2*Pi);

[t = 6.28318530717958, x(t) = 6.28318530717958357,
     y(t) = -0.0623375491269087187]

The ‘y’ value should have been zero. In Maple 12.02:

dsys := {diff(x(t),t)=1, y(t)=sin(t), x(0)=0}:
 dsn := dsolve(dsys, numeric):
 dsn(Pi);

[t = 3.14159265358979, x(t) = 3.14159265358978956,
     y(t) = -0.117631599366556372 10^-6  ]

dsn(2*Pi);

[t = 6.28318530717958, x(t) = 6.28318530717958090,
     y(t) = -0.130170125786817359 10^-6  ]

which is zero within the default error tolerances.

Plot Annotations bug fix

In 12.01, some plot annotations were not appearing as expected. When a text box was entered on a 2D plot, the text would not appear until focus was taken away from the text box itself. For example, if you were to create a plot of sin(x) plot(sin(x)) and then click on the plot, select drawing from the toolbar and then select ‘T’ to enter a text field, you could begin typing, but would not receive visual feedback of what you entered until you clicked outside of the textbox. Obviously, this was a bug, and it was fixed in 12.02.

Improvements to embedded components

Prior to 12.02, some installations of Linux displayed some issues with redrawing of various embedded components, which slowed down scrolling in a Maple document. In 12.02, Maplesoft added a few fixes to the way that they handle embedded components, especially for 32-bit systems, which took care of this issue for most Linux installations. Also, since they were in the area, they took the opportunity to tweak response times for embedded components when creating them and executing the code that dictates their behavior in a document. This is not *very* noticeable when you have just a few components in a document, but it becomes very visible with Maplesoft’s interactive ebooks and with user applications that rely on a large number of components in a single application.

Excel Link improvements

In Maple, there is a built-in link to Microsoft Excel, so that you can perform Maple computations within an Excel spreadsheet. Maplesoft started supporting Excel 2007 in Maple 12, but with a service pack release to Windows released shortly thereafter and some security enhancements added to Maple, the link did not perform as expected in 12.01. Certain values were being interpreted incorrectly, as such, Maplesoft felt that they needed to address these inconsistencies as soon as possible. So for 12.02, they fixed the link for Excel 2007 to ensure that values were faithfully being passed from Microsoft Excel to Maple, in order to maintain the connection and computation accuracy.