Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
channel.cpp
Go to the documentation of this file.
1 
14 #include "channel.h"
15 
16 //====================================================================
17 Channel *Communicator::send_init(int count, int idir, int ipm)
18 {
19  LOG;
20 
21  assert(ipm == 1 || ipm == -1);
22 
23  Channel *ch = new Channel(count);
24  if (!ch) {
25  printf("%s: allocate channel failed.\n", __func__);
26  exit(EXIT_FAILURE);
27  }
28 
29  return ch;
30 }
31 
32 
33 //====================================================================
34 Channel *Communicator::recv_init(int count, int idir, int ipm)
35 {
36  LOG;
37 
38  assert(ipm == 1 || ipm == -1);
39 
40  Channel *ch = new Channel(count);
41  if (!ch) {
42  printf("%s: allocate channel failed.\n", __func__);
43  exit(EXIT_FAILURE);
44  }
45 
46  return ch;
47 }
48 
49 
50 //====================================================================
51 Channel *Communicator::send_init(int count, int idir, int ipm, void *buf)
52 {
53  LOG;
54 
55  assert(ipm == 1 || ipm == -1);
56 
57  Channel *ch = new Channel(buf);
58  if (!ch) {
59  printf("%s: allocate channel failed.\n", __func__);
60  exit(EXIT_FAILURE);
61  }
62 
63  return ch;
64 }
65 
66 
67 //====================================================================
68 Channel *Communicator::recv_init(int count, int idir, int ipm, void *buf)
69 {
70  LOG;
71 
72  assert(ipm == 1 || ipm == -1);
73 
74  Channel *ch = new Channel(buf);
75  if (!ch) {
76  printf("%s: allocate channel failed.\n", __func__);
77  exit(EXIT_FAILURE);
78  }
79 
80  return ch;
81 }
82 
83 
84 //====================================================================
85 // class Channel
87  : m_buf(NULL),
88  m_my_buf(false)
89 {
90 }
91 
92 
93 Channel::Channel(void *buf)
94  : m_buf(reinterpret_cast<element_type *>(buf)),
95  m_my_buf(false)
96 {
97 }
98 
99 
100 Channel::Channel(const int count)
101 {
102  m_buf = new element_type[count];
103  m_my_buf = true;
104 }
105 
106 
108 {
109  if (m_my_buf) delete [] m_buf;
110 
111  m_buf = NULL;
112  m_my_buf = false;
113 }
114 
115 
116 //====================================================================
117 int Channel::start()
118 {
119  return 0;
120 }
121 
122 
123 //====================================================================
124 int Channel::wait()
125 {
126  return 0;
127 }
128 
129 
130 //====================================================================
131 // class ChannelSet
132 ChannelSet::ChannelSet(int count)
133 {
134  LOG;
135 }
136 
137 
138 //====================================================================
140 {
141  return 0;
142 }
143 
144 
145 //====================================================================
146 int ChannelSet::start()
147 {
148  return 0;
149 }
150 
151 
152 //====================================================================
153 int ChannelSet::wait()
154 {
155  return 0;
156 }
157 
158 
159 //====================================================================
160 //============================================================END=====
int wait()
wait for completion
Definition: channel.cpp:122
int start()
collective start
Definition: channel.cpp:153
int start()
start asynchronous communication
Definition: channel.cpp:114
static Channel * recv_init(int count, int idir, int ipm)
bool m_my_buf
whether buffer is owned by this instance.
Definition: channel.h:70
container_type m_buf
buffer
Definition: channel.h:68
int append(Channel *const p)
append channel to the set. there is no way to remove a channel.
Definition: channel.cpp:139
Channel class for asynchronous communication.
Definition: channel.h:48
#define LOG
Definition: bridge_defs.h:21
Channel()
constructor.
Definition: channel.cpp:95
int wait()
collective wait
Definition: channel.cpp:161
char element_type
data transfer is byte-wise.
Definition: channel.h:50
virtual ~Channel()
destructor
Definition: channel.cpp:107
static Channel * send_init(int count, int idir, int ipm)
ChannelSet(int nchannel=8)
constructor. default number of channels is 8 for upward and downward in 4 dimensions.
Definition: channel.cpp:131