Question

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 ?!

Was it helpful?

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.

OTHER TIPS

Further to Daniel's suggestion, ideally to apply PARFOR you'd find a time-consuming FOR loop in you algorithm where the iterations are independent and convert that to PARFOR. Generally, PARFOR works best when applied at the outermost level possible. It's also definitely worth using the MATLAB profiler to help you optimise your serial code before you start adding parallelism.

With my own simulations I find that I cannot recode them using Parfor, the for loops I have are too intertwined to take advantage of multiple cores.

HOWEVER:

You can open a second (and third, and fourth etc) instance of Matlab and tell this additional instance to run another job. Each instance of matlab open will use a different core. So if you have a quadcore, you can have 4 instances open and get 100% efficiency by running code in all 4.

So, I gained efficiency by having multiple instances of matlab open at the same time and running a job. My jobs took 8 to 27 hours at a time, and as one might imagine without liquid cooling I burnt out my cpu fan and had to replace it.

Also do look into optimizing your matlab code, I recently optimized my code and now it runs 40% faster.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top