System.Threading.TParallel.For
Delphi
class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorEvent): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorEvent; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorStateEvent): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorStateEvent; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorEvent): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorEvent; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorStateEvent): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorStateEvent; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer>): TLoopResult; overload; static; inline;
class function &For(ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer>; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer, TLoopState>): TLoopResult; overload; static; inline;
class function &For(ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer, TLoopState>; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(AStride, ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer>): TLoopResult; overload; static; inline;
class function &For(AStride, ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer>; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(AStride, ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer, TLoopState>): TLoopResult; overload; static; inline;
class function &For(AStride, ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer, TLoopState>; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorEvent64): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorEvent64; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorStateEvent64): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorStateEvent64; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorEvent64): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorEvent64; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorStateEvent64): TLoopResult; overload; static; inline;
class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorStateEvent64; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64>): TLoopResult; overload; static; inline;
class function &For(ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64>; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64, TLoopState>): TLoopResult; overload; static; inline;
class function &For(ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64, TLoopState>; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(AStride, ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64>): TLoopResult; overload; static; inline;
class function &For(AStride, ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64>; APool: TThreadPool): TLoopResult; overload; static; inline;
class function &For(AStride, ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64, TLoopState>): TLoopResult; overload; static; inline;
class function &For(AStride, ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64, TLoopState>; APool: TThreadPool): TLoopResult; overload; static; inline;
C++
static TLoopResult __fastcall For(System::TObject* Sender, int ALowInclusive, int AHighInclusive, TIteratorEvent AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, int ALowInclusive, int AHighInclusive, TIteratorEvent AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, int ALowInclusive, int AHighInclusive, TIteratorStateEvent AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, int ALowInclusive, int AHighInclusive, TIteratorStateEvent AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, int AStride, int ALowInclusive, int AHighInclusive, TIteratorEvent AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, int AStride, int ALowInclusive, int AHighInclusive, TIteratorEvent AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, int AStride, int ALowInclusive, int AHighInclusive, TIteratorStateEvent AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, int AStride, int ALowInclusive, int AHighInclusive, TIteratorStateEvent AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(int ALowInclusive, int AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__1<int> > AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(int ALowInclusive, int AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__1<int> > AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(int ALowInclusive, int AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__2<int,TLoopState*> > AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(int ALowInclusive, int AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__2<int,TLoopState*> > AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(int AStride, int ALowInclusive, int AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__1<int> > AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(int AStride, int ALowInclusive, int AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__1<int> > AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(int AStride, int ALowInclusive, int AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__2<int,TLoopState*> > AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(int AStride, int ALowInclusive, int AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__2<int,TLoopState*> > AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, __int64 ALowInclusive, __int64 AHighInclusive, TIteratorEvent64 AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, __int64 ALowInclusive, __int64 AHighInclusive, TIteratorEvent64 AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, __int64 ALowInclusive, __int64 AHighInclusive, TIteratorStateEvent64 AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, __int64 ALowInclusive, __int64 AHighInclusive, TIteratorStateEvent64 AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, __int64 AStride, __int64 ALowInclusive, __int64 AHighInclusive, TIteratorEvent64 AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, __int64 AStride, __int64 ALowInclusive, __int64 AHighInclusive, TIteratorEvent64 AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, __int64 AStride, __int64 ALowInclusive, __int64 AHighInclusive, TIteratorStateEvent64 AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(System::TObject* Sender, __int64 AStride, __int64 ALowInclusive, __int64 AHighInclusive, TIteratorStateEvent64 AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(__int64 ALowInclusive, __int64 AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__1<__int64> > AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(__int64 ALowInclusive, __int64 AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__1<__int64> > AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(__int64 ALowInclusive, __int64 AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__2<__int64,TLoopState*> > AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(__int64 ALowInclusive, __int64 AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__2<__int64,TLoopState*> > AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(__int64 AStride, __int64 ALowInclusive, __int64 AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__1<__int64> > AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(__int64 AStride, __int64 ALowInclusive, __int64 AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__1<__int64> > AIteratorEvent, TThreadPool* APool)/* overload */;
static TLoopResult __fastcall For(__int64 AStride, __int64 ALowInclusive, __int64 AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__2<__int64,TLoopState*> > AIteratorEvent)/* overload */;
static TLoopResult __fastcall For(__int64 AStride, __int64 ALowInclusive, __int64 AHighInclusive, const System::DelphiInterface<System::Sysutils::TProc__2<__int64,TLoopState*> > AIteratorEvent, TThreadPool* APool)/* overload */;
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | System.Threading.pas System.Threading.hpp |
System.Threading | TParallel |
Description
Iterates through a sequence of integral index values calling an event handler for each iteration such that any of these calls may be handled in a parallel thread.
Whether or not an iterator event is handled in a parallel thread depends on available threading resources and capabilities. While the name For suggests equivalence with the for-loop in the language, TParallel.For may execute two or more iteration events simultaneously, that is, in parallel, rather than one after the other sequentially, as happens with the customary for-loop in the language.
While each TParallel.For overload method essentially performs the same operation, differing parameters of each overload offer different functionality and information during execution.
All overloads of TParallel.For return TParallel.TLoopResult. When all the iterations of a TParallel.For iterator event have been executed, the Completed property of the TLoopResult instance returned by TParallel.For is set to True.
When the overload of TParallel.For has a Sender
parameter, the caller passes an object instance which is sent to the iterator event in each iteration as its Sender
parameter, as is done with other event handlers in RAD Studio. Overloads of TParallel.For not involving a Sender
parameter pass nil as the Sender
parameter to the iterator event with each iteration.
All overloads of TParallel.For involve the parameters, ALowInclusive
and AHighInclusive
, that are either Integer or Int64 values representing the lower and upper inclusive bounds for the iteration. That is, if the value of ALowInclusive
is set to 1 and AHighInclusive
is set to 4, the iterator event will be executed for each expected value between 1 and 4.
The AStride
parameter allows you to tune the performance. The "parallel for" loop uses a thread pool to schedule the work. If the work packets are very small, then the synchronization overhead within the thread pool can dominate performance. If the AStride
parameter is greater than 1, then AStride
indices will be grouped into a single piece of work. This reduces the amount of time spent on synchronization overhead at the expense of reducing parallelism in the loop.
Iterator event handlers are distinguished by the size of the iterating range, Integer or Int64, and by whether or not a TParallel.TLoopState is present, as seen in the declarations below for the method types involving a Sender
parameter.
TIteratorEvent = procedure (Sender: TObject; AIndex: Integer) of object; TIteratorStateEvent = procedure (Sender: TObject; AIndex: Integer; const LoopState: TLoopState) of object; TIteratorEvent64 = procedure (Sender: TObject; AIndex: Int64) of object; TIteratorStateEvent64 = procedure (Sender: TObject; AIndex: Int64; const LoopState: TLoopState) of object;
Procedure references are also suitable for iterator events where Sender
objects are not needed, which also allows for the use of anonymous methods as iterator event handlers.
If control of the iteration itself is needed from the iterator event, the iterator event handler should be one using the TParallel.TLoopState parameter. When present, the event handler will be given an instance of TParallel.TLoopState from which state information from Faulted,Stopped, or ShouldExit can be monitored, or the iteration loop itself can be controlled with the Break or Stop methods.
When APool
parameter of type TThreadPool is specified, the program author controls the thread resources available to the iterated events of TParallel.For through the use of its TThreadPool.SetMinWorkerThreads and TThreadPool.SetMaxWorkerThreads methods. Be advised when calling these methods that too many simultaneous threads can generate overhead that diminishes or eliminates the benefit of executing routines in parallel.
See Also
- System.Threading.TParallel.TIteratorEvent
- System.Threading.TParallel.TLoopResult
- System.Threading.TParallel
- System.Threading.TParallel.TIteratorStateEvent
- System.Threading.TParallel.TIteratorEvent64
- System.Threading.TParallel.TIteratorStateEvent64
- System.Threading.TParallel.TLoopState
- System.Threading.TThreadPool
- Using TParallel.For from the Parallel Programming Library
- Tutorial: Using the For Loop from the Parallel Programming Library