public static class Arrays.Copier extends Arrays.ParallelExecutor
simple copying of the source array.
This class is used by
Arrays.copy(ArrayContext, UpdatableArray, Array) and
Arrays.copy(ArrayContext, UpdatableArray, Array, int) methods.
Please note: this class does not provide functionality of the methods
Arrays.copy(ArrayContext, UpdatableArray, Array, int, boolean) and
Arrays.compareAndCopy(ArrayContext, UpdatableArray, Array).
|Constructor and Description|
Creates new instance of this class, performing copying of src array to dest array.
|Modifier and Type||Method and Description|
Performs full processing the source AlgART array, passed to the constructor.
checkInterruption, correctNumberOfRanges, endGap, finish, granularity, increaseReadyCount, numberOfRanges, numberOfTasks, processRange, rangeFrom, rangeLength, rangeTo, readyCount, recommendedNumberOfRanges, startGap, toString, updateProgress
public Copier(ArrayContext context, UpdatableArray dest, Array src, int numberOfTasks, long numberOfRanges)
process()method of the created instance is equivalent to
Arrays.copy(context, dest, src, numberOfTasks)call, excepting that the last method sometimes uses more complex copying algorithms.
context- the context of copying; may be null, then it will be ignored.
dest- the destination array.
src- the source array.
numberOfTasks- the desired number of parallel tasks or 0 if you want to determine this number automatically, from the passed context or (if it is null) from
numberOfRanges- the desired number of ranges for splitting the source array. If the
Arrays.ParallelExecutor.numberOfTasks(calculated automatically or equal to the corresponding argument) is 1, then this argument is ignored and 1 range is used (no splitting). If this argument is positive and <
Arrays.ParallelExecutor.numberOfTasks, it is replaced with
Arrays.ParallelExecutor.numberOfTasks. If this argument is 0 and
Arrays.ParallelExecutor.numberOfTasks>1, then the number of ranges is chosen automatically as max(
java.lang.NullPointerException- if the src or dest argument is null.
java.lang.IllegalArgumentException- if blockSize <= 0, or if numberOfTasks < 0, or if numberOfRanges < 0.
public void process()
This method uses a thread pool for performing calculations:
The full processing task is split into M=
and the source array is split into n=
It is possible to use M=1 (recommended settings for 1 CPU kernel),
but even in this case we recommend to choice n big enough to split the array
into not too large regions: it can help this method to optimize preloading and flushing
external disk resources.
The lengths of ranges are chosen equal or almost equal, with the only condition
that the first index of every range (splitting position) is multiple of
Each task #k, 0<=k<M,
processes a set of regions of the src array with step M regions,
i.e. the regions #k, #k+M, #k+2M, ...
Processing each region means just a call of
Arrays.ParallelExecutor.processRange(long, long, int, long) method
for the corresponding region of the array.
All tasks are submitted to the thread pool, and then this method
waits until all tasks will be completed.
If some task throws an exception, this exception is stored and the internal flag
"interruptionRequested" is set, that should lead to interruption of
Arrays.ParallelExecutor.processRange(long, long, int, long) methods (due to calling
Arrays.ParallelExecutor.checkInterruption() by them).
This exception will be re-thrown by this method before finishing.
In addition to calling
this method also interrupts all running threads, if the current thread,
that calls this method,
is interrupted by the standard Thread.interrupt() call.
In this (and only this) case this method throws java.io.IOError.
Usually, you should avoid interrupting the threads, processing AlgART arrays,
via Thread.interrupt() technique: see the package description
about runtime exceptions issue.
The number of tasks and regions and the sizes of regions may be specified by arguments of the constructor or may be chosen automatically (if that arguments are 0).
The thread pool, performing the multithread processing,
is returned and (before finishing the processing) released by the methods of
where context is the argument of the constructor.
If context argument is null,
DefaultThreadPoolFactory instance is created and used instead
Note: if the number of parallel tasks is 1, this method performs processing in the current thread and does not use the thread pool at all.
At the end, in finally section, this method calls
Arrays.ParallelExecutor.finish() method. Please note: if some RuntimeException B is thrown
Arrays.ParallelExecutor.finish() and there were some other exception A while executing
the main body of this
Arrays.ParallelExecutor.process() method, than the finishing exception B is ignored,
but the main (usually more important) exception A is thrown.
This method does nothing if the length the source array is 0.
protected void processSubArr(long position, int count, int threadIndex)
subArr(position,count) to dest.