Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Convert Parallel Loop in Matlab to Python?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 361
    Answer it

       

     T = 10   
        N = 100  % number of tasks
    
        parfor i = 1:N
           
           % initialize "t" for each "i"  
           t(i) = 2;
        
           % keep track of t(i) for each "i"
           while t(i) < T
    
                 x(i) = i*2;
                 t(i) = t(i) + 1e-2;
           end
    
         end

    In conjunction, I needed a way to detect if any `x(i)` changed for any `i` inside the while loop.
    If so, then, want to perform a computation on all of `x(i)` ... would this require collecting all the terms in a common memory location?

    Finally, I also needed to store `x, t` for each `i`, i.e., the above represents N-copies running in parallel ... with ref to the paragraph above, I need to collect all the `x(i)`'s to perform a computation when any one of the N `x(i)` gets updated.

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: