Parallelized the trainer with variable number of threads.