I can replicate it too on OS X, R2012b. In mex
, mexPrintf
is not thread safe. See this. I wouldn't be surprised if Matlab's fprintf
relies on mexPrintf
- or similar code - under the hood. If you turn your script into a function - just put function parfortest
on the first line - the problem goes away, so it may also be a scoping issue.
EDIT: Try printing more than five numbers, say twelve of them. Now use char
to convert these values to ASCII characters. It looks like, in the parfor
loop fprintf
is printing out the path to the file you ran via the Terminal command (some form of parfortest.m
in a randomish order - I ran the file from ~/Desktop/parfortest.m
and converting the number from fprintf
to chars I got D/~ksepotap/frroetst.m
). If you try to print more values than the length of the path then you'll get an error. I can't find a workaround other than turn your script into a function (which is a good idea anyways). Definitely seems like a bug.