4. Edit Launch Script

Here we will look at the script that actually launches MATLAB ~/ondemand/dev/bc_my_center_matlab/template/script.sh.erb.

By now you should have selected your preferred window manager. Examples of using XFCE, Mate, and Fluxbox:

Invoking MATLAB without a Window Manager

 1 cd "$HOME"
 2
 3 #
 4 # Start MATLAB
 5 #
 6
 7 # Load the required environment
 8 module load xalt/latest <%= context.version %>
 9
10 # Launch MATLAB
11 # Switch the implementation on if the user requested a visualization GPU node
12 <%- if context.node_type.include?("vis") -%>
13 module load intel/16.0.3 virtualgl  # Perform whatever set up you want / need
14 module list  # List loaded modules for debugging purposes
15 set -x
16 vglrun matlab -desktop -nosoftwareopengl  # Launch MATLAB using VirtualGL
17 <%- else -%>
18 # When not using a GPU node
19 module list  # List loaded modules for debugging purposes
20 set -x
21 matlab -desktop  # Launch MATLAB
22 <%- end -%>

Use XFCE for the Window Manager

XFCE is OSC's preferred desktop environment for launching VNC applications. The code for starting XFCE in the background looks like this (see highlighted lines 1-20):

 1  #
 2  # Launch Xfce Window Manager and Panel
 3  #
 4
 5  (
 6    export SEND_256_COLORS_TO_REMOTE=1
 7    # session.staged_root.join("config") refers to /.../bc_my_center_matlab/template/config
 8    # which is copied at job start time to a session specifc directory.
 9    # It will override without replacing any XFCE settings that the user
10    # already has.
11    export XDG_CONFIG_HOME="<%= session.staged_root.join("config") %>"
12    export XDG_DATA_HOME="<%= session.staged_root.join("share") %>"
13    export XDG_CACHE_HOME="$(mktemp -d)"
14    module restore
15    set -x
16    xfwm4 --compositor=off --daemon --sm-client-disable
17    xsetroot -solid "#D3D3D3"
18    xfsettingsd --sm-client-disable
19    xfce4-panel --sm-client-disable
20  ) &
21
22  cd "$HOME"
23
24  #
25  # Start MATLAB
26  #
27
28  # Load the required environment
29  module load xalt/latest <%= context.version %>
30
31  # Launch MATLAB
32  # Switch the implementation on if the user requested a visualization GPU node
33  <%- if context.node_type.include?("vis") -%>
34  module load intel/16.0.3 virtualgl  # Perform whatever set up you want / need
35  module list  # List loaded modules for debugging purposes
36  set -x
37  vglrun matlab -desktop -nosoftwareopengl  # Launch MATLAB using VirtualGL
38  <%- else -%>
39  # When not using a GPU node
40  module list  # List loaded modules for debugging purposes
41  set -x
42  matlab -desktop  # Launch MATLAB
43  <%- end -%>

Use Mate for the Window Manager

The code for starting Mate in the background looks like this (see highlighted lines 1-4):

 1  # Launch Mate Window Manager and Panel
 2  marco --no-composite --no-force-fullscreen --sm-disable &
 3  # mate-panel blocks, but does not work reliably when launched in the same subshell as marco
 4  mate-panel &
 5
 6  cd "$HOME"
 7
 8  #
 9  # Start MATLAB
10  #
11
12  # Load the required environment
13  module load xalt/latest <%= context.version %>
14
15  # Launch MATLAB
16  # Switch the implementation on if the user requested a visualization GPU node
17  <%- if context.node_type.include?("vis") -%>
18  module load intel/16.0.3 virtualgl  # Perform whatever set up you want / need
19  module list  # List loaded modules for debugging purposes
20  set -x
21  vglrun matlab -desktop -nosoftwareopengl  # Launch MATLAB using VirtualGL
22  <%- else -%>
23  # When not using a GPU node
24  module list  # List loaded modules for debugging purposes
25  set -x
26  matlab -desktop  # Launch MATLAB
27  <%- end -%>

Note

According to the developers the correct pronunciation of Mate is mah-tay like the drink, and not matey like pirates, or mate like a friend.

Use Fluxbox for the Window Manager

Warning

Fluxbox has been replaced by XFCE as OSC's preferred window manager / desktop environment.

The code for starting Fluxbox in the background looks like this (see highlighted lines 1-36):

 1  #
 2  # Launch Fluxbox
 3  #
 4
 5  FLUXBOX_RC_FILE="$(pwd)/fluxbox.rc"
 6  # Find an example of the Fluxbox assets at https://github.com/OSC/bc_osc_matlab/tree/bcff07264b318688c3f4272a9662b13477833373/template/fluxbox
 7  FLUXBOX_ASSETS_ROOT="<%= session.staged_root.join("fluxbox")%>"
 8
 9  # Create Fluxbox root or it will override the below init file
10  (
11    umask 077
12    mkdir -p "${HOME}/.fluxbox"
13  )
14
15  # Build Fluxbox init file
16  cat > "${FLUXBOX_RC_FILE}" << EOT
17  session.configVersion: 13
18  session.screen0.toolbar.widthPercent: 60
19  session.screen0.toolbar.tools: prevworkspace, workspacename, nextworkspace, iconbar, systemtray, prevwindow, nextwindow, clock
20  session.menuFile: $FLUXBOX_ASSETS_ROOT/menu
21  session.keyFile: $FLUXBOX_ASSETS_ROOT/keys
22  session.styleOverlay: $FLUXBOX_ASSETS_ROOT/overlay
23  EOT
24
25  # Export the module function for the terminal
26  [[ $(type -t module) == "function" ]] && export -f module
27
28  # Start the Fluxbox window manager (it likes to crash on occassion, make it
29  # persistent)
30  (
31    export FLUXBOX_ASSETS_ROOT="${FLUXBOX_ASSETS_ROOT}"
32    until fluxbox -display "${DISPLAY}.0" -rc "${FLUXBOX_RC_FILE}"; do
33      echo "Fluxbox crashed with exit code $?. Respawning..." >&2
34      sleep 1
35    done
36  ) &
37
38  cd "$HOME"
39
40  #
41  # Start MATLAB
42  #
43
44  # Load the required environment
45  module load xalt/latest <%= context.version %>
46
47  # Launch MATLAB
48  # Switch the implementation on if the user requested a visualization GPU node
49  <%- if context.node_type.include?("vis") -%>
50  module load intel/16.0.3 virtualgl  # Perform whatever set up you want / need
51  module list  # List loaded modules for debugging purposes
52  set -x
53  vglrun matlab -desktop -nosoftwareopengl  # Launch MATLAB using VirtualGL
54  <%- else -%>
55  # When not using a GPU node
56  module list  # List loaded modules for debugging purposes
57  set -x
58  matlab -desktop  # Launch MATLAB
59  <%- end -%>