Bridge++  Ver. 1.1.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
channel.cpp
Go to the documentation of this file.
1 
14 #include "communicator_mpi.h"
15 #include "layout.h"
16 #include "channel.h"
17 
25 Channel *Communicator_impl::send_init(int count, int idir, int ipm)
26 {
27  LOG;
28 
29  assert(ipm == 1 || ipm == -1);
30  assert(Layout::m_ndim <= max_dimension);
31 
32  Channel *ch = new Channel(count);
33  if (!ch) {
34 #ifdef DEBUG
35  printf("%s: allocate channel failed.\n", __func__);
36 #endif
37  abort();
38  }
39 
40  int dest = (ipm == Forward) ? Layout::m_ipe_up[idir] : Layout::m_ipe_dn[idir];
41  int tag = idir + max_dimension * (((ipm == Forward) ? 0 : 1) + 2 * m_grid_rank);
42 
43  int retv = MPI_Send_init((void *)&ch->m_buf[0], sizeof(Channel::element_type) * count, MPI_BYTE, dest, tag, m_comm, &ch->m_request);
44 
45  if (retv != MPI_SUCCESS) {
46  return (Channel *)0;
47  }
48 
49  return ch;
50 }
51 
52 
60 Channel *Communicator_impl::recv_init(int count, int idir, int ipm)
61 {
62  LOG;
63 
64  assert(ipm == 1 || ipm == -1);
65  assert(Layout::m_ndim <= max_dimension);
66 
67  Channel *ch = new Channel(count);
68  if (!ch) {
69 #ifdef DEBUG
70  printf("%s: allocate channel failed.\n", __func__);
71 #endif
72  abort();
73  }
74 
75  int src = (ipm == Forward) ? Layout::m_ipe_up[idir] : Layout::m_ipe_dn[idir];
76  int tag = idir + max_dimension * (((ipm == Forward) ? 1 : 0) + 2 * src);
77 
78  int retv = MPI_Recv_init((void *)&ch->m_buf[0], sizeof(Channel::element_type) * count, MPI_BYTE, src, tag, m_comm, &ch->m_request);
79 
80  if (retv != MPI_SUCCESS) {
81  return (Channel *)0;
82  }
83 
84  return ch;
85 }
86 
87 
88 // class Channel
89 Channel::Channel() : m_buf(0)
90 {
91  LOG;
92 }
93 
94 
95 Channel::Channel(const int count) : m_buf(count)
96 {
97  LOG;
98 }
99 
100 
102 {
103  LOG;
104 }
105 
106 
108 {
109  LOG;
110  return MPI_Start(&m_request);
111 }
112 
113 
115 {
116  LOG;
117  return MPI_Wait(&m_request, &m_status);
118 }
119 
120 
121 // class ChannelSet
122 ChannelSet::ChannelSet(int count) : m_array(count), m_nreq(0)
123 {
124  LOG;
125 }
126 
127 
129 {
130  LOG;
131 
132  if (m_nreq >= m_array.size()) {
133  return MPI_ERR_BUFFER;
134  }
135  m_array[m_nreq++] = p->m_request; //* need grant access to private data of channel class.
136 
137  return MPI_SUCCESS;
138 }
139 
140 
142 {
143  LOG;
144  return MPI_Startall(m_nreq, &m_array[0]);
145 }
146 
147 
149 {
150  LOG;
151  return MPI_Waitall(m_nreq, &m_array[0], (MPI_Status *)0);
152 }