if nthreads>ncores nthreads=ncores