add a heuristic for setting the number of threads