Set the number of CPUs used for MPI.
188336
def set_mpi_procs(self, mpi_procs):
        """"""
        QueueAdapter.set_mpi_procs(self, mpi_procs)

        num_nodes, rest_cores = self.hw.divmod_node(mpi_procs, omp_threads=1)
        if num_nodes == 0:
            self.qparams["nodes"] = 1
            self.qparams["ppn"] = mpi_procs
        else:
            if rest_cores != 0:
                # Pack cores as much as possible.
                num_nodes += 1
            self.qparams["nodes"] = num_nodes
            self.qparams["ppn"] = self.hw.cores_per_node
164199
def cli(env, identifier, wait):
    """"""

    compute = SoftLayer.HardwareManager(env.client)
    compute_id = helpers.resolve_id(compute.resolve_ids, identifier,
                                    'hardware')
    ready = compute.wait_for_ready(compute_id, wait)
    if ready:
        env.fout("READY")
    else:
        raise exceptions.CLIAbort("Server %s not ready" % compute_id)
489949
def _validate_resources(self):
        """"""
        resources = self.options.resources

        for key in ['num_machines', 'num_mpiprocs_per_machine', 'tot_num_mpiprocs']:
            if key in resources and resources[key] != 1:
                raise exceptions.FeatureNotAvailable(
                    "Cannot set resource '{}' to value '{}' for {}: parallelization is not supported, "
                    "only a value of '1' is accepted.".format(key, resources[key], self.__class__.__name__))
1271497
public void setParallelism(int parallelism) {
		Preconditions.checkArgument(
				parallelism > 0 || parallelism == ExecutionConfig.PARALLELISM_DEFAULT,
				"The parallelism must be at least one, or ExecutionConfig.PARALLELISM_DEFAULT (use system default).");
		this.parallelism = parallelism;
	}
321383
def partition_by_cores(a:Collection, n_cpus:int)->List[Collection]:
    ""
    return partition(a, len(a)//n_cpus + 1)
547474
def map(self):
        """"""
        with Pool(self.cpu_count) as pool:
            pool.map(self._func, self._iterable)
            pool.close()
        return True
656651
def infer_process_count(self):
        '''
        '''

        try:
            self.processes = multiprocessing.cpu_count()
        except NotImplementedError:
            self._logger.log(
                'error',
                'Could infer CPU count, setting number of processes back to 4'
            )
            self.processes = 4
513815
def _collect_cpu_info(run_info):
  """"""
  cpu_info = {}

  cpu_info["num_cores"] = multiprocessing.cpu_count()

  # Note: cpuinfo is not installed in the TensorFlow OSS tree.
  # It is installable via pip.
  import cpuinfo    # pylint: disable=g-import-not-at-top

  info = cpuinfo.get_cpu_info()
  cpu_info["cpu_info"] = info["brand"]
  cpu_info["mhz_per_cpu"] = info["hz_advertised_raw"][0] / 1.0e6

  run_info["machine_config"]["cpu_info"] = cpu_info
226269
def process_affinity(affinity=None):
    
    if affinity is not None:
        affinity = CPUSet(affinity)
        if not affinity.issubset(system_affinity()):
            raise ValueError("unknown cpus: %s" % affinity)
    return system_affinity()
859717
public static void setNumberOfThreads(Job job, int threads) {
        job.getConfiguration().setInt(ConfigConstants.CONF_THREADS_PER_SPLIT,
            threads);
    }
415812
def with_cpu(ops, model):
    """"""
    model.to_cpu()

    def with_cpu_forward(inputs, drop=0.0):
        cpu_outputs, backprop = model.begin_update(_to_cpu(inputs), drop=drop)
        gpu_outputs = _to_device(ops, cpu_outputs)

        def with_cpu_backprop(d_outputs, sgd=None):
            cpu_d_outputs = _to_cpu(d_outputs)
            return backprop(cpu_d_outputs, sgd=sgd)

        return gpu_outputs, with_cpu_backprop

    return wrap(with_cpu_forward, model)
1137690
def run_multicore(fn, items, config, parallel=None):
    
    if len(items) == 0:
        return []
    if parallel is None or "num_jobs" not in parallel:
        if parallel is None:
            parallel = {"type": "local", "cores": config["algorithm"].get("num_cores", 1)}
        sysinfo = system.get_info({}, parallel)
        parallel = resources.calculate(parallel, items, sysinfo, config,
                                       parallel.get("multiplier", 1),
                                       max_multicore=int(parallel.get("max_multicore", sysinfo["cores"])))
    items = [config_utils.add_cores_to_config(x, parallel["cores_per_job"]) for x in items]
    if joblib is None:
        raise ImportError("Need joblib for multiprocessing parallelization")
    out = []
    for data in joblib.Parallel(parallel["num_jobs"], batch_size=1, backend="multiprocessing")(joblib.delayed(fn)(*x) for x in items):
        if data:
            out.extend(data)
    return out
455269
def set_parallel_value_for_key(self, key, value):
        
        if self._remotelib:
            self._remotelib.run_keyword('set_parallel_value_for_key',
                                        [key, value], {})
        else:
            _PabotLib.set_parallel_value_for_key(self, key, value)
173605
function num_of_cpus() {
  try {
    if(process.env['OMP_NUM_THREADS']) {
      return process.env['OMP_NUM_THREADS'];
    }

    return Math.ceil(jsonConfig.info.limits.cpu);
  } catch (err) {
    throw new Error('Could not get number of cpus');
  }
}
554729
def update(self):
        """"""
        # Init new stats
        stats = self.get_init_value()

        # Grab per-CPU stats using psutil's cpu_percent(percpu=True) and
        # cpu_times_percent(percpu=True) methods
        if self.input_method == 'local':
            stats = cpu_percent.get(percpu=True)
        else:
            # Update stats using SNMP
            pass

        # Update the stats
        self.stats = stats

        return self.stats
252798
def _munch_off_batch(self, queue):
        
        """

        # if the number of CPUs used == 1, just pop one off (which == below)
        # elif the the number of things in the queue is 1, use all the CPUs and just that hmm
        if len(queue) == 1 or self._num_cpus == 1:
            pairs_to_run = [[queue.pop(0), self._num_cpus]]
        else:
            # else share out CPUs among hmmers
            pairs_to_run = []
            while len(queue) > 0 and len(pairs_to_run) < self._num_cpus:
                pairs_to_run.append([queue.pop(0), 1])
            # Share out any remaining CPUs
            num_cpus_left = self._num_cpus - len(pairs_to_run)
            while num_cpus_left > 0:
                for i, _ in enumerate(pairs_to_run):
                    pairs_to_run[i][1] += 1
                    num_cpus_left -= 1
                    if num_cpus_left == 0: break

        return pairs_to_run
191843
def _setup_resources():
    
    target_procs = 10240
    cur_proc, max_proc = resource.getrlimit(resource.RLIMIT_NPROC)
    target_proc = min(max_proc, target_procs) if max_proc > 0 else target_procs
    resource.setrlimit(resource.RLIMIT_NPROC, (max(cur_proc, target_proc), max_proc))
    cur_hdls, max_hdls = resource.getrlimit(resource.RLIMIT_NOFILE)
    target_hdls = min(max_hdls, target_procs) if max_hdls > 0 else target_procs
    resource.setrlimit(resource.RLIMIT_NOFILE, (max(cur_hdls, target_hdls), max_hdls))