AGX Dynamics  2.35.0.1
ParallelRaContainerKernel.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agx/Kernel.h>
20 
21 namespace agx
22 {
23  template<typename T, typename argument_type = typename T::const_reference>
25  {
26  public:
33  virtual void doExecute( const T* container );
34 
35  protected:
40  ParallelRaContainerKernel( const agx::Name& name );
41 
45  agx::UInt getNumElements() const;
46 
51  const T* getContainer() const;
52 
53  protected:
57  virtual void onPreExecute();
58 
64  virtual void onElement( agx::UInt index, argument_type element ) = 0;
65 
69  virtual void onPostExecute();
70 
71  private:
73  ParallelRaContainerKernel<T>& operator=( const ParallelRaContainerKernel<T>& ) = delete;
74 
80 
84  void executeJob( const agx::RangeJob& job );
85 
86  private:
87  const T* m_container;
88  };
89 
90  template<typename T, typename argument_type>
92  : LambdaKernel( name,
93  std::bind( &ParallelRaContainerKernel<T, argument_type>::executeJob, this, std::placeholders::_1 ),
94  std::bind( &ParallelRaContainerKernel<T, argument_type>::getNumElements, this ) ),
95  m_container( nullptr )
96  {
97  }
98 
99  template<typename T, typename argument_type>
101  {
102  return m_container != nullptr ? agx::UInt( m_container->size() ) : agx::UInt( 0 );
103  }
104 
105  template<typename T, typename argument_type>
107  {
108  return m_container;
109  }
110 
111  template<typename T, typename argument_type>
113  {
114  }
115 
116  template<typename T, typename argument_type>
118  {
119  m_container = container;
120  if ( m_container != nullptr ) {
121  onPreExecute();
123  onPostExecute();
124  }
125  m_container = nullptr;
126  }
127 
128  template<typename T, typename argument_type>
130  {
131  }
132 
133  template<typename T, typename argument_type>
135  {
136  for ( agx::UInt i = job.range().begin(), end = job.range().end(); i != end; ++i )
137  onElement( i, const_cast<T&>(*m_container)[ i ] );
138  }
139 }
Representation of a name string.
Definition: Name.h:33
ParallelRaContainerKernel(const agx::Name &name)
Construct given name.
virtual void onPostExecute()
Callback after the kernel (onElement callback) is executed.
virtual void onElement(agx::UInt index, argument_type element)=0
Callback with current element.
virtual void doExecute(const T *container)
Execute the jobs (blocking mode) given container.
virtual void onPreExecute()
Callback before the kernel (onElement callback) is executed.
A range job executes a kernel implementation on a subset of the data.
Definition: Job.h:284
IndexRange & range()
Definition: Job.h:631
void execute()
Execute the task.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt
Definition: Integer.h:34
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)