Parallelizing the part to compute gradients