def test_can_run_loop_body_in_process_per_item(): pids = multiprocessing.Array(c_int, 10) sequence = range(10) for i in parallelize(sequence, fork=per_item): pids[i] = os.getpid() assert len(set(pids)) == len(sequence)
def test_runs_loop_body_in_process_per_cpu_by_default(): cpus = multiprocessing.cpu_count() pids = multiprocessing.Array(c_int, 100) sequence = range(100) for i in parallelize(sequence): pids[i] = os.getpid() assert len(set(pids)) == cpus
def Energy_list_parallel(self,x,atomCount = None,cores = None): if cores: c = cores else: c = self.num_cores if atomCount == None: atomCount = [None for i in range(len(x))] return pa.parallelize(self.Energy,zip(*[x,atomCount]),c)
def get_matches(self, num_processes, sample=None): job = utils.sample_index(self.df, sample) partitions_results = parallelize.parallelize( num_processes, map=self.partition, reduce=self.match).run(job) return dedupe.collect_matches(partitions_results)
import os from parallelize import parallelize from time import sleep, time print('one process:') t0 = time() for i in range(12): print('%2d pid = %d' % (i, os.getpid())) sleep(.2) print('elapsed time: %0.2f' % (time() - t0)) print() print('several processes:') t0 = time() for i in parallelize(range(12)): print('%2d pid = %d' % (i, os.getpid())) sleep(.2) print('elapsed time: %0.2f' % (time() - t0))
import os from time import sleep, time from parallelize import parallelize, per_item DELAY = .2 def loiter(serial, delay): pid = os.getpid() print('%2d pid = %d' % (serial, pid)) sleep(delay) return pid t0 = time() results = [] for i in parallelize(range(15), fork=per_item): res = loiter(i, DELAY) results.append(res) print('Processes used: ', list(set(results))) print('### Elapsed time: %0.2f' % (time() - t0))