Switching to atlas

I was running some numpy code that uses blas under the hood. I realised that I had not installed an optimised version of blas so I started digging around.

My system is Antargos (Arch variant), and I had installed python-numpy which is the python3 version of numpy from the Arch official repos. I ran a test in ipython:

In [1]: import numpy as np

In [2]: %timeit np.dot(np.random.random((2000,2000)),np.random.random((2000,2000)))
1 loops, best of 3: 10.8 s per loop

Then I installed the atlas-lapack-base package, restarted Ipython and ran the same test:

In [2]: %timeit np.dot(np.random.random((2000,2000)),np.random.random((2000,2000)))
1 loops, best of 3: 2.66 s per loop

Very satisfying without any effort!


Linux Mint brightness control problems

I recently installed Linux Mint 17.1 and was reminded of a problem I believe I have noticed with previous versions of LM as well.

When I had the laptop connected to a monitor with HDMI cable, I noticed that if I unplugged the laptop, I lost the ability to control the brightness. I could dim the screen but I could not make it brighter.

What seems to have done the trick for me was from a forum thread at LM http://forums.linuxmint.com/viewtopic.php?f=49&t=142017

Changing the grub variable



GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_backlight=vendor acpi_osi=Linux"

Seems to have fixed this. There are other suggestions in the forum that is worth trying if the problem persists.

Just remember to:

sudo update-grub

Setting up Eclipse to compile and resolve C++11 syntax

To get your compiler to use the C++11 flag -std=c++11 and to get the Eclipse editor to recognize the C++11 syntax we need to change two settings in Eclipse.

To get Eclipse to recognize C++11 syntax in the editor for all future projects you do:

Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery

Here you select the CDT GCC Built-in Compiler Settings. You need to add to the text box -std=c++11. Hit OK.

If you already have a project that uses C++11 you need to select:

Project -> C/C++ Index -> Re-resolve Unresolved Includes

which should then recognize the C++11 syntax.

To get your compiler to compile C++11 features you should edit:

Project -> Properties -> C/C++ Build

Here I select [ All configurations ] in the Configuration drop down box so that the -std=c++11 flag is added to all build configurations. Select:

Settings -> GCC C++ Compiler -> Miscellaneous

Here I append “-std=c++11” (without the quotes) to the “Other flags” text box. Now the compiler uses the c++11 compiler option. Hit OK.

Interesting comparison of different accelerator pros and cons

During a workshop on GPGPU programming we got some overview of NVIDIA’s new Kepler GPU and Intel Xeon Phi Coprocessor technologies. I started wondering how we develop for different technologies (multicores, multi CPU’s vs GPU’s) and found an interesting blog post that cover in quite detail differences between the most common architectures and different techniques required to squeeze the most out of each one. From what I can gather, the OpenACC seems to currently be the best bet if you want to write programs for many current and future architecture. If you know your program will only run on certain hardware or you need to squeeze as much performance out as possible then other tools can offer better optimization, but they require deep knowledge of the tool and its possibilities (which is essential in such cases). But for us mere mortals who want to start experimenting with GPGPU programming I guess the OpenACC is a nice first step.

The article can be found here.

And now I just need to find a nice problem to start testing this out🙂


Installing VirtualBox on Linux Mint (Ubuntu 13.04)

