Differences
This shows you the differences between two versions of the page.
software:matlab [2017-09-07 16:51] – created sraskar | software:matlab [2017-09-07 16:55] (current) – removed sraskar | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Using Matlab ====== | ||
- | MATLAB® is a high-level language and interactive environment for numerical computation, | ||
- | |||
- | **Details by clusters** | ||
- | * [[software: | ||
- | * [[software: | ||
- | |||
- | See [[software: | ||
- | |||
- | ====== License information ====== | ||
- | |||
- | MATLAB is product licensed by Mathworks. | ||
- | |||
- | The Mathworks R2013b and newer license server is being queried every 6 minutes on each cluster for available seats licensed for Matlab, Simulink and associated toolboxes. | ||
- | |||
- | < | ||
- | qhost -h global -F | ||
- | </ | ||
- | |||
- | to list number of unused license seats for each product. | ||
- | |||
- | Below is an example representing a snapshot of unused licensed seats for Matlab products on the cluster. | ||
- | < | ||
- | [traine@mills ~]$ qhost -h global -F | ||
- | HOSTNAME | ||
- | ------------------------------------------------------------------------------- | ||
- | global | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | gc: | ||
- | </ | ||
- | |||
- | Matlab jobs can be submitted to require a certain number of license seats to be available before a job will run. If there are inter-license dependencies for toolboxes, then you should specify all the licenses including Matlab and/or Simulink. | ||
- | |||
- | For example, if a Matlab job requires the Financial toolbox, then you will also need to specify all the inter-related toolbox licenses required by the Financial toolbox such as the Statistics and Optimization toolboxes as well Matlab itself. See [[http:// | ||
- | ]] for complete details. | ||
- | |||
- | < | ||
- | qsub -l MLM.MATLAB=1, | ||
- | </ | ||
- | |||
- | Naturally, this isn't a to-the-moment mapping because the license server is not being queried constantly. | ||
- | |||
- | This will be most helpful when submitting many Matlab jobs that require a toolbox with a low-seat count. They will wait for a toolbox seat to become available rather than trying to run and having many getting the " | ||
- | |||
- | ====== Project directory ====== | ||
- | |||
- | MATLAB is a language for scientific computing. | ||
- | |||
- | MATLAB has tools to help you make your project portable, and you should use them. For example, you should specify all files using | ||
- | [[http:// | ||
- | |||
- | <note tip> | ||
- | |||
- | Your preferences at | ||
- | |||
- | MATLAB -> General -> MAT-files | ||
- | |||
- | may have a older MAT-file save format selected as the default. | ||
- | |||
- | [[http:// | ||
- | </ | ||
- | |||
- | When you have a MATLAB job tested and debugged in a project directory, you are ready run on a cluster. | ||
- | |||
- | ===== Copy the project folder ===== | ||
- | |||
- | Copy the project folder to a directory on the cluster. | ||
- | Use any [[general: | ||
- | |||
- | ====== Batch job====== | ||
- | |||
- | Here are specific details for running MATLAB as an [[general: | ||
- | should have a copy of your MATLAB [[#project directory]] on the cluster. | ||
- | |||
- | <note important> | ||
- | |||
- | MATLAB has a new version twice a year. It is important to keep the version you use on your desktop the same as the | ||
- | one on the cluster. | ||
- | < | ||
- | vpkg_versions matlab | ||
- | </ | ||
- | will show you the versions available on a cluster. | ||
- | </ | ||
- | |||
- | <note tip> | ||
- | |||
- | It is frequently advisable to keep your MATLAB project clean from non-MATLAB files such as the queue | ||
- | script file and the script output file. But you may combine them, and even use the MATLAB editor to | ||
- | create the script file and look at the output file. | ||
- | If you create the file on a PC, take care to not [[general: | ||
- | |||
- | When you have one combined directory do not put the '' | ||
- | to the project directory with | ||
- | '' | ||
- | </ | ||
- | |||
- | |||
- | ===== Create a queue script file ===== | ||
- | You should create a queue script file to submit a batch job. Start by modifying a grid-engine template file, for example, to submit a serial job on one core of a compute node, copy the serial template. | ||
- | In your copy change the commented '' | ||
- | require MATLAB, and then add your shell commands to the end of the file. Your copy may contain the lines: | ||
- | < | ||
- | # Add vpkg_require commands after this line: | ||
- | vpkg_require matlab | ||
- | |||
- | # Now append all of your shell commands necessary to run your program | ||
- | # after this line: | ||
- | cd project_directory | ||
- | matlab -nodisplay -singleCompThread -r main_script | ||
- | </ | ||
- | The '' | ||
- | one line **'' | ||
- | |||
- | |||
- | <note tip> | ||
- | |||
- | You should include toolbox dependencies in your batch script. | ||
- | need to run the MATLAB script, and it will avoid a failure, which will occur if the job starts with no [[#license information|licenses]] available. | ||
- | |||
- | For example, to Bioinformatics toolbox only has one seat, and in addition it requires the Statistics and machine learning toolbox as well as the core MATLAB. | ||
- | < | ||
- | #$ -l MLM.MATLAB=1, | ||
- | </ | ||
- | |||
- | </ | ||
- | |||
- | For more examples, including examples that use multiple computational threads or the Parallel toolbox, see the [[#cluster details]] | ||
- | ===== Submit batch job ===== | ||
- | Your shell must be in a [[general: | ||
- | to submit any jobs. | ||
- | Use the '' | ||
- | and note the ''<< | ||
- | submit the job with: | ||
- | < | ||
- | qsub matlab_first.qs | ||
- | </ | ||
- | |||
- | <note important> | ||
- | |||
- | This is the message you get if you are not in workgroup. | ||
- | </ | ||
- | |||
- | <note warning> | ||
- | |||
- | It is true that a queue script file is (usually) a bash script, but it must be executed with the '' | ||
- | </ | ||
- | |||
- | ===== Wait for job to complete ===== | ||
- | You can [[general: | ||
- | For example, to list the information for job ''<< | ||
- | < | ||
- | qstat -j << | ||
- | </ | ||
- | |||
- | For long running jobs, you could change your queue script to notify you via an e-mail message when the job is | ||
- | complete. | ||
- | ===== Post process job ===== | ||
- | All MATLAB output data files will be in the project directory, but the MATLAB standard output will be in | ||
- | the current directory, from which you submitted the job. Look for a file ending in your assigned JOBID. | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ====== Interactive job ====== | ||
- | |||
- | Here are specific details for running MATLAB as an [[general: | ||
- | |||
- | ===== Command-line ===== | ||
- | |||
- | You should work on a compute node when in command-line MATLAB. | ||
- | Your shell must be in a [[general: | ||
- | to submit a single threaded interactive job using '' | ||
- | |||
- | < | ||
- | qlogin | ||
- | vpkg_require matlab | ||
- | cd project_directory | ||
- | matlab -nodesktop -singleCompThread | ||
- | </ | ||
- | |||
- | This will start a interactive command-line session in your terminal window. | ||
- | |||
- | ===== Desktop ===== | ||
- | |||
- | You should be on a compute node before you start MATLAB. | ||
- | To start a MATLAB desktop (GUI mode) on a cluster, you must be running an X11 server and you must have | ||
- | [[general: | ||
- | X11 tunneling]]. | ||
- | |||
- | Your shell must be in a [[general: | ||
- | to submit a job using '' | ||
- | |||
- | < | ||
- | qlogin -l exclusive=1 | ||
- | vpkg_require matlab | ||
- | cd project_directory | ||
- | matlab | ||
- | </ | ||
- | |||
- | This will start a interactive DESKTOP session on you X11 screen. | ||
- | |||
- | |||
- | See [[: | ||
- | |||
- | ====== Compiling with MATLAB ====== | ||
- | |||
- | We show the three most common ways to work with compilers when using MATLAB. | ||
- | |||
- | - Compiling your matlab code to run in the MCR (Matlab Compiler Runtime) | ||
- | - Compiling your C or Fortran program to call MATLAB engine. | ||
- | - Compiling your own function in C or Fortran to be used in a MATLAB session. | ||
- | |||
- | < | ||
- | < | ||
- | Warning: You are using gcc version ' | ||
- | with MEX is ' | ||
- | http:// | ||
- | </ | ||
- | But the compilation completes successfully. | ||
- | </ | ||
- | |||
- | ===== Compiling your MATLAB ===== | ||
- | |||
- | There is an example MCR project in the ''/ | ||
- | |||
- | ==== Copy dev-projects template ==== | ||
- | |||
- | On the head node | ||
- | < | ||
- | cp -r / | ||
- | cd MCR | ||
- | </ | ||
- | |||
- | ==== Compile with make ==== | ||
- | |||
- | Now compile on the compute node by using | ||
- | |||
- | < | ||
- | qlogin | ||
- | make | ||
- | </ | ||
- | |||
- | < | ||
- | </ | ||
- | |||
- | Resulting output from the make command: | ||
- | < | ||
- | Adding package `mcr/ | ||
- | make[1]: Entering directory `/ | ||
- | mcc -o maxEig -R " | ||
- | Compiler version: 5.2 (R2014b) | ||
- | Dependency analysis by REQUIREMENTS. | ||
- | Parsing file "/ | ||
- | (Referenced from: " | ||
- | Deleting 0 temporary MEX authorization files. | ||
- | Generating file "/ | ||
- | Generating file " | ||
- | make[1]: Leaving directory `/ | ||
- | </ | ||
- | Take note of the package added, and the files that are generated. | ||
- | You must add the package in your batch script or to test interactively. | ||
- | |||
- | ==== test interactively ==== | ||
- | |||
- | To test interactively on the same compute node. | ||
- | < | ||
- | vpkg_require mcr/ | ||
- | time ./maxEig 20.8 | ||
- | </ | ||
- | <note tip>This example is designed as a test for batch computing, and takes about 15 minutes to complete. If you | ||
- | change the MATLAB statement dim=10000 to dim=1000, and recompile, it will take about 10 seconds</ | ||
- | |||
- | ==== back to the head node ==== | ||
- | When done, exit the compute node. | ||
- | < | ||
- | exit | ||
- | </ | ||
- | |||
- | ==== Copy array job example ==== | ||
- | |||
- | < | ||
- | cp / | ||
- | vi matlab-mcr.qs | ||
- | diff / | ||
- | </ | ||
- | The '' | ||
- | < | ||
- | 46c46 | ||
- | < # -l m_mem_free=5G | ||
- | --- | ||
- | > #$ -l m_mem_free=3G | ||
- | 51c51 | ||
- | < # -t 1-4 | ||
- | --- | ||
- | > #$ -t 1-100 | ||
- | 63c63,64 | ||
- | < vpkg_require mcr/ | ||
- | --- | ||
- | > vpkg_require mcr/ | ||
- | > let lambda=" | ||
- | 79c80 | ||
- | < MCR_EXECUTABLE_FLAGS=(" | ||
- | --- | ||
- | > MCR_EXECUTABLE_FLAGS=(" | ||
- | </ | ||
- | To submit a standby array job that has 100 tasks. | ||
- | < | ||
- | qsub -l standby=1 matlab-mcr.qs | ||
- | </ | ||
- | |||
- | Example | ||
- | < | ||
- | [(it_css: | ||
- | Your job-array 627074.1-100: | ||
- | [(it_css: | ||
- | Mon Apr 11 14:56:26 EDT 2016 | ||
- | [(it_css: | ||
- | Mon Apr 11 15:17:33 EDT 2016 | ||
- | [(it_css: | ||
- | 100 | ||
- | </ | ||
- | There are 100 output files with the names matlab-mcr.qs.o627074.1 to matlab-mcr.qs.o627074.100 | ||
- | For example file 50: | ||
- | < | ||
- | [CGROUPS] UD Grid Engine cgroup setup commencing | ||
- | [CGROUPS] Setting 3221225472 bytes (vmem none bytes) on n106 (master) | ||
- | [CGROUPS] | ||
- | [CGROUPS] done. | ||
- | |||
- | Adding package `mcr/ | ||
- | GridEngine parameters: | ||
- | MCR_ROOT = / | ||
- | MCR executable = / | ||
- | flags = 49 | ||
- | MCR_CACHE_ROOT = / | ||
- | -- begin maxEig run -- | ||
- | |||
- | maxe = | ||
- | |||
- | | ||
- | |||
- | -- end maxEig run -- | ||
- | </ | ||
- | |||
- | |||
- | [[more examples]] | ||
- | |||
- | |||
- | ===== Compiling your code to use MATLAB engine ====== | ||
- | |||
- | There is an simple example function '' | ||
- | |||
- | On the head node and in a workgroup shell: | ||
- | |||
- | < | ||
- | vpkg_require matlab/ | ||
- | cp $MATLABROOT/ | ||
- | export LD_LIBRARY_PATH=$MATLABROOT/ | ||
- | mex -client engine fengdemo.F | ||
- | </ | ||
- | |||
- | To start MATLAB on a compute node to test this new program: | ||
- | |||
- | < | ||
- | qlogin | ||
- | vpkg_require matlab/ | ||
- | export LD_LIBRARY_PATH=$MATLABROOT/ | ||
- | ./fengdemo | ||
- | exit | ||
- | </ | ||
- | |||
- | Step one of the fengdemo should give the plot: | ||
- | |||
- | {{: | ||
- | |||
- | Step two should give the table: | ||
- | |||
- | < | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | </ | ||
- | |||
- | ===== Compiling your own MATLAB function ====== | ||
- | |||
- | There is an simple example function '' | ||
- | |||
- | On the head node and in a workgroup shell: | ||
- | |||
- | < | ||
- | vpkg_require matlab/ | ||
- | cp $MATLABROOT/ | ||
- | mex timestwo.c | ||
- | </ | ||
- | |||
- | To start MATLAB on a compute node to test this new function: | ||
- | |||
- | < | ||
- | qlogin | ||
- | vpkg_require matlab/ | ||
- | matlab -nodesktop | ||
- | timestwo(4) | ||
- | quit | ||
- | exit | ||
- | </ | ||
- | |||
- | You should get the answer | ||
- | |||
- | < | ||
- | >> timestwo(4) | ||
- | |||
- | ans = | ||
- | |||
- | 8 | ||
- | |||
- | >> | ||
- | </ | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ====== Parallel job ====== | ||
- | |||
- | You can use [[http:// | ||
- | There are three ways do this using the cluster scheduler and/or MATLAB toolboxes. | ||
- | |||
- | |||
- | ===== Array job ===== | ||
- | |||
- | Multiple, independent, | ||
- | |||
- | ===== Multiple computational threads ===== | ||
- | |||
- | MATLAB will detect you are on a multicore host and use all the cores it can to speed up its internal calculations. | ||
- | |||
- | ===== Parallel computing toolbox ===== | ||
- | |||
- | Using the [[http:// | ||
- | |||
- | |||
- | |||
- | |||
- | ====== Cluster details ====== | ||
- | **Using MATLAB details by cluster** | ||
- | * [[.matlab: | ||
- | * [[.matlab: |