Search code examples
matlabtimeconsumingparticle-swarm

How to fully use the CPU in Matlab [Improving performance of a repetitive, time-consuming program]


I'm working on an adaptive and Fully automatic segmentation algorithm under varying light condition , the core of this algorithm uses Particle swarm Optimization(PSO) to tune the fuzzy system and believe me it's very time consuming :| for only 5 particles and 100 iterations I have to wait 2 to 3 hours ! and it's just processing one image from my data set containing over 100 photos !

I'm using matlab R2013 ,with a intel coer i7-2670Qm @ 2.2GHz //8.00GB RAM//64-bit operating system

the problem is : when starting the program it uses only 12%-16% of my CPU and only one core is working !!

I've searched a lot and came into matlabpool so I added this line to my code :

matlabpool open 8

now when I start the program the task manger shows 98% CPU usage, but it's just for a few seconds ! after that it came back to 12-13% CPU usage :|

Do you have any idea how can I get this code run faster ?!


Solution

  • 12 Percent sounds like Matlab is using only one Thread/Core and this one with with full load, which is normal.

    matlabpool open 8 is not enough, this simply opens workers. You have to use commands like parfor, to assign work to them.