ndmspc v1.2.0-0.1.rc5
Loading...
Searching...
No Matches
Ndmspc::NDimensionalExecutor Class Reference

Executes a function over all points in an N-dimensional space, optionally in parallel. More...

#include <NDimensionalExecutor.h>

Classes

struct  IpcSession
 

Public Member Functions

 NDimensionalExecutor (const std::vector< int > &minBounds, const std::vector< int > &maxBounds)
 Constructor from min/max bounds for each dimension.
 
 NDimensionalExecutor (THnSparse *hist, bool onlyfilled=false)
 Constructor from THnSparse histogram.
 
void SetBounds (const std::vector< int > &minBounds, const std::vector< int > &maxBounds)
 
void Execute (const std::function< void(const std::vector< int > &coords)> &func)
 Execute a function over all coordinates in the N-dimensional space.
 
template<typename TObject>
void ExecuteParallel (const std::function< void(const std::vector< int > &coords, TObject &thread_object)> &func, std::vector< TObject > &thread_objects)
 Execute a function in parallel over all coordinates, using thread-local objects.
 
size_t ExecuteParallelProcessIpc (std::vector< NThreadData * > &workerObjects, size_t processCount)
 Execute fixed-contract processing in multiple child processes over IPC.
 
void StartProcessIpc (std::vector< NThreadData * > &workerObjects, size_t processCount, const std::string &tcpBindEndpoint="", const std::string &jobDir="", const std::string &treeName="ngnt", const std::string &macroList="", const std::string &tmpDir="", const std::string &tmpResultsDir="", const std::string &macroParams="")
 
size_t ExecuteCurrentBoundsProcessIpc (const std::string &definitionName="", const std::vector< Long64_t > *definitionIds=nullptr, const std::function< void(const ExecutionProgress &)> &progressCallback=nullptr)
 
void FinishProcessIpc (bool abort=false)
 
std::set< size_t > GetRegisteredWorkerIndices () const
 
size_t Dimensions () const
 Returns the number of dimensions.
 
const std::vector< int > & GetMinBounds () const
 Returns the minimum bounds for each dimension.
 
const std::vector< int > & GetMaxBounds () const
 Returns the maximum bounds for each dimension.
 

Private Member Functions

bool Increment ()
 Increment the current coordinates to the next point in the N-dimensional space.
 
bool InitTcpWorker (const std::string &identity)
 Sends INIT to a newly-connected TCP worker, waits for ACK, and registers it in identityToWorker / workerIdentityVec.
 
bool HandleBootstrap (const std::string &identity)
 Handles a BOOTSTRAP message from a worker: assigns the next sequential index and replies with a CONFIG frame containing macro list, macro params, and env vars.
 
size_t HandleWorkerFailure (const std::string &failedIdentity, const std::string &failureReason, size_t &outstanding, size_t &acked)
 Centralized worker failure handling: recovers tasks, removes worker, updates state. Returns the count of tasks redistributed to the pending queue.
 

Private Attributes

size_t fNumDimensions
 Number of dimensions.
 
std::vector< int > fMinBounds
 Minimum bounds for each dimension.
 
std::vector< int > fMaxBounds
 Maximum bounds for each dimension.
 
std::vector< int > fCurrentCoords
 Current coordinates during iteration.
 
std::unique_ptr< IpcSessionfIpcSession
 
std::set< size_t > fRegisteredWorkerIndices
 Worker indices that completed registration (TCP mode)
 

Detailed Description

Executes a function over all points in an N-dimensional space, optionally in parallel.

Author
Martin Vala mvala.nosp@m.@cer.nosp@m.n.ch

Definition at line 42 of file NDimensionalExecutor.h.

Constructor & Destructor Documentation

◆ NDimensionalExecutor() [1/2]

Ndmspc::NDimensionalExecutor::NDimensionalExecutor ( const std::vector< int > & minBounds,
const std::vector< int > & maxBounds )

Constructor from min/max bounds for each dimension.

Parameters
minBoundsMinimum bounds for each dimension.
maxBoundsMaximum bounds for each dimension.

Constructor

Definition at line 127 of file NDimensionalExecutor.cxx.

References fCurrentCoords, fMaxBounds, fMinBounds, and fNumDimensions.

◆ NDimensionalExecutor() [2/2]

