update algorithm to parallel.foreach