add omp reduction and mutex to prevent writing contension