Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MATLABStan with parfor #30

Open
Peshkin opened this issue Apr 10, 2017 · 4 comments
Open

MATLABStan with parfor #30

Peshkin opened this issue Apr 10, 2017 · 4 comments
Assignees

Comments

@Peshkin
Copy link

Peshkin commented Apr 10, 2017

I am failing to get MATLAB Stan to run with parallelized loop "parfor" ...
Things work with regular "for", work with parfor when workers pool is not started (meaning the parser swallows the syntax and types variables, etc), but as soon as I turn on the worker's pool it breaks with the following error.

Not sure yet what caused exact error I mention below, but there are seem to be a few issues with StanModel.m which would prevent multi-worker execution with "parfor" in MATLAB, since
fname = fullfile(self.working_dir,'temp.data.R');
fname = fullfile(self.working_dir,'temp.init.R');
always saves temporary data into the same file, overwriting it across workers
same issue is hidden someplace with the sample_file which would be by default
output-1.csv
same for all workers.

Also "cores" option does not seem to have been made available within MATLAB.

THANK YOU

 -Leon

ERROR:
Error using StanModel/set.control (line 600)
Too many input arguments.

Error in StanModel/set (line 293)
self.control = p.Results.control;

Error in StanModel/sampling (line 709)
self.set(varargin{:});

Error in P3v2parfor>(parfor body) (line 90)
fit = model.sampling( 'data', peps_dat, 'iter', P.BTnum, 'warmup', round(.1
* P.BTnum), 'chains', P.numChains) ;

Error in P3v2parfor (line 82)
parfor nd =1:NndxActual % parfor % process multi-peptide proteins

@brian-lau
Copy link
Owner

Can you post some skeletal code of what you are trying to do with parfor? Running the same model on different data sets?

I'm not sure what 'cores' option you are referring to. Can you clarify?

@Peshkin
Copy link
Author

Peshkin commented May 17, 2017

'cores' as in Rstan manual for example:
"cores: Number of cores to use when executing the chains in parallel, which defaults to
1 but we recommend setting the mc.cores option to be as many processors as the hardware and RAM allow (up to the number of chains)"

@Peshkin
Copy link
Author

Peshkin commented May 17, 2017

Do you in turn have any sample code of successful parfor use with Stan ?
given what I mention about use of the same file name 'temp.data.R" I do not see how
different threads would not interfere with one another ...

@brian-lau
Copy link
Owner

Each chain gets run in parallel as a separate process. I haven't found any way to control how these processes get distributed to different processors/cores, but I've observed that they tend to get distributed to however many cores you have available.

I understand your point about the filenames, and I'll add a unique tag to prevent the overwriting.

@brian-lau brian-lau self-assigned this Jun 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants