Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
channel.h
Go to the documentation of this file.
1 #ifndef CHANNEL_INCLUDED
2 #define CHANNEL_INCLUDED
3 
4 #include "configure.h"
5 #include "defs.h"
6 
7 #include <cstdio>
8 #include <valarray>
9 #include <vector>
10 #include <cassert>
11 
12 #include "communicator.h"
13 
14 static const int max_dimension = 4;
15 
16 class Channel {
17  public:
18  typedef char element_type;
19  typedef std::valarray<element_type> container_type;
20  enum channel_mode { SEND, RECV };
21  private:
22 
23  /*
24  element_type* m_buf;
25  // container_type m_buf;
26  static std::vector<container_type> m_buf_send;
27  static std::vector<container_type> m_buf_recv;
28  */
29  static std::vector<container_type> m_buf;
30  int m_count;
31  int m_ibuf;
32 
33  struct bgnet_IDs
34  {
35  int fifoID;
36  int sendBufID;
38  int size;
39  int destRank;
40  int groupID;
41  int recvBufID;
43  int counterID;
44  };
45 
47  std::valarray<bgnet_IDs> m_bgnet_ids_thread;
48 
49  static int m_set_id;
50 
51  public:
52 
53  Channel();
54  Channel(const int count);
55  Channel(const int count, const int tag, const channel_mode mode);
56  virtual ~Channel();
57 
58  int start();
59  int wait();
60 
62  static void increment_channel_set_id();
63 
64  void set_thread(int, const std::valarray<int>&,
65  const std::valarray<int>&, const std::valarray<int>&);
66  int start_thread(int);
67  int wait_thread(int);
68 
69  inline element_type& operator[](unsigned int idx)
70  {
71  return m_buf[m_ibuf][idx];
72  }
73 
74  // inline element_type operator[] (unsigned int idx) const { return m_buf[idx]; }
75 
76  inline const element_type *ptr()
77  {
78  return &m_buf[m_ibuf][0];
79  }
80 
81  inline const element_type *ptr(int offset)
82  {
83  return &m_buf[m_ibuf][offset];
84  }
85 
86  friend class Communicator_impl;
87 };
88 
89 #endif /* CHANNEL_INCLUDED */
std::valarray< bgnet_IDs > m_bgnet_ids_thread
Definition: channel.h:47
std::valarray< element_type > container_type
Definition: channel.h:19
int wait()
Definition: channel.cpp:220
bgnet_IDs m_bgnet_ids
Definition: channel.h:46
static const int max_dimension
Definition: channel.h:14
void set_thread(int, const std::valarray< int > &, const std::valarray< int > &, const std::valarray< int > &)
Definition: channel.cpp:40
const element_type * ptr(int offset)
Definition: channel.h:81
int m_count
Definition: channel.h:30
int start()
Definition: channel.cpp:196
int start_thread(int)
Definition: channel.cpp:238
static void increment_channel_set_id()
To be called before defining new set of channels for a operator.
Channel class for asynchronous communication.
Definition: channel.h:16
int wait_thread(int)
Definition: channel.cpp:263
Channel()
Definition: channel.cpp:89
element_type & operator[](unsigned int idx)
Definition: channel.h:69
static std::vector< container_type > m_buf
Definition: channel.h:29
const element_type * ptr()
Definition: channel.h:76
char element_type
Definition: channel.h:18
virtual ~Channel()
Definition: channel.cpp:189
static int m_set_id
identifies set of channels.
Definition: channel.h:49
Implementation of Communicator with BGNET library.
channel_mode
Definition: channel.h:20
int m_ibuf
Definition: channel.h:31