How to set prefdir for parpool workers?
    10 views (last 30 days)
  
       Show older comments
    
    Geoffrey Aguirre
 on 16 Jul 2017
  
    
    
    
    
    Answered: Faiz Gouri
    
 on 21 Jul 2017
            I am running parpool jobs with 10 workers under 2016b on my Mac (Mac Pro “Twelve Core”; 3.06 GHz 6 Core Xeon X5675 x2).
Initial jobs run without error. Over time, however, workers begin to fail with the error:
Error using prefutils>loadPrefs (line 42)
    Unable to read MAT-file /Users/myname/Library/Application
    Support/MathWorks/MATLAB/R2016b/matlabprefs.mat. File might be corrupt.
After some searching, I found these links. They advise changing the Matlab prefdir prior to starting a parpool job so as to avoid write conflicts within the prefs file:
This advice, however, seems to regard the situation in which multiple parpools are running concurrently.
More generally, I am unable to determine how I would arrange for each worker in a parpool to start with its own, separate prefdir, and if this is even needed to fix the error that I am encountering.
Thanks for any help.
0 Comments
Accepted Answer
  Faiz Gouri
    
 on 21 Jul 2017
        This error occurs when multiple MATLAB workers attempt to access the matlabprefs.mat file simultaneously. Here is a sample code to reproduce this issue:
function parTest
    if matlabpool('size')==0
      matlabpool('open');
    end
    parfor i=1:10
      pause(randn(1));
      setpref('parTest','test','test');
    end %parfor
  end %function parTest
To avoid this problem, set preferences using "pctRunOnAll" , before the parfor loop.
function parTest
    if matlabpool('size')==0
      matlabpool('open');
    end
    pctRunOnAll setpref('parTest','test','test');
    parfor i=1:10
      ...parfor statements go here...
    end
end %function parTest
Alternatively, the problem can be avoided by increasing the pause time from "pause(randn(1))" to "pause(randn(i/100))" , where 'i' is the parfor counter variable.
0 Comments
More Answers (0)
See Also
Categories
				Find more on Parallel Computing Fundamentals in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