Ndmspc::NDimensionalExecutor::NDimensionalExecutor ( THnSparse * hist,
bool onlyfilled = false )

Constructor from THnSparse histogram.

Parameters
histPointer to THnSparse histogram.
onlyfilledIf true, iterate only filled bins.

Constructor with THnSparse input

Definition at line 180 of file NDimensionalExecutor.cxx.

References fCurrentCoords, fMaxBounds, fMinBounds, and fNumDimensions.

Member Function Documentation

◆ Dimensions()

size_t Ndmspc::NDimensionalExecutor::Dimensions ( ) const
inline

Returns the number of dimensions.

Returns
Number of dimensions.

Definition at line 101 of file NDimensionalExecutor.h.

References fNumDimensions.

◆ Execute()

void Ndmspc::NDimensionalExecutor::Execute ( const std::function< void(const std::vector< int > &coords)> & func)

Execute a function over all coordinates in the N-dimensional space.

Parameters
funcFunction to execute, taking coordinates as argument.

Sequential Execution

Definition at line 212 of file NDimensionalExecutor.cxx.

References fCurrentCoords, fMinBounds, fNumDimensions, and Increment().

Referenced by Ndmspc::NBinning::FillAll(), Ndmspc::NBinningDef::RefreshContentFromIds(), Ndmspc::NBinningDef::RefreshIdsFromContent(), and Ndmspc::NGnNavigator::Reshape().

◆ ExecuteCurrentBoundsProcessIpc()

size_t Ndmspc::NDimensionalExecutor::ExecuteCurrentBoundsProcessIpc ( const std::string & definitionName = "",
const std::vector< Long64_t > * definitionIds = nullptr,
const std::function< void(const ExecutionProgress &)> & progressCallback = nullptr )

Definition at line 832 of file NDimensionalExecutor.cxx.

◆ ExecuteParallel()

template<typename TObject>
template void Ndmspc::NDimensionalExecutor::ExecuteParallel< NGnThreadData > ( const std::function< void(const std::vector< int > &coords, TObject &thread_object)> & func,
std::vector< TObject > & thread_objects )

Execute a function in parallel over all coordinates, using thread-local objects.

Execute a function in parallel over all coordinates, using thread-local objects. Handles task distribution, synchronization, and exception propagation.

Template Parameters
TObjectType of thread-local object.
Parameters
funcFunction to execute, taking coordinates and thread-local object.
thread_objectsVector of thread-local objects, one per thread.
Exceptions
std::exceptionIf any worker thread throws, the first exception is rethrown after joining.

Definition at line 235 of file NDimensionalExecutor.cxx.

References fCurrentCoords, fMinBounds, fNumDimensions, Ndmspc::NThreadData::GetAssignedIndex(), Increment(), and Ndmspc::NLogger::SetThreadName().

Referenced by Ndmspc::NGnTree::Process().

◆ ExecuteParallelProcessIpc()

size_t Ndmspc::NDimensionalExecutor::ExecuteParallelProcessIpc ( std::vector< NThreadData * > & workerObjects,
size_t processCount )

Execute fixed-contract processing in multiple child processes over IPC.

Parameters
workerObjectsWorker objects (NThreadData-derived) used by child processes.
processCountNumber of worker processes to use.
Returns
Number of processed tasks acknowledged by workers.

Definition at line 405 of file NDimensionalExecutor.cxx.

◆ FinishProcessIpc()

void Ndmspc::NDimensionalExecutor::FinishProcessIpc ( bool abort = false)

Definition at line 1578 of file NDimensionalExecutor.cxx.

◆ GetMaxBounds()

const std::vector< int > & Ndmspc::NDimensionalExecutor::GetMaxBounds ( ) const
inline

Returns the maximum bounds for each dimension.

Returns
Vector of maximum bounds.

Definition at line 113 of file NDimensionalExecutor.h.

References fMaxBounds.

◆ GetMinBounds()

const std::vector< int > & Ndmspc::NDimensionalExecutor::GetMinBounds ( ) const
inline

Returns the minimum bounds for each dimension.

Returns
Vector of minimum bounds.

Definition at line 107 of file NDimensionalExecutor.h.

References fMinBounds.

◆ GetRegisteredWorkerIndices()

