parameters: (start,        # First iteration's index
                 end,          # Final iteration's index
                 loopBody,     # Function to execute each iteration
                 scheduleType = 'guided', # Load balancing technique
                 minChunk = 1  # Smallest block of iterations
                 )
docstring: Execute the local iterations of a decomposed loop with
      the specified scheduling.
docstring_summary: Execute the local iterations of a decomposed loop with
      the specified scheduling.
docstring_tokens: Execute the local iterations of a decomposed loop with the specified scheduling .
function: def parForEach(start,        # First iteration's index
                 end,          # Final iteration's index
                 loopBody,     # Function to execute each iteration
                 scheduleType = 'guided', # Load balancing technique
                 minChunk = 1  # Smallest block of iterations
                 ):
      """Execute the local iterations of a decomposed loop with
      the specified scheduling.
      """
      global myID, libems, EMSmmapID, _regionN, pinThreads, domainName, inParallelContext, tasks, nThreads
  
      if scheduleType == 'static':  # Evenly divide the iterations across threads
          blocksz = math.floor((end - start) / nThreads) + 1
          s = int((blocksz * myID) + start)
          e = int((blocksz * (myID + 1)) + start)
          if e > end:
              e = end
          for idx in range(s, e):
              loopBody(idx)
      else:  # scheduleType == 'dynamic'  or  scheduleType == 'guided'  or default
          #  Initialize loop bounds, block size, etc.
          if scheduleType == 'guided':
              ems_sched_type = 1200  # From ems.h
          elif scheduleType == 'dynamic':
              ems_sched_type = 1201  # From ems.h
          else:
              print("EMS parForEach: Invalid scheduling type:", scheduleType)
              return
          libems.EMSloopInit(EMSmmapID, start, end, minChunk, ems_sched_type)
          #  Do not enter loop until all threads have completed initialization
          #  If the barrier is present at the loop end, this may replaced
          #  with first-thread initialization.
          barrier()
          extents = _loop_chunk()
          while extents['end'] - extents['start'] > 0:
              for idx in range(extents['start'], extents['end']):
                  loopBody(idx)
              extents = _loop_chunk()
  
      #  Do not proceed until all iterations have completed
      #  TODO: OpenMP offers NOWAIT to skip this barrier
      barrier()
function_tokens: def parForEach ( start , # First iteration's index end , # Final iteration's index loopBody , # Function to execute each iteration scheduleType = 'guided' , # Load balancing technique minChunk = 1 # Smallest block of iterations ) : global myID , libems , EMSmmapID , _regionN , pinThreads , domainName , inParallelContext , tasks , nThreads if scheduleType == 'static' : # Evenly divide the iterations across threads blocksz = math . floor ( ( end - start ) / nThreads ) + 1 s = int ( ( blocksz * myID ) + start ) e = int ( ( blocksz * ( myID + 1 ) ) + start ) if e > end : e = end for idx in range ( s , e ) : loopBody ( idx ) else : # scheduleType == 'dynamic'  or  scheduleType == 'guided'  or default #  Initialize loop bounds, block size, etc. if scheduleType == 'guided' : ems_sched_type = 1200 # From ems.h elif scheduleType == 'dynamic' : ems_sched_type = 1201 # From ems.h else : print ( "EMS parForEach: Invalid scheduling type:" , scheduleType ) return libems . EMSloopInit ( EMSmmapID , start , end , minChunk , ems_sched_type ) #  Do not enter loop until all threads have completed initialization #  If the barrier is present at the loop end, this may replaced #  with first-thread initialization. barrier ( ) extents = _loop_chunk ( ) while extents [ 'end' ] - extents [ 'start' ] > 0 : for idx in range ( extents [ 'start' ] , extents [ 'end' ] ) : loopBody ( idx ) extents = _loop_chunk ( ) #  Do not proceed until all iterations have completed #  TODO: OpenMP offers NOWAIT to skip this barrier barrier ( )