 
   if (gid < numvertices)
   {
-    float graphSpeed = *oldGraphSpeed;
-
-    float forceX = 0.0;
-    float forceY = 0.0;
-
-    float dispX = 0.0;
-    float dispY = 0.0;
-
-    float speed = 0.0;
+    if (gid == 0)
+    {
+      *graphSwing = 0.0;
+      *graphTract = 0.0;
+    }
+
+    forceX[gid] = 0;
+    forceY[gid] = 0;
+
+    // Gravity force
+    fa2Gravity(gid, numvertices, vxLocs, vyLocs, &forceX[gid], &forceY[gid], numNeighbours);
+    // Repulsion between vertices
+    fa2Repulsion(gid, numvertices, vxLocs, vyLocs, &forceX[gid], &forceY[gid], numNeighbours);
+    // Attraction on edges
+    fa2Attraction(gid, numvertices, vxLocs, vyLocs, numedges, edgeSources,
+        edgeTargets, &forceX[gid], &forceY[gid]);
+
+    // Calculate speed of vertices.
+    // Update swing of vertices.
+    fa2UpdateSwing(gid, numvertices, forceX[gid], forceY[gid], oldForceX, oldForceY, swg);
+
+    // Update traction of vertices.
+    fa2UpdateTract(gid, numvertices, forceX[gid], forceY[gid], oldForceX, oldForceY, tra);
+  }
+}
+
+__global__ void fa2MoveVertices(
+    float* vxLocs, float* vyLocs,
+    unsigned int numvertices,
+    float* tra, float* swg,
+    float* forceX, float* forceY,
+    float* oldForceX, float* oldForceY,
+    float* graphSwing,
+    float* graphTract)
+{
+  unsigned int gid = threadIdx.x + (blockIdx.x * BLOCK_SIZE);
+
+  if (gid < numvertices)
+  {
+    float speed = 0;
+    float dispX = 0;
+    float dispY = 0;
+
+    float graphSpeed = 0;
 
     // Update speed of Graph.
     fa2UpdateSpeedGraph(*graphSwing, *graphTract, &graphSpeed);
 
-    if (gid == 0)
-    {
-      *oldGraphSpeed = graphSpeed;
-      *graphSwing = 0.0;
-      *graphTract = 0.0;
-    }
-
-    // Gravity force
-    fa2Gravity(gid, numvertices, vxLocs, vyLocs, &forceX, &forceY, numNeighbours);
-    // Repulsion between vertices
-    fa2Repulsion(gid, numvertices, vxLocs, vyLocs, &forceX, &forceY, numNeighbours);
-    // Attraction on edges
-    fa2Attraction(gid, numvertices, vxLocs, vyLocs, numedges, edgeSources,
-        edgeTargets, &forceX, &forceY);
-
-    // Calculate speed of vertices.
-    // Update swing of vertices.
-    fa2UpdateSwing(gid, numvertices, forceX, forceY, oldForceX, oldForceY, swg);
-
-    // Update traction of vertices.
-    fa2UpdateTract(gid, numvertices, forceX, forceY, oldForceX, oldForceY, tra);
-
     // Update speed of vertices.
-    fa2UpdateSpeed(gid, numvertices, &speed, swg, forceX, forceY, graphSpeed);
+    fa2UpdateSpeed(gid, numvertices, &speed, swg, forceX[gid], forceY[gid], graphSpeed);
 
     // Update displacement of vertices.
-    fa2UpdateDisplacement(gid, numvertices, speed, forceX, forceY, &dispX, &dispY);
+    fa2UpdateDisplacement(gid, numvertices, speed, forceX[gid], forceY[gid], &dispX, &dispY);
 
     // Update vertex locations based on speed.
-    // TODO Add a barrier here to make sure no vertex location is update before
-    // all vertices have calculated their repulsion and attraction forces.
     fa2UpdateLocation(gid, numvertices, vxLocs, vyLocs, dispX, dispY);
 
     // Set current forces as old forces in vertex data.
-    fa2SaveOldForces(gid, numvertices, forceX, forceY, oldForceX, oldForceY);
+    fa2SaveOldForces(gid, numvertices, forceX[gid], forceY[gid], oldForceX, oldForceY);
   }
 }
 

    printf("time: all forces and moving vertices.\n");
    printCudaTimer(&timer);
    resetCudaTimer(&timer);
    code = cudaGetLastError();
    if (code != cudaSuccess)
    {
      printf("Error in kernel 2.\n%s\n", cudaGetErrorString(code));

  cudaMalloc(&numNeighbours, g->numvertices * sizeof(int));
  cudaMalloc(&tra, g->numvertices * sizeof(float));
  cudaMalloc(&swg, g->numvertices * sizeof(float));
  cudaMalloc(&forceX, g->numvertices * sizeof(float));
  cudaMalloc(&forceY, g->numvertices * sizeof(float));
  cudaMalloc(&oldForceX, g->numvertices * sizeof(float));
  cudaMalloc(&oldForceY, g->numvertices * sizeof(float));
  cudaMalloc(&graphSwing, sizeof(float));
