title: Is the following implementation making my code parallel?
body: <p>I had an assignment in Go to parallelize a given loop of a code. I am unsure whether or not my code is parallel. </p>
  
  <p>I tried simply dividing the array i had into two halves, and used a go routine on both halves.</p>
  
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      "fmt"
      "math"
  )
  
  type Body struct {
      x, y, vx, vy, mass float64
      r, g, b uint
  }
  
  func main() {
      var count uint
      var radius float64
      done := make(chan bool)
      fmt.Scan(&amp;count, &amp;radius)
      bodies := make([]Body, count)
      for i := range bodies {
          b := &amp;bodies[i]
          fmt.Scan(&amp;b.x, &amp;b.y, &amp;b.vx, &amp;b.vy, &amp;b.mass, &amp;b.r, &amp;b.g, &amp;b.b)
      }
  
      updatedBodies := make([]Body, count)
      copy(updatedBodies, bodies)
      mid := len(updatedBodies)/2
  
  
      go func(){
      for i := range updatedBodies[mid:] {
          b := &amp;updatedBodies[i+mid]
          for _, ob := range bodies {
              dx, dy := ob.x - b.x, ob.y - b.y
              if dist := math.Sqrt(dx*dx + dy*dy); dist &gt; 1 { // far enough
                  accel := 0.0000000000667 * ob.mass / (dist * dist * dist)
                  b.vx += accel * dx
                  b.vy += accel * dy
              }
          }
          b.x += b.vx
          b.y += b.vy
  
      }
      done &lt;- true
  }()
      go func(){
          for i := range updatedBodies[:mid] {
          b := &amp;updatedBodies[i]
          for _, ob := range bodies {
              dx, dy := ob.x - b.x, ob.y - b.y
              if dist := math.Sqrt(dx*dx + dy*dy); dist &gt; 1 { // far enough
                  accel := 0.0000000000667 * ob.mass / (dist * dist * dist)
                  b.vx += accel * dx
                  b.vy += accel * dy
              }
          }
          b.x += b.vx
          b.y += b.vy
  
      }
      done &lt;- true
  }()
  
      &lt;- done
      &lt;- done
      fmt.Println(count)
      fmt.Println(radius)
      for _, b := range updatedBodies {
          fmt.Println(b.x, b.y, b.vx, b.vy, b.mass, b.r, b.g, b.b)
      }
  }
  </code></pre>
  
  <pre><code>for i := range updatedBodies {
          b := &amp;updatedBodies[i]
          for _, ob := range bodies {
              dx, dy := ob.x - b.x, ob.y - b.y
              if dist := math.Sqrt(dx*dx + dy*dy); dist &gt; 1 { // far enough
                  accel := 0.0000000000667 * ob.mass / (dist * dist * dist)
                  b.vx += accel * dx
                  b.vy += accel * dy
              }
          }
          b.x += b.vx
          b.y += b.vy
  
      }
  </code></pre>
  
  <p>I asked a professor about the code he said I had to recursively run a go routine to make the loop parallel.</p>