add a bunch of code for ncpu support.