System.Threading.TParallel.For

Aus RAD Studio API Documentation
Wechseln zu: Navigation, Suche

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 */;

Eigenschaften

Typ Sichtbarkeit Quelle Unit Übergeordnet
function public
System.Threading.pas
System.Threading.hpp
System.Threading TParallel


Beschreibung

Iteriert durch eine Folge von integralen Indexwerten und ruft eine Ereignisbehandlungsroutine für jede Iteration auf, sodass jeder dieser Aufrufe in einem parallelen Thread verarbeitet werden könnte.

Ob ein Iterator-Ereignis in einem parallelen Thread verarbeitet wird, hängt von den verfügbaren Threading-Ressourcen und -Möglichkeiten ab. Obwohl der Name For auf eine Äquivalenz mit der for-Schleife hinweist, kann TParallel.For zwei oder mehr Iterationsereignisse simultan ausführen, d. h. parallel und nicht eins nach dem anderen wie bei der üblichen for-Schleife.

Jede überladene TParallel.For-Methode führt im Grunde dieselbe Operation durch, aber die unterschiedlichen Parameter jeder Überladung bieten verschiedene Funktionen und Informationen bei der Ausführung.

Alle Überladungen von TParallel.For geben TParallel.TLoopResult zurück. Wenn alle Iterationen eines TParallel.For-Iterator-Ereignisses ausgeführt wurden, wird die Eigenschaft Completed der von TParallel.For zurückgegebenen TLoopResult-Instanz auf True gesetzt.

Wenn die Überladung von TParallel.For über einen Sender-Parameter verfügt, übergibt der Aufrufer eine Objektinstanz, die bei jeder Iteration als Sender-Parameter an das Iterator-Ereignis gesendet wird, genau wie bei anderen Ereignisbehandlungsroutinen in RAD Studio. Überladungen von TParallel.For ohne einen Sender-Parameter übergeben bei jeder Iteration nil als Sender-Parameter an das Iterator-Ereignis.

Alle Überladungen von TParallel.For enthalten die Parameter ALowInclusive und AHighInclusive, die entweder Integer- oder Int64-Werte sind und die inklusiven Unter- und Obergrenzen für die Iteration repräsentieren. Das heißt, dass wenn der Wert von ALowInclusive auf 1 gesetzt wird und AHighInclusive auf 4, das Iterator-Ereignis für jeden erwarteten Wert zwischen 1 und 4 ausgeführt wird.

Mithilfe des Parameters AStride können Sie die Leistung optimieren. Die "parallel for"-Schleife verwendet zur Planung ihrer Arbeit einem Thread-Pool. Wenn die Arbeitspakete sehr klein sind, dann kann der Synchronisierungs-Overhead in dem Thread-Pool die Leistung dominieren. Wenn der Parameter AStride größer als 1 ist, dann werden AStride-Indizes in eine einzelne Arbeitseinheit gruppiert. Dadurch wird die für den Synchronisierungs-Overhead aufgewendete Zeit zulasten der Reduzierung des Parallelismus in der Schleife verringert.

Iterator-Ereignisbehandlungsroutinen werden anhand der Größe des Iteratorbereichs, Integer oder Int64, unterschieden, und ob TParallel.TLoopState vorhanden ist oder nicht. Siehe die folgenden Deklarationen für die Methodentypen, die einen Sender-Parameter enthalten.

  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;

Prozedurreferenzen eignen sich auch für Iterator-Ereignisse, in denen keine Sender-Objekte benötigt werden, was zudem die Verwendung von anonymen Methoden als Iterator-Ereignisbehandlungsroutinen ermöglicht.

Wenn die Steuerung der Iteration selbst vom Iterator-Ereignis erforderlich ist, sollte in der Iterator-Ereignisbehandlungsroutine der Parameter TParallel.TLoopState verwendet werden. Sofern vorhanden, wird der Ereignisbehandlungsroutine eine Instanz von TParallel.TLoopState übergeben, mit der Statusinformationen von Faulted, Stopped oder ShouldExit überwacht werden können, oder die Iterationsschleife kann mit der Methode Break oder Stop gesteuert werden.

Wenn ein APool-Parameter mit dem Typ TThreadPool angegeben ist, steuert der Programmentwickler die Thread-Ressourcen, die für die Iterator-Ereignisse von TParallel.For verfügbar sind, durch die Verwendung der Methoden TThreadPool.SetMinWorkerThreads und TThreadPool.SetMaxWorkerThreads. Achten Sie beim Aufruf dieser Methoden darauf, dass zu viele simultane Threads einen Overhead generieren können, der die Vorteile der parallelen Ausführung von Routinen reduziert oder vollständig zunichte macht.

Siehe auch