LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * This program is free software; you can redistribute it and/or modify | 3 * This program is free software; you can redistribute it and/or modify |
4 * it under the terms of the GNU General Public License version 2 as | 4 * it under the terms of the GNU General Public License version 2 as |
5 * published by the Free Software Foundation; | 5 * published by the Free Software Foundation; |
6 * | 6 * |
7 * This program is distributed in the hope that it will be useful, | 7 * This program is distributed in the hope that it will be useful, |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 * GNU General Public License for more details. | 10 * GNU General Public License for more details. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 #ifdef NS3_MPI | 64 #ifdef NS3_MPI |
65 MPI_Request* | 65 MPI_Request* |
66 SentBuffer::GetRequest () | 66 SentBuffer::GetRequest () |
67 { | 67 { |
68 return &m_request; | 68 return &m_request; |
69 } | 69 } |
70 #endif | 70 #endif |
71 | 71 |
72 uint32_t MPIInterface::m_rank = 0; | 72 uint32_t MpiInterface::m_sid = 0; |
73 uint32_t MPIInterface::m_size = 1; | 73 uint32_t MpiInterface::m_size = 1; |
74 bool MPIInterface::m_initialized = false; | 74 bool MpiInterface::m_initialized = false; |
75 bool MPIInterface::m_enabled = false; | 75 bool MpiInterface::m_enabled = false; |
76 uint32_t MPIInterface::m_rxCount = 0; | 76 uint32_t MpiInterface::m_rxCount = 0; |
77 uint32_t MPIInterface::m_txCount = 0; | 77 uint32_t MpiInterface::m_txCount = 0; |
78 std::list<SentBuffer> MPIInterface::m_pendingTx; | 78 std::list<SentBuffer> MpiInterface::m_pendingTx; |
79 | 79 |
80 #ifdef NS3_MPI | 80 #ifdef NS3_MPI |
81 MPI_Request* MPIInterface::m_requests; | 81 MPI_Request* MpiInterface::m_requests; |
82 char** MPIInterface::m_pRxBuffers; | 82 char** MpiInterface::m_pRxBuffers; |
83 #endif | 83 #endif |
84 | 84 |
85 void | 85 void |
86 MPIInterface::Destroy () | 86 MpiInterface::Destroy () |
87 { | 87 { |
88 #ifdef NS3_MPI | 88 #ifdef NS3_MPI |
89 for (uint32_t i = 0; i < Size (); ++i) | 89 for (uint32_t i = 0; i < GetSize (); ++i) |
90 { | 90 { |
91 delete [] m_pRxBuffers[i]; | 91 delete [] m_pRxBuffers[i]; |
92 } | 92 } |
93 delete [] m_pRxBuffers; | 93 delete [] m_pRxBuffers; |
94 delete [] m_requests; | 94 delete [] m_requests; |
95 | 95 |
96 m_pendingTx.clear (); | 96 m_pendingTx.clear (); |
97 #endif | 97 #endif |
98 } | 98 } |
99 | 99 |
100 uint32_t | 100 uint32_t |
101 MPIInterface::GetRxCount () | 101 MpiInterface::GetRxCount () |
102 { | 102 { |
103 return m_rxCount; | 103 return m_rxCount; |
104 } | 104 } |
105 | 105 |
106 uint32_t | 106 uint32_t |
107 MPIInterface::GetTxCount () | 107 MpiInterface::GetTxCount () |
108 { | 108 { |
109 return m_txCount; | 109 return m_txCount; |
110 } | 110 } |
111 | 111 |
112 uint32_t | 112 uint32_t |
113 MPIInterface::Rank () | 113 MpiInterface::GetSystemId () |
114 { | 114 { |
115 if (!m_initialized) | 115 if (!m_initialized) |
116 { | 116 { |
117 Simulator::GetImplementation (); | 117 Simulator::GetImplementation (); |
118 m_initialized = true; | 118 m_initialized = true; |
119 } | 119 } |
120 return m_rank; | 120 return m_sid; |
121 } | 121 } |
122 | 122 |
123 uint32_t | 123 uint32_t |
124 MPIInterface::Size () | 124 MpiInterface::GetSize () |
125 { | 125 { |
126 if (!m_initialized) | 126 if (!m_initialized) |
127 { | 127 { |
128 Simulator::GetImplementation (); | 128 Simulator::GetImplementation (); |
129 m_initialized = true; | 129 m_initialized = true; |
130 } | 130 } |
131 return m_size; | 131 return m_size; |
132 } | 132 } |
133 | 133 |
134 bool | 134 bool |
135 MPIInterface::IsEnabled () | 135 MpiInterface::IsEnabled () |
136 { | 136 { |
137 if (!m_initialized) | 137 if (!m_initialized) |
138 { | 138 { |
139 Simulator::GetImplementation (); | 139 Simulator::GetImplementation (); |
140 m_initialized = true; | 140 m_initialized = true; |
141 } | 141 } |
142 return m_enabled; | 142 return m_enabled; |
143 } | 143 } |
144 | 144 |
145 void | 145 void |
146 MPIInterface::Enable (int* pargc, char*** pargv) | 146 MpiInterface::Enable (int* pargc, char*** pargv) |
147 { | 147 { |
148 #ifdef NS3_MPI | 148 #ifdef NS3_MPI |
149 // Initialize the MPI interface | 149 // Initialize the MPI interface |
150 MPI_Init (pargc, pargv); | 150 MPI_Init (pargc, pargv); |
151 MPI_Barrier (MPI_COMM_WORLD); | 151 MPI_Barrier (MPI_COMM_WORLD); |
152 MPI_Comm_rank (MPI_COMM_WORLD, (int*)&m_rank); | 152 MPI_Comm_rank (MPI_COMM_WORLD, (int*)&m_sid); |
153 MPI_Comm_size (MPI_COMM_WORLD, (int*)&m_size); | 153 MPI_Comm_size (MPI_COMM_WORLD, (int*)&m_size); |
154 m_enabled = true; | 154 m_enabled = true; |
155 m_initialized = true; | 155 m_initialized = true; |
156 // Post a non-blocking receive for all peers | 156 // Post a non-blocking receive for all peers |
157 m_pRxBuffers = new char*[m_size]; | 157 m_pRxBuffers = new char*[m_size]; |
158 m_requests = new MPI_Request[m_size]; | 158 m_requests = new MPI_Request[m_size]; |
159 for (uint32_t i = 0; i < Size (); ++i) | 159 for (uint32_t i = 0; i < GetSize (); ++i) |
160 { | 160 { |
161 m_pRxBuffers[i] = new char[MAX_MPI_MSG_SIZE]; | 161 m_pRxBuffers[i] = new char[MAX_MPI_MSG_SIZE]; |
162 MPI_Irecv (m_pRxBuffers[i], MAX_MPI_MSG_SIZE, MPI_CHAR, MPI_ANY_SOURCE, 0, | 162 MPI_Irecv (m_pRxBuffers[i], MAX_MPI_MSG_SIZE, MPI_CHAR, MPI_ANY_SOURCE, 0, |
163 MPI_COMM_WORLD, &m_requests[i]); | 163 MPI_COMM_WORLD, &m_requests[i]); |
164 } | 164 } |
165 #else | 165 #else |
166 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); | 166 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); |
167 #endif | 167 #endif |
168 } | 168 } |
169 | 169 |
170 void | 170 void |
171 MPIInterface::SendPacket (Ptr<Packet> p, const Time& rxTime, uint32_t node, uint
32_t dev) | 171 MpiInterface::SendPacket (Ptr<Packet> p, const Time& rxTime, uint32_t node, uint
32_t dev) |
172 { | 172 { |
173 #ifdef NS3_MPI | 173 #ifdef NS3_MPI |
174 SentBuffer sendBuf; | 174 SentBuffer sendBuf; |
175 m_pendingTx.push_back (sendBuf); | 175 m_pendingTx.push_back (sendBuf); |
176 std::list<SentBuffer>::reverse_iterator i = m_pendingTx.rbegin (); // Points t
o the last element | 176 std::list<SentBuffer>::reverse_iterator i = m_pendingTx.rbegin (); // Points t
o the last element |
177 | 177 |
178 uint32_t serializedSize = p->GetSerializedSize (); | 178 uint32_t serializedSize = p->GetSerializedSize (); |
179 uint8_t* buffer = new uint8_t[serializedSize + 16]; | 179 uint8_t* buffer = new uint8_t[serializedSize + 16]; |
180 i->SetBuffer (buffer); | 180 i->SetBuffer (buffer); |
181 // Add the time, dest node and dest device | 181 // Add the time, dest node and dest device |
(...skipping 12 matching lines...) Expand all Loading... |
194 | 194 |
195 MPI_Isend ((void*)i->GetBuffer (), serializedSize + 16, MPI_CHAR, nodeSysId, | 195 MPI_Isend ((void*)i->GetBuffer (), serializedSize + 16, MPI_CHAR, nodeSysId, |
196 0, MPI_COMM_WORLD, (i->GetRequest ())); | 196 0, MPI_COMM_WORLD, (i->GetRequest ())); |
197 m_txCount++; | 197 m_txCount++; |
198 #else | 198 #else |
199 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); | 199 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); |
200 #endif | 200 #endif |
201 } | 201 } |
202 | 202 |
203 void | 203 void |
204 MPIInterface::ReceiveMessages () | 204 MpiInterface::ReceiveMessages () |
205 { // Poll the non-block reads to see if data arrived | 205 { // Poll the non-block reads to see if data arrived |
206 #ifdef NS3_MPI | 206 #ifdef NS3_MPI |
207 while (true) | 207 while (true) |
208 { | 208 { |
209 int flag = 0; | 209 int flag = 0; |
210 int index = 0; | 210 int index = 0; |
211 MPI_Status status; | 211 MPI_Status status; |
212 | 212 |
213 MPI_Testany (Size (), m_requests, &index, &flag, &status); | 213 MPI_Testany (GetSize (), m_requests, &index, &flag, &status); |
214 if (!flag) | 214 if (!flag) |
215 { | 215 { |
216 break; // No more messages | 216 break; // No more messages |
217 } | 217 } |
218 int count; | 218 int count; |
219 MPI_Get_count (&status, MPI_CHAR, &count); | 219 MPI_Get_count (&status, MPI_CHAR, &count); |
220 m_rxCount++; // Count this receive | 220 m_rxCount++; // Count this receive |
221 | 221 |
222 // Get the meta data first | 222 // Get the meta data first |
223 uint64_t* pTime = (uint64_t*)m_pRxBuffers[index]; | 223 uint64_t* pTime = (uint64_t*)m_pRxBuffers[index]; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // Re-queue the next read | 256 // Re-queue the next read |
257 MPI_Irecv (m_pRxBuffers[index], MAX_MPI_MSG_SIZE, MPI_CHAR, MPI_ANY_SOURCE
, 0, | 257 MPI_Irecv (m_pRxBuffers[index], MAX_MPI_MSG_SIZE, MPI_CHAR, MPI_ANY_SOURCE
, 0, |
258 MPI_COMM_WORLD, &m_requests[index]); | 258 MPI_COMM_WORLD, &m_requests[index]); |
259 } | 259 } |
260 #else | 260 #else |
261 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); | 261 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); |
262 #endif | 262 #endif |
263 } | 263 } |
264 | 264 |
265 void | 265 void |
266 MPIInterface::TestSendComplete () | 266 MpiInterface::TestSendComplete () |
267 { | 267 { |
268 #ifdef NS3_MPI | 268 #ifdef NS3_MPI |
269 std::list<SentBuffer>::iterator i = m_pendingTx.begin (); | 269 std::list<SentBuffer>::iterator i = m_pendingTx.begin (); |
270 while (i != m_pendingTx.end ()) | 270 while (i != m_pendingTx.end ()) |
271 { | 271 { |
272 MPI_Status status; | 272 MPI_Status status; |
273 int flag = 0; | 273 int flag = 0; |
274 MPI_Test (i->GetRequest (), &flag, &status); | 274 MPI_Test (i->GetRequest (), &flag, &status); |
275 std::list<SentBuffer>::iterator current = i; // Save current for erasing | 275 std::list<SentBuffer>::iterator current = i; // Save current for erasing |
276 i++; // Advance to next | 276 i++; // Advance to next |
277 if (flag) | 277 if (flag) |
278 { // This message is complete | 278 { // This message is complete |
279 m_pendingTx.erase (current); | 279 m_pendingTx.erase (current); |
280 } | 280 } |
281 } | 281 } |
282 #else | 282 #else |
283 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); | 283 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); |
284 #endif | 284 #endif |
285 } | 285 } |
286 | 286 |
287 } // namespace ns3 | 287 } // namespace ns3 |
LEFT | RIGHT |