parfor variable cannot be classified
    6 views (last 30 days)
  
       Show older comments
    
    Jeremy Rutman
      
 on 11 Nov 2015
  
    
    
    
    
    Edited: Jeremy Rutman
      
 on 17 Nov 2015
            as far as i can tell, the following code should be parallelizable, however I get a 'cannot be classified' error no matter how I twist it. This is paraphrased code . It is 'theoretically parallelizable' i blv., as the result is independent of execution order.
    a{1}=''
    a{2}='hi'
    a{3}=''
    a{4}='bye'
       parfor k = 1:10
          j=mod(k,5)
          b=a{j}
          if isempty(b)
            a{j} = j+3
          end
        end
along these lines, what can this possibly mean:
    "Notably, the assignments to the variables i, t, and u do not affect variables with the same name in the context of the parfor statement. "
a more concise statement of the problem is that the following, which is in principle parallelizable for arbitrary 'index' functions f,g (ie positive integer functions in range of the array in question), cannot in fact be compiled due to matlab compiler limitations.
    parfor k=1:10
        index=f(k)
        array(index)=g(index)
    end
however as walter roberson points out below this limitation can be somewhat avoided in this case by the following:
     parfor k=1:10 
           index=f(k)
           temparray(k)=g(index)
           indices(k)=index
     end
     for k=1:10
         array(indices(k)) = temparray(k)
     end
2 Comments
Accepted Answer
  Walter Roberson
      
      
 on 12 Nov 2015
        When k = 1 or k = 6 both times j = 1 so you have multiple iterations that would be accessing the same elements of a{}. That is not permitted
The indexing of the loop variable needs to be in-line in the access, not calculated in a previous statement and then used, so that parfor can verify that there is no possibility of overlap. mod() is not one of the permitted operations in the indexing for parfor.
6 Comments
  Walter Roberson
      
      
 on 17 Nov 2015
				We do not inherently know that g(f(x)) will be the same for the non-unique values of f. g could be a function that returns different values at different times. You would need to know that g() is either an array that is invariant during the operation, or a function that has no side effects.
None of the parallelizing compilers I have ever seen have ever been happy with code of this form that might write the same location multiple times but with the same result each time.
More Answers (0)
See Also
Categories
				Find more on Performance and Memory 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!