Free Electron
ProxHash.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __spatial_ProxHash_h__
8 #define __spatial_ProxHash_h__
9 
10 #include "signal/signal.h"
11 #include "Proximity.h"
12 
13 #if FE_MT
14 #define FE_PROXHASH_THREADED 1
15 #else
16 #define FE_PROXHASH_THREADED 0
17 #endif
18 
19 #if FE_PROXHASH_THREADED
20 //#include "tbb/tbb.h"
21 #include "tbb/concurrent_vector.h"
22 #include "tbb/blocked_range.h"
23 #include "tbb/spin_mutex.h"
24 #include "tbb/parallel_for.h"
25 //#include "omp.h"
26 #endif
27 
28 
29 namespace fe
30 {
31 namespace ext
32 {
33 
34 // TODO: AJW: clean up the debris here
35 class ProxHash :
36  public Config,
37  virtual public ProxI,
38  public Initialize<ProxHash>
39 {
40  public:
41  ProxHash(void);
42 virtual ~ProxHash(void);
43  void initialize(void);
44 
45  // AS ProxI
46 virtual unsigned int detect( sp<Layout> l_pair,
47  sp<RecordGroup> rg_in,
48  sp<RecordGroup> rg_out);
49 
50  private:
51  class LocalRecord
52  {
53  public:
54  LocalRecord(void) : m_mark(false)
55  {
56  }
57  unsigned int m_index;
58  RecordArray *m_pRA;
59  SpatialVector m_location;
60  Real m_radius;
61  bool m_mark;
62  //std::set<void *> m_candidates;
63  };
64  typedef Array<LocalRecord> t_lrecords;
65 
66  void setup(sp<Scope> spScope);
67  //bool check(LocalRecord &r_a, LocalRecord &r_b);
68  unsigned int hash(int a_x, int a_y, int a_z);
69 public:
70  void checkSingle(unsigned int i, Array<unsigned int> &to_check, std::vector<bool> &mark, Array< std::pair<unsigned int, unsigned int> > &a_hits);
71  void accumulateHits(Array< std::pair<unsigned int, unsigned int> > &a_hits);
72  unsigned int sz() { return m_store.size(); }
73  void transferHitsToPool(Array< std::pair<unsigned int, unsigned int> > &a_hits, FE_UWORD i_pool);
74  FE_UWORD getNextPoolIndex(void);
75 private:
76  bool check(unsigned int a_a, unsigned int a_b, Array< std::pair<unsigned int, unsigned int> > &a_hits);
77  void transferHitsToPool();
78 
79  sp<Scope> m_spScope;
80  AsBounded m_asBounded;
81  AsParticle m_asParticle;
82  AsProximity m_asProximity;
83 
84  Array<BaseAccessor> m_filters;
85 
86  unsigned int m_poolCount;
87  //sp<RecordArray> m_spPool;
88  //FE_UWORD m_poolIndex;
89  Array< sp<RecordArray> > m_spPool;
90  Array< FE_UWORD > m_poolIndex;
91  Array< Array< std::pair<unsigned int, unsigned int> > > m_hits;
92 
93 #if FE_PROXHASH_THREADED
94  tbb::concurrent_vector< std::pair<unsigned int, unsigned int> > m_chits;
95 #else
96  Array< std::pair<unsigned int, unsigned int> > m_chits;
97 #endif
98 
99  Array< Array<unsigned int> > m_cells;
100  Array<LocalRecord> m_store;
101 
102  hp<Layout> m_hpPairLayout;
103 
104  Real m_radius;
105  unsigned int m_tableSize;
106 
107  Array< std::pair<unsigned int, unsigned int> > m_checklist;
108 
109 #if FE_PROXHASH_THREADED
110  tbb::spin_mutex m_mutex;
111 #endif
112 
113 };
114 
115 } /* namespace ext */
116 } /* namespace fe */
117 
118 
119 #endif /* __spatial_ProxHash_h__ */
120 
kernel
Definition: namespace.dox:3