Split a job into subjobs and run a thread for each
Each thread spawned will call L{target} to handle a slice of the job.
Parameters: | job_size : int
thread_count : int
target : callable
args : sequence
kwargs : dict
|
---|
Examples
squaring 100 million numbers:
>>> import numpy
>>> import spacepy.toolbox as tb
>>> numpy.random.seed(8675301)
>>> a = numpy.random.randint(0, 100, [100000000])
>>> b = numpy.empty([100000000], dtype='int64')
>>> def targ(in_array, out_array, start, count): out_array[start:start + count] = in_array[start:start + count] ** 2
>>> tb.thread_job(len(a), 0, targ, a, b)
>>> print(b[0:5])
[2704 7225 196 1521 36]