modifying CPX code to accept num_threads argument