41 | | In order to submit MATLAB jobs to Cypress from your laptop/desktop, you need to install a custom Matlab plugin scripts that are configured to interact with the Slurm job scheduler on Cypress. Use the links below to download the script package. |
42 | | |
| 41 | In order to submit MATLAB jobs to Cypress from your laptop/desktop, you need to install a custom Matlab plugin scripts that are configured to interact with the Slurm job scheduler on Cypress. Use the link below to download the script package to your laptop/desktop. |
| 42 | |
| 43 | [https://wiki.hpc.tulane.edu/trac/attachment/wiki/Matlab-Slurm/TU.nonshared.R2021a.zip TU.nonshared.R2021a.zip] |
| 44 | |
| 45 | Download the archive file and start MATLAB. The archive file should be unzipped in the location returned by calling |
| 46 | |
| 47 | {{{ |
| 48 | >> userpath |
| 49 | }}} |
| 50 | |
| 51 | See [https://www.mathworks.com/help/matlab/ref/userpath.html here] to view or change default user work folder on MATLAB. |
| 52 | |
| 53 | ==== Run the configCluster.m Script to Create a Cluster Profile ==== |
| 54 | Configure MATLAB to run parallel jobs on your cluster by calling '''configCluster'''. This only needs to be called '''once''' per version of MATLAB. |
| 55 | |
| 56 | {{{ |
| 57 | >> configCluster |
| 58 | }}} |
| 59 | |
| 60 | Submission to the Cypress requires SSH credentials. You will be prompted for your ssh username and password or identity file (private key). The username and location of the private key will be stored in MATLAB for future sessions. |
| 61 | |
| 62 | |
| 63 | == Configuring Jobs == |
| 64 | Prior to submitting the job, we can specify various parameters to pass to our jobs, such as queue, e-mail, walltime, etc. |
| 65 | |
| 66 | {{{ |
| 67 | >> % Get a handle to the cluster |
| 68 | >> c = parcluster; |
| 69 | }}} |
| 70 | |
| 71 | === Optional === |
| 72 | {{{ |
| 73 | >> % Specify an account to use for MATLAB jobs |
| 74 | >> c.AdditionalProperties.AccountName = 'account-name'; |
| 75 | }}} |
| 76 | |
| 77 | {{{ |
| 78 | >> % Specify e-mail address to receive notifications about your job |
| 79 | >> c.AdditionalProperties.EmailAddress = 'user-id@tulane.edu'; |
| 80 | }}} |
| 81 | |
| 82 | {{{ |
| 83 | >> % Specify Debug mode |
| 84 | >> c.AdditionalProperties.EnableDebug = 'false'; |
| 85 | }}} |
| 86 | |
| 87 | {{{ |
| 88 | >> % Specify memory to use for MATLAB jobs, per core (MB) |
| 89 | >> c.AdditionalProperties.MemUsage = '4000'; |
| 90 | }}} |
| 91 | |
| 92 | {{{ |
| 93 | >> % Specify processors per node |
| 94 | >> c.AdditionalProperties.ProcsPerNode = '2'; |
| 95 | }}} |
| 96 | |
| 97 | {{{ |
| 98 | >> % Specify Quality of Service |
| 99 | >> c.AdditionalProperties.QoS = 'qos-value'; |
| 100 | }}} |
| 101 | |
| 102 | {{{ |
| 103 | >> % Specify a queue to use for MATLAB jobs |
| 104 | >> c.AdditionalProperties.QueueName = 'queue-name'; |
| 105 | }}} |
| 106 | |
| 107 | {{{ |
| 108 | >> % Specify the walltime (e.g. 5 hours) |
| 109 | >> c.AdditionalProperties.WallTime = '05:00:00'; |
| 110 | }}} |
| 111 | |
| 112 | Save changes after modifying !AdditionalProperties for the above changes to persist between MATLAB sessions. |
| 113 | {{{ |
| 114 | >> c.saveProfile |
| 115 | }}} |
| 116 | |
| 117 | To see the values of the current configuration options, display !AdditionalProperties. |
| 118 | {{{ |
| 119 | >> % To view current properties |
| 120 | >> c.AdditionalProperties |
| 121 | }}} |
| 122 | |
| 123 | |
| 124 | Unset a value when no longer needed. |
| 125 | {{{ |
| 126 | >> % Turn off email notifications |
| 127 | >> c.AdditionalProperties.EmailAddress = ''; |
| 128 | >> c.saveProfile |
| 129 | }}} |
| 130 | |
| 131 | |
| 132 | == INTERACTIVE JOBS - MATLAB client on Cypress == |
| 133 | To run an interactive pool job on the cluster, continue to use parpool as you’ve done before. |
| 134 | {{{ |
| 135 | >> % Get a handle to the cluster |
| 136 | >> c = parcluster; |
| 137 | }}} |
| 138 | {{{ |
| 139 | >> % Open a pool of 64 workers on the cluster |
| 140 | >> p = c.parpool(64); |
| 141 | }}} |
| 142 | Rather than running local on the local machine, the pool can now run across multiple nodes on the cluster. |
| 143 | {{{ |
| 144 | >> % Run a parfor over 1000 iterations |
| 145 | >> parfor idx = 1:1000 |
| 146 | a(idx) = … |
| 147 | end |
| 148 | }}} |
| 149 | Once we’re done with the pool, delete it. |
| 150 | {{{ |
| 151 | >> % Delete the pool |
| 152 | >> p.delete |
| 153 | }}} |
| 154 | |
| 155 | == INDEPENDENT BATCH JOB == |
| 156 | Use the batch command to submit asynchronous jobs to the cluster. The batch command will return a job object which is used to access the output of the submitted job. See the MATLAB documentation for more help on batch. |
| 157 | {{{ |
| 158 | >> % Get a handle to the cluster |
| 159 | >> c = parcluster; |
| 160 | }}} |
| 161 | {{{ |
| 162 | >> % Submit job to query where MATLAB is running on the cluster |
| 163 | >> j = c.batch(@pwd, 1, {}, … |
| 164 | 'CurrentFolder','.', 'AutoAddClientPath',false); |
| 165 | }}} |
| 166 | {{{ |
| 167 | >> % Query job for state |
| 168 | >> j.State |
| 169 | }}} |
| 170 | {{{ |
| 171 | >> % If state is finished, fetch the results |
| 172 | >> j.fetchOutputs{:} |
| 173 | }}} |
| 174 | {{{ |
| 175 | >> % Delete the job after results are no longer needed |
| 176 | >> j.delete |
| 177 | }}} |
| 178 | To retrieve a list of currently running or completed jobs, call parcluster to retrieve the cluster object. The cluster object stores an array of jobs that were run, are running, or are queued to run. This allows us to fetch the results of completed jobs. Retrieve and view the list of jobs as shown below. |
| 179 | {{{ |
| 180 | >> c = parcluster; |
| 181 | >> jobs = c.Jobs; |
| 182 | }}} |
| 183 | Once we’ve identified the job we want, we can retrieve the results as we’ve done previously. |
| 184 | fetchOutputs is used to retrieve function output arguments; if calling batch with a script, use load instead. Data that has been written to files on the cluster needs be retrieved directly from the file system (e.g. via ftp). |
| 185 | To view results of a previously completed job: |
| 186 | {{{ |
| 187 | >> % Get a handle to the job with ID 2 |
| 188 | >> j2 = c.Jobs(2); |
| 189 | }}} |
| 190 | NOTE: You can view a list of your jobs, as well as their IDs, using the above c.Jobs command. |
| 191 | {{{ |
| 192 | >> % Fetch results for job with ID 2 |
| 193 | >> j2.fetchOutputs{:} |
| 194 | }}} |
| 195 | |
| 196 | == PARALLEL BATCH JOB == |
| 197 | Users can also submit parallel workflows with the batch command. Let’s use the following example for a parallel job, which is saved as {{{parallel_example.m}}}. |
| 198 | |
| 199 | {{{ |
| 200 | function t = parallel_example(iter) |
| 201 | |
| 202 | if nargin==0, iter = 8; end |
| 203 | |
| 204 | disp('Start sim') |
| 205 | |
| 206 | t0 = tic; |
| 207 | parfor idx = 1:iter |
| 208 | A(idx) = idx; |
| 209 | pause(2) |
| 210 | end |
| 211 | t = toc(t0); |
| 212 | |
| 213 | disp('Sim Completed') |
| 214 | }}} |
| 215 | |
| 216 | This time when we use the batch command, to run a parallel job, we’ll also specify a MATLAB Pool. |
| 217 | {{{ |
| 218 | >> % Get a handle to the cluster |
| 219 | >> c = parcluster; |
| 220 | }}} |
| 221 | {{{ |
| 222 | >> % Submit a batch pool job using 4 workers for 16 simulations |
| 223 | >> j = c.batch(@parallel_example, 1, {16}, 'Pool',4, … |
| 224 | 'CurrentFolder','.', 'AutoAddClientPath',false); |
| 225 | }}} |
| 226 | {{{ |
| 227 | >> % View current job status |
| 228 | >> j.State |
| 229 | }}} |
| 230 | {{{ |
| 231 | >> % Fetch the results after a finished state is retrieved |
| 232 | >> j.fetchOutputs{:} |
| 233 | ans = |
| 234 | 8.8872 |
| 235 | }}} |
| 236 | The job ran in 8.89 seconds using four workers. Note that these jobs will always request N+1 CPU cores, since one worker is required to manage the batch job and pool of workers. For example, a job that needs eight workers will consume nine CPU cores. |
| 237 | We’ll run the same simulation but increase the Pool size. This time, to retrieve the results later, we’ll keep track of the job ID. |
| 238 | NOTE: For some applications, there will be a diminishing return when allocating too many workers, as the overhead may exceed computation time. |
| 239 | {{{ |
| 240 | >> % Get a handle to the cluster |
| 241 | >> c = parcluster; |
| 242 | }}} |
| 243 | {{{ |
| 244 | >> % Submit a batch pool job using 8 workers for 16 simulations |
| 245 | >> j = c.batch(@parallel_example, 1, {16}, 'Pool', 8, … |
| 246 | 'CurrentFolder','.', 'AutoAddClientPath',false); |
| 247 | }}} |
| 248 | {{{ |
| 249 | >> % Get the job ID |
| 250 | >> id = j.ID |
| 251 | id = |
| 252 | 4 |
| 253 | }}} |
| 254 | {{{ |
| 255 | >> % Clear j from workspace (as though we quit MATLAB) |
| 256 | >> clear j |
| 257 | }}} |
| 258 | |
| 259 | Once we have a handle to the cluster, we’ll call the findJob method to search for the job with the specified job ID. |
| 260 | {{{ |
| 261 | >> % Get a handle to the cluster |
| 262 | >> c = parcluster; |
| 263 | }}} |
| 264 | {{{ |
| 265 | >> % Find the old job |
| 266 | >> j = c.findJob('ID', 4); |
| 267 | }}} |
| 268 | {{{ |
| 269 | >> % Retrieve the state of the job |
| 270 | >> j.State |
| 271 | ans = |
| 272 | finished |
| 273 | }}} |
| 274 | {{{ |
| 275 | >> % Fetch the results |
| 276 | >> j.fetchOutputs{:}; |
| 277 | ans = |
| 278 | 4.7270 |
| 279 | }}} |
| 280 | The job now runs in 4.73 seconds using eight workers. Run code with different number of workers to determine the ideal number to use. |
| 281 | Alternatively, to retrieve job results via a graphical user interface, use the Job Monitor (Parallel > Monitor Jobs). |
| 282 | |
| 283 | == DEBUGGING == |
| 284 | If a serial job produces an error, call the getDebugLog method to view the error log file. When submitting independent jobs, with multiple tasks, specify the task number. |
| 285 | {{{ |
| 286 | >> c.getDebugLog(j.Tasks(3)) |
| 287 | }}} |
| 288 | For Pool jobs, only specify the job object. |
| 289 | {{{ |
| 290 | >> c.getDebugLog(j) |
| 291 | }}} |
| 292 | When troubleshooting a job, the cluster admin may request the scheduler ID of the job. This can be derived by calling schedID |
| 293 | {{{ |
| 294 | >> schedID(j) |
| 295 | ans = |
| 296 | 25539 |
| 297 | }}} |
| 298 | |
| 299 | |
| 300 | == TO LEARN MORE == |
| 301 | To learn more about the MATLAB Parallel Computing Toolbox, check out these resources: |
| 302 | * [http://www.mathworks.com/products/parallel-computing/code-examples.html Parallel Computing Coding Examples] |
| 303 | * [http://www.mathworks.com/help/distcomp/index.html Parallel Computing Documentation] |
| 304 | * [http://www.mathworks.com/products/parallel-computing/index.html Parallel Computing Overview] |
| 305 | * [http://www.mathworks.com/products/parallel-computing/tutorials.html Parallel Computing Tutorials] |
| 306 | * [http://www.mathworks.com/products/parallel-computing/videos.html Parallel Computing Videos] |
| 307 | * [http://www.mathworks.com/products/parallel-computing/webinars.html Parallel Computing Webinars] |
| 308 | |