title: How to run given function in Bash in parallel?
body: <p>There have been some similar questions, but my problem is not "run several programs in parallel" - which can be trivially done with <code>parallel</code> or <code>xargs</code>.</p>
  
  <p>I need to parallelize Bash functions.</p>
  
  <p>Let's imagine code like this:</p>
  
  <pre><code>for i in "${list[@]}"
  do
      for j in "${other[@]}"
      do
      # some processing in here - 20-30 lines of almost pure bash
      done
  done
  </code></pre>
  
  <p>Some of the processing requires calls to external programs.</p>
  
  <p>I'd like to run some (4-10) tasks, each running for different <code>$i</code>. Total number of elements in $list is > 500.</p>
  
  <p>I know I can put the whole <code>for j ... done</code> loop in external script, and just call this program in parallel, but is it possible to do without splitting the functionality between two separate programs?</p>