std::set< size_t > Ndmspc::NDimensionalExecutor::GetRegisteredWorkerIndices ( ) const
inline

Definition at line 95 of file NDimensionalExecutor.h.

◆ HandleBootstrap()

bool Ndmspc::NDimensionalExecutor::HandleBootstrap ( const std::string & identity)
private

Handles a BOOTSTRAP message from a worker: assigns the next sequential index and replies with a CONFIG frame containing macro list, macro params, and env vars.

Definition at line 519 of file NDimensionalExecutor.cxx.

Referenced by InitTcpWorker().

◆ HandleWorkerFailure()

size_t Ndmspc::NDimensionalExecutor::HandleWorkerFailure ( const std::string & failedIdentity,
const std::string & failureReason,
size_t & outstanding,
size_t & acked )
private

Centralized worker failure handling: recovers tasks, removes worker, updates state. Returns the count of tasks redistributed to the pending queue.

Definition at line 755 of file NDimensionalExecutor.cxx.

◆ Increment()

bool Ndmspc::NDimensionalExecutor::Increment ( )
private

Increment the current coordinates to the next point in the N-dimensional space.

Returns
True if increment was successful, false if end reached.

Definition at line 115 of file NDimensionalExecutor.cxx.

References fCurrentCoords, fMaxBounds, fMinBounds, and fNumDimensions.

Referenced by Execute(), and ExecuteParallel().

◆ InitTcpWorker()

bool Ndmspc::NDimensionalExecutor::InitTcpWorker ( const std::string & identity)
private

Sends INIT to a newly-connected TCP worker, waits for ACK, and registers it in identityToWorker / workerIdentityVec.

Definition at line 420 of file NDimensionalExecutor.cxx.

References HandleBootstrap().

◆ SetBounds()

void Ndmspc::NDimensionalExecutor::SetBounds ( const std::vector< int > & minBounds,
const std::vector< int > & maxBounds )

Definition at line 155 of file NDimensionalExecutor.cxx.

◆ StartProcessIpc()

void Ndmspc::NDimensionalExecutor::StartProcessIpc ( std::vector< NThreadData * > & workerObjects,
size_t processCount,
const std::string & tcpBindEndpoint = "",
const std::string & jobDir = "",
const std::string & treeName = "ngnt",
const std::string & macroList = "",
const std::string & tmpDir = "",
const std::string & tmpResultsDir = "",
const std::string & macroParams = "" )

Definition at line 553 of file NDimensionalExecutor.cxx.

Member Data Documentation

◆ fCurrentCoords

std::vector<int> Ndmspc::NDimensionalExecutor::fCurrentCoords
private

Current coordinates during iteration.

Definition at line 119 of file NDimensionalExecutor.h.

Referenced by Execute(), ExecuteParallel(), Increment(), NDimensionalExecutor(), and NDimensionalExecutor().

◆ fIpcSession

std::unique_ptr<IpcSession> Ndmspc::NDimensionalExecutor::fIpcSession
private

Definition at line 144 of file NDimensionalExecutor.h.

◆ fMaxBounds

std::vector<int> Ndmspc::NDimensionalExecutor::fMaxBounds
private

Maximum bounds for each dimension.

Definition at line 118 of file NDimensionalExecutor.h.

Referenced by GetMaxBounds(), Increment(), NDimensionalExecutor(), and NDimensionalExecutor().

◆ fMinBounds

std::vector<int> Ndmspc::NDimensionalExecutor::fMinBounds
private

Minimum bounds for each dimension.

Definition at line 117 of file NDimensionalExecutor.h.

Referenced by Execute(), ExecuteParallel(), GetMinBounds(), Increment(), NDimensionalExecutor(), and NDimensionalExecutor().

◆ fNumDimensions

size_t Ndmspc::NDimensionalExecutor::fNumDimensions
private

Number of dimensions.

Definition at line 116 of file NDimensionalExecutor.h.

Referenced by Dimensions(), Execute(), ExecuteParallel(), Increment(), NDimensionalExecutor(), and NDimensionalExecutor().

◆ fRegisteredWorkerIndices

std::set<size_t> Ndmspc::NDimensionalExecutor::fRegisteredWorkerIndices
private

Worker indices that completed registration (TCP mode)

Definition at line 145 of file NDimensionalExecutor.h.


The documentation for this class was generated from the following files: