.. _matlab: | :Last modified: |today| | MATLAB ====== Software availability ---------------------- to list Matlab versions, open a terminal window on the neuro cluster, and type 'matlab' followed by the tab key (twice), e.g.:: matlab Compatibility ------------- There is a known problem displaying Java applications (including Matlab) remotely on Mac computers with the M1 chip. The screen will appear black while the mouse focus is on the Matlab window. As a work-around, open a terminal window on the neuro cluster, and run the following commands:: cd cat << END > java.opts -Dsun.java2d.xrender=false END This will create a file called 'java.opts' in your home directory. Now you may run Matlab from your home directory and the screen will appear normal. For example:: cd matlab-2021a If you prefer to run Matlab from a different directory, then copy the java.opts file to that directory. Graphics -------- If you experience poor graphics rendering, e.g. the screen doesn't refresh leaving a 'ghosting' appearance, then you may use a graphics processor to improve graphics performance. To use a graphics processor, preface the 'matlab' command with a 'g'. This may degrade overall performance and/or cause session errors, so use cautiously. An example is below:: $ gmatlab-2010b SPM --- The following MATLAB/SPM command shortcuts are available for your convenience: | matlab-spm2 | matlab-spm5 | matlab-spm8 To determine the specific MATLAB version used by a shortcut, run the 'ls' command followed by the path to the shortcut from a :ref:`terminal window `, e.g. :: ls -l `which matlab-spm2` Toolboxes --------- Toolboxes are located in /usr/local/matlab-tools. To request a toolbox, please email support-neuro@berkeley.edu. Additional documentation is provided below: | `marsbar `_ | `snpm (versions 3 and 5b) `_ | `wfu_toolboxes `_ | `mrDiffusion `_ | `spm2DespoBasic `_ .. disabled since IST offered unlimited license. to uncomment, remove the '..', and move the following line to the beginning of the line: **MATLAB Licences** A MATLAB license is 'in use' until the matlab application is closed. To monitor license usage, use the 'lmstat' command. The lmstat command displays who has each license checked out, where they checked it out, and when they checked it out. :: lmstat -a You may see a license error while using MATLAB, e.g.: | License checkout failed. | License Manager Error -4 | Maximum number of users for X Toolbox reached. This error indicates that all toolbox licenses were issued. You may contact support-neuro@berkeley.edu, or use the lmstat command to identify unused licenses (search for earliest issue date, and ask the owner to close the unused MATLAB session). .. _matlab_install: PC Installation --------------- You may be authorized to run MATLAB on a personal computer for free. For more information, email me at support-neuro@berkeley.edu. Alternativey, use the `IST MATLAB FAQ `_ to see if you qualify, and to request a license. .. You may download MATLAB software from the Neuro cluster via :ref:`sftp` or :ref:`scp`: .. | /usr/local/matlab-source/Mac_UNIX .. | /usr/local/matlab-source/Windows .. You may install a matlab license file directly on your computer, or use a network license file. Both options are described below. .. **Network license** .. Please read the `Installation Instructions `_ from Mathworks. An internet connection is required to install, and use MATLAB with the network license. .. * :ref:`Installation Key` .. * :download:`license.dat file` .. **Local license** .. Since January 2012, UC Berkeley provides campus-wide access to MATLAB. A local license allows you to use MATLAB without an internet connection. .. #. Send email to software@berkeley.edu (from your @berkeley.edu email address). .. * Request a Designated Computer (also called 'Group') MATLAB license .. * Specify the operating system of your computer .. * Include the MAC address of your computer .. #. Create a Mathworks account at http://www.mathworks.com with your @berkeley email address. Specify the license is for "academic use". .. #. When logged into your Mathworks account, associate your account with the campus license using "add license" and entering the key when prompted for it. .. #. Open MATLAB. In the help menu choose "activate account", choose "activate with internet connection", enter your Mathworks account details, and enter the activation key. .. _matlab_performance: .. Parallel Computing .. ------------------ .. We use the MATALAB distributed computing server (MDCS) to run jobs in parallel, across all nodes in the Neuro cluster. Below are instructions to configure your MATLAB client to use MDCS (only version 2012b is supported): .. #. Log into the cluster via :ref:`SSH` or :ref:`NX`: .. #. Open a :ref:`terminal window`. At the shell prompt, make a directory for MATLAB to store state information:: .. mkdir ~/.matlab-mdcs .. #. At the shell prompt, start matlab without a graphical display:: .. matlab -nodisplay .. #. Configure MATLAB to use the MDCS. These commands should only be run once:: .. >> HWNI=parallel.importProfile('/usr/local/matlab-tools/HWNI'); >> parallel.defaultClusterProfile(HWNI); .. .. #. Specify how many jobs you want to run in parallel. We currently have a limit of 40, so you may specify between 1-40 parallel streams:: .. >> matlabpool 8 .. #. Run your matlab script or code. The simplest way to execute code in parallel is with MATLAB's 'parfor' command. parfor is a modified for loop, instructing MATLAB to run the for loop in parallel. For example:: .. >> parfor x = 1 : 1000 .. y = rand(1000) .. end .. #. We have limited licenses, so It's essential (ESSENTIAL) that you free the MATLAB licenses so others can run their code. For this reason, I recommend writing a script to execute your code, and always (ALWAYS) include the following line at the end:: .. >> matlabpool close .. For more information about MATLAB parallel computing, see: .. | http://www.mathworks.com/help/distcomp/matlabpool.html .. | http://www.mathworks.com/help/distcomp/parfor.html .. ... also check the :ref:`UC Berkeley MATLAB seminars schedule` and/or watch a `parallel computing video tutorial `_.