System.Threading.TParallel.For

De RAD Studio API Documentation
Aller à : navigation, rechercher

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

Propriétés

Type Visibilité  Source Unité  Parent
function public
System.Threading.pas
System.Threading.hpp
System.Threading TParallel


Description

Parcourt une séquence de valeurs d'index intégrales en appelant un gestionnaire d'événement pour chaque itération de manière à ce que chacun de ces appels puisse être géré dans un thread parallèle.

La gestion d'un événement itérateur dans un thread parallèle dépend des ressources de threads et des capacités disponibles. Bien que le nom For suggère une équivalence avec la boucle for, TParallel.For permet d'exécuter au moins deux événements d'itération simultanément, c'est-à-dire en parallèle, au lieu de les exécuter l'un après l'autre séquentiellement, ce qui est le cas avec la boucle for habituellement utilisée.

Même si chaque méthode de surcharge TParallel.For effectue pour l'essentiel la même opération, les paramètres distincts de chaque surcharge offrent des fonctionnalités et des informations différentes pendant l'exécution.

Toutes les surcharges de TParallel.For renvoient TParallel.TLoopResult. Une fois que toutes les itérations d'un événement itérateur TParallel.For ont été exécutées, la propriété Completed de l'instance TLoopResult renvoyée par TParallel.For est définie sur True.

Lorsque la surcharge de TParallel.For comporte un paramètre Sender, l'appelant transmet une instance d'objet qui est envoyée à l'événement itérateur dans chaque itération en tant que paramètre Sender de cet événement, comme cela se produit avec les autres gestionnaires d'événement dans RAD Studio. Les surcharges de TParallel.For n'impliquant pas un paramètre Sender transmettent nil en tant que paramètre Sender à l'événement itérateur avec chaque itération.

Toutes les surcharges de TParallel.For impliquent les paramètres ALowInclusive et AHighInclusive, qui sont des valeurs entières ou Int64 représentant les limites inférieures et supérieures inclusives de l'itération. C'est-à-dire que si la valeur de ALowInclusive est définie sur 1 et que AHighInclusive est défini sur 4, l'événement itérateur sera exécuté pour chaque valeur attendue entre 1 et 4.

Le paramètre AStride vous permet de régler la performance. La boucle "parallel for" utilise un thread-pool pour planifier le travail. Si les paquets de travail sont très petits, la surcharge de synchronisation dans le thread-pool peut diminuer la performance. Si le paramètre AStride est supérieur à 1, alors les indices AStride sont regroupés dans une seule partie du travail. Cela réduit le temps dédié à la surcharge de synchronisation au détriment de la réduction du parallélisme dans la boucle.

Les gestionnaires d'événement itérateur se distinguent par la taille de la plage d'itération (valeur entière ou Int64) et par la présence ou non d'un TParallel.TLoopState, comme on peut le voir dans les déclarations ci-dessous pour les types de méthode impliquant un paramètre Sender.

  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;

Les références de procédure conviennent également aux événements itérateurs lorsque des objets Sender ne sont pas nécessaires, ce qui permet également d'utiliser des méthodes anonymes comme gestionnaires d'événement itérateur.

Si le contrôle de l'itération elle-même est nécessaire à partir de l'événement itérateur, le gestionnaire d'événement itérateur doit utiliser le paramètre TParallel.TLoopState. Lorsqu'il est présent, le gestionnaire d'événement reçoit une instance de TParallel.TLoopState à partir duquel les informations d'état telles que Faulted, Stopped ou ShouldExit peuvent être surveillées. Sinon, la boucle d'itération elle-même peut être contrôlée avec les méthodes Break ou Stop.

Lorsque le paramètre APool de type TThreadPool est spécifié, le créateur du programme contrôle les ressources de threads disponibles pour les événements itérés de TParallel.For via l'utilisation de ses méthodes TThreadPool.SetMinWorkerThreads et TThreadPool.SetMaxWorkerThreads. Lorsque vous appelez ces méthodes, n'oubliez pas qu'un trop grand nombre de threads simultanés peut générer une surcharge qui diminue ou élimine l'avantage de l'exécution de routines en parallèle.

Voir aussi