parallelized the algorithm with pthreads