Replace for loop with parallel thread for loop