0

I am using Matlab R2011b version on Windows 7 64 bit, Core i7 CPU with 8 GB RAM. I am running Approximate Nearest Neighbor algorithm called the Locality Sensitive Hashing using Matlabpool. Upon starting Matlab pool, I get the output

Starting matlabpool using the 'local' configuration ... connected to 4 labs.

When the control reaches the for loop, Matlab throws errro

Error using parallel_function (line 598)

Out of memory. Type HELP MEMORY for your options.

Error stack:
remoteParallelFunction.m at 29

Error in Evaluate (line 19)
parfor i=1:query_num

I have no clue how to solve this problem. Please help. Thank you

Sm1
  • 560
  • 2
  • 6
  • 24
  • The error message is very clear, you ran out of memory. Did you try using `for` instead of `parfor`? Using the parallel computing toolbox requires more memory because the data is copied to the workers. – Daniel Feb 09 '16 at 18:45
  • 2
    [Saving time and memory using `parfor`](http://stackoverflow.com/questions/32146555/saving-time-and-memory-using-parfor-in-matlab/32146700#32146700) should contain all the information you need about the memory working of `parfor` – Adriaan Feb 12 '16 at 16:06

1 Answers1

2

That is because the parfor requires a lot more memory.

All the workers/labs in a parfor loop are independent so each of them needs his amount of memory. Also, there is overhead involved due to the fact that the pool must spread and collect data from/to the workers.

Try using a regular for or open a pool with 2 workers instead of 4.

Also, it depends on how optimized your some_function() is: try using as few variables as possible.

dgoverde
  • 110
  • 2
  • 15
AlessioX
  • 3,167
  • 6
  • 24
  • 40
  • Thank you for your answer, the program runs without error after I replaced the parfor with the for loop. But this leads to another Question which is if there is any need to use matlabpool now that parfor is not being used? Or there is no relation between the usage of parfor and matlabpool ? – Sm1 Feb 11 '16 at 02:22
  • 1
    The matlabpool (or parpool) should be triggered when there are parallel commands such as MapReduce or Parfor or you use genetic algorithms which have a flag true/false if you want them parallelized (and many other cases). You can open the matlabpool without having parallel executions...but that's just silly. You waste computational time by opening the pool and not using it – AlessioX Feb 11 '16 at 09:03