Calculate the number of threads as natom*dim.