Skip to content

Latest commit

 

History

History
183 lines (136 loc) · 4.57 KB

matlab_singularity.md

File metadata and controls

183 lines (136 loc) · 4.57 KB

Installing Matlab Inside a Singularity Image and Formatting Figure Output

Overview

This guide describes how to download and install a full matlab instance inside a singularity image.

Steps

Start Docker

This will allow forwarding of x server so gui will appear. Note this may be specific to centos

sudo docker run -it --privileged --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" centos:6.8

Get Matlab ISO

cd /tmp
yum install -y wget
wget --user=USER --password=PASSWORD https://sds.vuse.vanderbilt.edu/SDS-SSL/MATLAB/R2017a/unix/R2017a_glnxa64_dvd1.iso && wget --user=USER --password=PASSWORD https://sds.vuse.vanderbilt.edu/SDS-SSL/MATLAB/R2017a/unix/R2017a_glnxa64_dvd2.iso

Mount ISO

Install utilites for mount command

yum install -y util-linux-ng

Mount matlab iso

mkdir matlab
mount -t iso9660 -o loop R2017a_glnxa64_dvd1.iso /tmp/matlab/

Install Matlab

First install libraries which make gui work (note gedit must contain a lot of dependencies to make gui applications work)

yum install -y dejavu-lgc-sans-fonts gedit libXt

This fixes some X issue

dbus-uuidgen > /var/lib/dbus/machine-id

Install

sh matlab/install

Hit “ctrl+z” to background the installer. Unmount first dvd.

umount /tmp/matlab/

Mount second one

mount -t iso9660 -o loop R2017a_glnxa64_dvd2.iso /tmp/matlab/

Type “fg” to bring stopped job to foreground. Then hit continue. Activate matlab. Test out matlab.

matlab

Remove isos when finishes

rm -f R2017a_glnxa64_dvd*.iso

Unmount iso

umount /tmp/matlab/

Clear command history

history -c

DO NOT EXIT CONTAINER UNTIL IT HAS BEEN COMMITTED OR ALL CHANGES WILL BE LOST!!!

Docker Stuff

  • Open another terminal and find out the CONTAINER ID. Hopefully you only have a single centos:6.8 container running, then it will be easy to find
  • Commit the docker container
sudo docker commit
  • Push to docker hub
sudo docker login
sudo docker push
  • This might take a little bit of time… also the docker container becomes “frozen” during this time
  • Also note you can run this matlab directly on another machine if you spoof the mac addres with the –mac-address option in docker run

Singularity

  • We want to be able to run this on the cluster with singularity. In order to do this we will need to use the cluster license
  • First, convert the docker container to a singularity container. I had to run this as root for some reason. It may also take a while…
sudo -i
mkdir /tmp/centos_with_matlab
cd /tmp/centos_with_matlab
export SINGULARITY_DOCKER_USERNAME=
export SINGULARITY_DOCKER_PASSWORD=
singularity -vvv build --writable centos_with_matlab.simg docker:DOCKER IMAGE TAG

Cluster Usage

  • Copy over to cluster – might take a little bit, its ~20 gigs
scp centos_with_matlab.simg USER@HOST:DIRECTORY
  • Test on cluster
ssh @
ml GCC Singularity
singularity shell /tmp/centos_with_matlab.simg
Singularity centos_with_matlab.simg:~> matlab -c
  • Hopefully matlab should start

Other Processes

Possibly Better Solution

https://github.com/baxpr/connprep

One Way of Doing Matlab+SPM Spiders

https://github.com/baxpr/example-spm-singularity-spider

Linux Docker to Create Matlab Singularity Containers

This option is probably only useful to OSX users: https://github.com/baxpr/mcrsing-docker

Matlab Figure Output on ACCRE

A couple of tips to make figures come out right when generated by Matlab on ACCRE. This is a starting point and could be wrong.

Settings in the .fig File

For the figure itself

  • 'Units', 'inches'
  • 'Position', [0.5 0.5 7.5 10] (For US letter in guide)
  • 'PaperPosition', [0.5 0.5 7.5 10] (Critical for correct size when printing. Again, this for US letter)

For axes, text boxes, etc

  • 'Units', 'normalized' So they will resize appropriately on screen
  • 'Font', 'default' Probably helps avoid resizing issues
  • 'FontUnits', 'normalized' Avoids resizing issues. Size is specified relative to height of parent axes/text box so it takes some fiddling to get right.

Settings at Runtime

% Figure out screen size
ss = get(0,'screensize');
ssw = ss(3);
ssh = ss(4);
ratio = 8.5/11;  % Width/height ratio. Should match the position settings described above
if ssw/ssh >= ratio
        dh = ssh;
        dw = ssh * ratio;
else
        dw = ssw;
        dh = ssw / ratio;
end

f = openfig('figure_file.fig','new');

% Fit the figure on the screen. Change units to pixels - if we leave at inches, we have memory trouble.
set(f,'Units','pixels','Position',[0 0 dw dh]);