SST/macro
thread_barrier.h
Go to the documentation of this file.
1 #ifndef THREAD_BARRIER_H
2 #define THREAD_BARRIER_H
3 
4 #include <pthread.h>
5 #include <vector>
6 #include <stdint.h>
8 
9 namespace sstmac {
10 namespace native {
11 
13 
14  public:
15  virtual int64_t
16  execute(int64_t) = 0;
17 
18 };
19 
21 
22  public:
23 #ifdef SSTMAC_USE_SPINLOCK
24  typedef pthread_spinlock_t lock_t;
25 #else
27 #endif
28 
29  thread_barrier(int nthread);
30 
32 
33  void
34  start(int me, thread_barrier_functor* functor = 0);
35 
36  int64_t
37  vote(int me, int64_t vote, thread_barrier_functor* functor = 0);
38 
39  void init(int nthread);
40 
41  protected:
42  int64_t
43  run(int me, int level, int nthread, int64_t vote, thread_barrier_functor* functor);
44 
45  void lock(lock_t* l);
46 
47  void unlock(lock_t* l);
48 
49  int init_level(int level, int num, int offset);
50 
51 
52 
53  protected:
54  struct barrier_state {
55  lock_t* in_lock;
56  lock_t* out_lock;
57  int64_t vote;
58  };
59 
60  int nthread_;
61  int twoPowN_;
62  lock_t* out_locks_;
63  lock_t* in_locks_;
64  std::vector<std::vector<barrier_state> > levels_;
65 };
66 
68 {
69  public:
72 
73  private:
74  int next;
75 
76  public:
78  b0(0), b1(0),
79  next(0)
80  {
81  }
82 
83  void
84  start(int me){
85  if (next==0){
86  b0->start(me);
87  } else {
88  b1->start(me);
89  }
90  next=(next+1)%2;
91  }
92 };
93 
94 }
95 }
96 
97 #endif // THREAD_BARRIER_H
std::vector< std::vector< barrier_state > > levels_
virtual int64_t execute(int64_t)=0
#define pthread_mutex_t
parallel_runtime * init()
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
void start(int me, thread_barrier_functor *functor=0)
void run(opts &oo, sstmac::parallel_runtime *rt, sprockit::sim_parameters *params, sim_stats &stats)
#define pthread_spinlock_t