I always have problems with this. I found a very nice blogpost that was very easy to follow and in my case very complete (http://aahank.com/2013/install-virtualbox-on-ubuntu/). All credit goes to http://aahank.com/.

I’ll summarise this for my own future installations of VirtualBox🙂

sudo apt-get update && sudo apt-get upgrade

sudo apt-get install linux-headers-$(uname -r)

sudo apt-get install dkms

Now we are ready to install VirtualBox. So go ahead and download the latest stable package for your Linux distribution here. Double click the downloaded .deb file and install as usual.

sudo usermod -aG vboxusers username

(Don’t forget to replace ‘username’ in the above command with yours.)

One last thing. You might also want to install the VirtualBox Extension Pack as it enables support for USB 2.0 devices, among a few others. You can download it here, and install then install it in two ways:

  • Double-click on the package file, and let the VirtualBox Manager guide you through the process.
  • Start Oracle VirtualBox from Ubuntu Dash, then go to File → Preferences, select Extensions tab in the settings window, and click Add package button.

Before you create a virtual machine, be sure to restart your PC.

Create a VM. Then start the VM, and installation of the operating system should begin. Once done, restart the VM, and when the guest OS is fully up, install VirtualBox Guest Additions by going to Devices → Install Guest Additions….

If the gui of the OS installed on a virtual machine is laggy, try disabling Hardware Virtualization.

Garmin Forerunner 410 on linux

Sports watches are poorly supported by their manufacturers regarding linux. After I started running I decided on a Garmin FR 410, since it was quite cheap and has all the functionality I wanted. I neglected to look up how it works under linux and for the first couple of months after I got it I had to boot up my XP in VM to transfer data to and from the watch.

Then I came across a nice python tool that made it possible to get data off the watch and upload it to Connect Garmin. The tool is called python_ant_downloader and you can find supported watch models on their github page. It is simple to install through pip (use sudo if needed):

user@host $ sudo pip install python_ant_downloader

Edit 3rd July 2014: If you use Anaconda for virtual python environments as I do, then you might be having issues with python module dbm not being installed when running the ant-downloader:

user@host $ ant-downloader
Traceback (most recent call last):
import dbm
ImportError: No module named dbm

If so, you can install it straight from github:

user@host $ sudo pip install git+git://github.com/braiden/python-ant-downloader.git

This gives you a terminal program called ant-downloader that can retrieve data from a connected garmin watch and upload it to garmin. First, I had a problem where my ant+ stick was not getting permissions to mount. In Ubuntu (and derived systems, and probably other distros as well) non-standard usb sticks are not allowed to mount automatically. Those devices follow permission rules that are present in /etc/udev/rules.d/. To generate a rule for our USB Ant+ stick we need to figure out the sticks ID:

user@host $ lsusb
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 003 Device 002: ID 0fcf:1008 Dynastream Innovations, Inc.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

In my case I identified my USB stick by running the command with it unplugged and then again plugged in. Here the Dynastream Innovation, Inc. is the stick and note the ID : 0fcf:1008. Now we generate a rule for that device:

user@host $ sudo echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="0fcf", ATTR{idProduct}=="1008", MODE="666"' > /etc/udev/rules.d/99-garmin.rules

user@host $ sudo bash -c "echo 'SUBSYSTEM==\"usb\", ATTR{idVendor}==\"0fcf\", ATTR{idProduct}==\"1008\", MODE=\"666\"' > /etc/udev/rules.d/99-garmin.rules"

Edit 3rd July 2014: On Arch based system (I’m using Manjaro at the moment) the command is a bit different:

user@host $ sudo bash -c "echo 'SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"0fcf\", ATTRS{idProduct}==\"1008\", MODE=\"666\"' > /etc/udev/rules.d/99-garmin.rules"

Note that the vendor and product attributes use their respective parts of the ID above. Saving this and plugin the USB again should allow you to run

user@host $ ant-downloader

The first time it runs, it generates configs and tries to pair with your watch. After that, you can edit the file ~/.antd/antd.cfg and add your connect.garmin details under the config [antd.connect] (and set enabled = True) for automatic upload to their server. Your workouts are also stored as .tcx files that you can upload to other servers than garmin, you find them in the folder ~/.antd/0xDEVICENR/tcx/ .

Hope this will be of use to someone🙂 Please let me know of any issues you find with this method.

Binni out.

Python virtualenv and virtualenvwrapper with scientific packages, the simple way

During a course on scientific programming in python, we were pointed to a nice linux script to get virtualenv and virtualenvwrapper installed with nice option for upgrading the environment in one command.
Virtualenv allows you to generate sandboxed python environment where you can experiment and install different python interpreters with their own packages that don’t interfere with your system python setup. This tutorial requires some packages and their respective development headers to be install with the root account. I have not had time to look into doing this with your regular account, which would be nice on a server where you are not given root access. But for now, to install:

user@host $ curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | $SHELL

This executes the shell script virtualenv-burrito.sh and sets up virtualenv and virtualenvwrapper for your local user. You should close and reopen terminal and see if virtualenvwrapper has been sourced. Test:

user@host $ mkvirtualenv -h

If it doesn’t work, fix your .bashrc, .bash_profile and .profile setup as suggested on the github link. Now:

user@host $ mkvirtualenv test

Now your prompt should look like:

(test) user@host $

Which indicates you are working in the test environment. You can leave that environment with the command deactivate, and you can enter the environment with workon:

(test) user@host $ deactivate
user@host $ workon test
(test) user@host $

In your new environment usually very few packages are installed after initialization. You can use pip to install new packages. Lets start with common system dependencies for some of the usual python packages and then use pip to install the python packages:

(test) user@host $ sudo apt-get install libblas3 libblas-dev liblapack3 liblapack-dev libfreetype6 libfreetype6-dev libpng12-dev libpng++-dev libzmq-dev gfortran gcc g++ python-qt4 python-dev build-essential
(test) user@host $ pip install numpy scipy matplotlib pandas scikit-learn biopython
(test) user@host $ pip install ipython[zmq,qtconsole,notebook,test] --upgrade

Given you have resolved all system dependencies. If this fails, install packages one by one and figure out what is missing. To test that the ipython notebook is working with matplotlib inline plotting, run this command:

(test) user@host $ ipython notebook --pylab=inline

and in the first cell do:


Which should put a plot in the notebook. To update the virtualenv and virtualenvwrapper, the script we installed provides a nice command to upgrade:

user@host $ virtualenv-burrito upgrade

Binni out!