You have the right idea. A couple of quick comments
- If you have a parallel pool running, then deleting the jobs will also delete the pool (a pool is a type of job). Therefore
is all you need.
- The "Cannot cancel or destroy a job that was not created by this Local cluster" is a known issue that I believe was resolved in R2022a.
The "cluster" (myCluster in your case) is a MATLAB object that contains properties of the cluster (e.g., number of workers, name of host, location of MATLAB, etc.) and methods that can operate on it (e.g, job launchers). There are two job launchers: parpool and batch. By and large, when using the local profile, you'll only call parpool (but you could in theory run batch jobs as well).
Therefore, there are two reasons you'd want to call parcluster.
- To override the default cluster
If you simply call
MATLAB will startup a pool of workers with a default pool size using your default profile. If you call
MATLAB will startup a pool of eight workers using your default profile (if using the local profile, setting the size is the most common reason to call parpool explicitly). If you call
MATLAB will startup a pool of 10 workers using the myCluster profile. As listed in your example, there's more arguments you can pass to parpool as well.
- [Optional] To set properties the job submitter will pickup to tweak your job submission.
Depending on the scheduler (and in particular 3rd party schedulers like Slurm and PBS), where MATLAB will submit your job, you can interject scheduler flags (e.g., walltime, queue name, etc.). Therefore, you might run something like
myCluster = parcluster('slurm');
myCluster.AdditionalSubmitArgs = '-p short';