title: parfor is much slower than for when matlabpool is not lauched
body: <p>in matlab' s document, it is said that if matlabpool is not launched, then parfor will be interpreted as for</p>
  
  <p>this implies that they are as efficient as each other</p>
  
  <p>however, in my code below, i find that parfor is 6 times slower than for.</p>
  
  <p>===================================</p>
  
  <pre><code>  clear all; close all; clc; tic 
  
    Nx=10;   Ny=10; 
     plist=0.05:0.05:0.95; 
    linked_list=zeros(1,length(plist)); 
  
   num_sample=20000; 
   % matlabpool open 3 
  parfor sss=1:length(plist) 
  sss 
  p=plist(sss); 
  
  numlink=0; 
  for s10=1:num_sample 
      pattern=(rand(Ny,Nx)&lt;p); 
      pattern2=zeros(Ny,Nx); 
  
      new=zeros(2,10000); 
      new2=zeros(2,10000); 
      num_new=0; 
      num_new2=0; 
  
      flag=0; 
      found=0; 
      s=0; 
      while (found==0)&amp;&amp;(s&lt;Nx) 
          s=s+1; 
          if (pattern(1,s)==1)&amp;&amp;(pattern2(1,s)==0); 
              flag=flag+1; 
  
              pattern2(1,s)=flag; 
  
              num_new=1; 
              new(1,1)=s; 
              new(2,1)=1; 
              num_new2=0; 
  
              while num_new&gt;0 
                  num_new2=0; 
                  for s1=1:num_new 
                      x=new(1,s1); 
                      y=new(2,s1); 
                      if (x-1&gt;0)&amp;&amp;(pattern(y,x-1)==1)&amp;&amp;(pattern2(y,x-1)~=flag) 
                          num_new2=num_new2+1; 
                          new2(1,num_new2)=x-1; 
                          new2(2,num_new2)=y; 
                          pattern2(y,x-1)=flag; 
                      end 
                      if (x+1&lt;=Nx)&amp;&amp;(pattern(y,x+1)==1)&amp;&amp;(pattern2(y,x+1)~=flag) 
                          num_new2=num_new2+1; 
                          new2(1,num_new2)=x+1; 
                          new2(2,num_new2)=y; 
                          pattern2(y,x+1)=flag; 
                      end 
                      if (y-1&gt;0)&amp;&amp;(pattern(y-1,x)==1)&amp;&amp;(pattern2(y-1,x)~=flag) 
                          num_new2=num_new2+1; 
                          new2(1,num_new2)=x; 
                          new2(2,num_new2)=y-1; 
                          pattern2(y-1,x)=flag; 
                      end 
                      if (y+1&lt;=Ny)&amp;&amp;(pattern(y+1,x)==1)&amp;&amp;(pattern2(y+1,x)~=flag) 
                          num_new2=num_new2+1; 
                          new2(1,num_new2)=x; 
                          new2(2,num_new2)=y+1; 
                          pattern2(y+1,x)=flag; 
                      end 
                  end 
  
                  num_new=num_new2; 
                  new(:,1:num_new)=new2(:,1:num_new); 
  
                  if max(new(2,1:num_new))==Ny 
                      found=1; 
                      break; 
                  end 
              end 
          end 
      end 
      numlink=numlink+found; 
   end 
   linked_list(sss)=numlink/num_sample; 
   end 
  
  
    plot(plist,linked_list,'*') 
  
    toc 
  </code></pre>