FreeNOS
MpiProxy.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __SERVER_MPIPROXY_MPIPROXY_H
19 #define __SERVER_MPIPROXY_MPIPROXY_H
20 
21 #include <Types.h>
22 #include <Index.h>
23 #include <Memory.h>
24 #include <Array.h>
25 #include <POSIXApplication.h>
26 #include <sys/socket.h>
27 
28 class NetworkClient;
29 class MemoryChannel;
30 
50 class MpiProxy : public POSIXApplication
51 {
52  private:
53 
55  static const u16 UdpPort = 6660;
56 
58  static const Size ReceiveTimeoutMs = 500;
59 
61  static const Size MaximumChannels = 128u;
62 
63  public:
64 
66  static const Size MaximumPacketSize = 1448;
67 
71  enum Operation
72  {
73  MpiOpSend = 0,
77  };
78 
82  struct Header
83  {
88 
89  union
90  {
93  };
95  };
96 
97  public:
98 
105  MpiProxy(int argc, char **argv);
106 
110  virtual ~MpiProxy();
111 
117  virtual Result initialize();
118 
124  virtual Result exec();
125 
126  private:
127 
137  Result udpSend(const void *packet,
138  const Size size,
139  const struct sockaddr & addr) const;
140 
150  Result udpSendMultiple(const struct iovec *vec,
151  const Size count,
152  const struct sockaddr & addr) const;
153 
163  Result udpReceive(void *packet,
164  Size & size,
165  struct sockaddr & addr) const;
166 
176  Result processRequest(const u8 *packet,
177  const Size size,
178  const struct sockaddr & addr);
179 
190  const u8 *packet,
191  const Size size);
192 
204  const u8 *packet,
205  const Size size,
206  const struct sockaddr & addr);
207 
221  const u8 *packet,
222  const Size size,
223  const struct sockaddr & addr);
224 
236  const u8 *packet,
237  const Size size,
238  const struct sockaddr & addr);
239 
248  Result createChannels(const Size rankId,
249  const Size coreCount);
250 
260  Result startLocalProcess(const char *command,
261  const Size rankId,
262  const Size coreCount);
263 
275  const char *command,
276  const Size rankId,
277  const Size coreCount);
278 
279  private:
280 
282  int m_sock;
283 
286 
289 
292 
295 
298 };
299 
305 #endif /* __SERVER_MPIPROXY_MPIPROXY_H */
MpiProxy::udpSend
Result udpSend(const void *packet, const Size size, const struct sockaddr &addr) const
Send UDP packet.
Definition: MpiProxy.cpp:142
MpiProxy::m_client
NetworkClient * m_client
Networking client object.
Definition: MpiProxy.h:285
Memory::Range
Memory range.
Definition: Memory.h:55
MpiProxy::Header::rankId
u16 rankId
Definition: MpiProxy.h:86
Types.h
MpiProxy
Server that bridges IP/UDP to local MPI communication channels.
Definition: MpiProxy.h:50
MpiProxy::processRecv
Result processRecv(const Header *header, const u8 *packet, const Size size, const struct sockaddr &addr)
Process MPI recv request.
Definition: MpiProxy.cpp:295
MpiProxy::Header::coreId
u16 coreId
Definition: MpiProxy.h:87
MpiProxy::m_sock
int m_sock
IP/UDP socket for external communication.
Definition: MpiProxy.h:282
Index.h
MpiProxy::MaximumChannels
static const Size MaximumChannels
Maximum number of supported MPI channels.
Definition: MpiProxy.h:61
MpiProxy::processRequest
Result processRequest(const u8 *packet, const Size size, const struct sockaddr &addr)
Process incoming packet.
Definition: MpiProxy.cpp:222
MpiProxy::MpiOpExec
@ MpiOpExec
Definition: MpiProxy.h:75
Index< MemoryChannel, MaximumChannels >
POSIXApplication
POSIX-compatible application.
Definition: POSIXApplication.h:35
Array.h
MpiProxy::processTerminate
Result processTerminate(const Header *header, const u8 *packet, const Size size, const struct sockaddr &addr)
Process MPI terminate request.
Definition: MpiProxy.cpp:435
MpiProxy::udpReceive
Result udpReceive(void *packet, Size &size, struct sockaddr &addr) const
Receive UDP packet.
Definition: MpiProxy.cpp:185
MpiProxy::startRemoteProcess
Result startRemoteProcess(const Size coreId, const char *command, const Size rankId, const Size coreCount)
Start a process on a secondary processor.
Definition: MpiProxy.cpp:642
sockaddr
Defines a socket address and port pair.
Definition: socket.h:35
Array< ProcessID, MaximumChannels >
MpiProxy::MaximumPacketSize
static const Size MaximumPacketSize
Maximum size of packet payload.
Definition: MpiProxy.h:66
MpiProxy::m_pids
Array< ProcessID, MaximumChannels > m_pids
Records the PID of each process participating in the computation.
Definition: MpiProxy.h:297
MpiProxy::MpiProxy
MpiProxy(int argc, char **argv)
Constructor.
Definition: MpiProxy.cpp:42
MpiProxy::Header
Packet payload header for MPI messages via IP/UDP.
Definition: MpiProxy.h:82
POSIXApplication.h
header
SystemDescriptorHeader header
Definition: IntelACPI.h:63
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h:56
MpiProxy::Header::datatype
u16 datatype
Definition: MpiProxy.h:92
MpiProxy::createChannels
Result createChannels(const Size rankId, const Size coreCount)
Create communication channels.
Definition: MpiProxy.cpp:496
MpiProxy::ReceiveTimeoutMs
static const Size ReceiveTimeoutMs
Timeout in milliseconds to wait for packet receive.
Definition: MpiProxy.h:58
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
MpiProxy::m_readChannels
Index< MemoryChannel, MaximumChannels > m_readChannels
Stores all channels for receiving data from processes.
Definition: MpiProxy.h:291
Application::Result
Result
Result codes.
Definition: Application.h:53
MpiProxy::MpiOpRecv
@ MpiOpRecv
Definition: MpiProxy.h:74
MemoryChannel
Unidirectional point-to-point channel using shared memory.
Definition: MemoryChannel.h:43
NetworkClient
Networking Client implementation.
Definition: NetworkClient.h:44
MpiProxy::startLocalProcess
Result startLocalProcess(const char *command, const Size rankId, const Size coreCount)
Start a process on the local processor.
Definition: MpiProxy.cpp:580
iovec
Input/Output vector for multi-packet operations.
Definition: socket.h:44
MpiProxy::~MpiProxy
virtual ~MpiProxy()
Destructor.
Definition: MpiProxy.cpp:54
MpiProxy::Header::datacount
u32 datacount
Definition: MpiProxy.h:94
Memory.h
MpiProxy::processExec
Result processExec(const Header *header, const u8 *packet, const Size size, const struct sockaddr &addr)
Process execute request.
Definition: MpiProxy.cpp:384
MpiProxy::MpiOpTerminate
@ MpiOpTerminate
Definition: MpiProxy.h:76
MpiProxy::Header::result
u8 result
Definition: MpiProxy.h:85
MpiProxy::processSend
Result processSend(const Header *header, const u8 *packet, const Size size)
Process MPI send request.
Definition: MpiProxy.cpp:252
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
MpiProxy::exec
virtual Result exec()
Run the server.
Definition: MpiProxy.cpp:109
MpiProxy::Header::coreCount
u16 coreCount
Definition: MpiProxy.h:91
socket.h
MpiProxy::Header::operation
u8 operation
Definition: MpiProxy.h:84
MpiProxy::MpiOpSend
@ MpiOpSend
Definition: MpiProxy.h:73
MpiProxy::UdpPort
static const u16 UdpPort
Port number for IP/UDP traffic.
Definition: MpiProxy.h:55
MpiProxy::m_memChannelBase
Memory::Range m_memChannelBase
Memory base address for local MPI communication.
Definition: MpiProxy.h:288
coreId
u8 coreId
Definition: IntelACPI.h:64
MpiProxy::Operation
Operation
Encodes various MPI operations.
Definition: MpiProxy.h:71
MpiProxy::initialize
virtual Result initialize()
Initialize the server.
Definition: MpiProxy.cpp:64
MpiProxy::m_writeChannels
Index< MemoryChannel, MaximumChannels > m_writeChannels
Stores all channels for sending data to processes.
Definition: MpiProxy.h:294
MpiProxy::udpSendMultiple
Result udpSendMultiple(const struct iovec *vec, const Size count, const struct sockaddr &addr) const
Send multiple UDP packets.
Definition: MpiProxy.cpp:160