Hi Harish Ananthakrishnan,
I understand you want to monitor the number of active threads used by your MATLAB App.
Unfortunately, In MATLAB, monitoring threads explicitly within the MATLAB environment is not possible as MATLAB itself manages the thread pools and low level thread management is not exposed.
Though you cannot directly monitor the threads created and used by MATLAB when you run your application you can use system-level tools for this purpose.
You can follow the below steps to get a rough estimation on the number of threads being used for an active process.
- Close any active MATLAB sessions on your machine and execute this command to get a base line measure level of threads active in system.
- Open a single copy of MATLAB and repeat the following command to get the measurement. The difference in the count between step 2 and step 1 is the number of active threads of a single MATLAB client.
- Add the below line to the function of the MATLAB App to get the process ID.
- In the system terminal execute the below command to know the number of MATLAB App UI thread count.
- Once parpool is open repeat the following command to get the measurement.
- Add the below line to the parallel worker function.
- Choosing one of the process IDs displayed by the parallel workers after executing the function run the following command to get a measurement. Perform this step for all the pool workers
The output after executing the command in step 4 is the active thread count for MATLAB App and the combined sum of outputs after step 7 is the MATLAB worker thread count.
Thank You.