FreeNOS
MpiHost.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 __LIB_LIBMPI_MPIHOST_H
19 #define __LIB_LIBMPI_MPIHOST_H
20 
21 #include <arpa/inet.h>
22 #include <netinet/in.h>
23 #include <Types.h>
24 #include <Index.h>
25 #include <List.h>
26 #include "MpiBackend.h"
27 
39 class MpiHost : public MpiBackend
40 {
41  private:
42 
44  static const Size MaximumNodes = 512;
45 
46  private:
47 
51  struct Node
52  {
53  in_addr_t ipAddress;
56  };
57 
61  struct Packet
62  {
63  u8 *data;
65  };
66 
67  public:
68 
72  MpiHost();
73 
82  virtual Result initialize(int *argc,
83  char ***argv);
84 
90  virtual Result terminate();
91 
100  virtual Result getCommRank(MPI_Comm comm,
101  int *rank);
102 
111  virtual Result getCommSize(MPI_Comm comm,
112  int *size);
113 
126  virtual Result send(const void *buf,
127  int count,
128  MPI_Datatype datatype,
129  int dest,
130  int tag,
131  MPI_Comm comm);
132 
146  virtual Result receive(void *buf,
147  int count,
148  MPI_Datatype datatype,
149  int source,
150  int tag,
151  MPI_Comm comm,
152  MPI_Status *status);
153 
154  private:
155 
163  Result parseHostsFile(const char *hostsfile);
164 
173  Result startProcesses(int argc,
174  char **argv);
175 
185  Result sendPacket(const Size nodeId,
186  const void *packet,
187  const Size size) const;
188 
199  Result receivePacket(const Size nodeId,
200  const MpiProxy::Operation operation,
201  void *packet,
202  Size & size);
203 
204  private:
205 
207  int m_sock;
208 
211 
214 };
215 
221 #endif /* __LIB_LIBMPI_MPIHOST_H */
MpiHost::m_nodes
Index< Node, MaximumNodes > m_nodes
Contains all known nodes that participate in the computation.
Definition: MpiHost.h:210
MpiHost::Packet::data
u8 * data
Definition: MpiHost.h:63
Types.h
MpiHost::receivePacket
Result receivePacket(const Size nodeId, const MpiProxy::Operation operation, void *packet, Size &size)
Receive UDP packet from remote node.
Definition: MpiHost.cpp:537
MPI_Comm
uint MPI_Comm
Communicator identifier.
Definition: mpi.h:38
MpiHost::initialize
virtual Result initialize(int *argc, char ***argv)
Initialize the backend.
Definition: MpiHost.cpp:41
Index.h
MpiBackend::Result
int Result
Result code.
Definition: MpiBackend.h:47
Index
Index is a N-sized array of pointers to items of type T.
Definition: Index.h:36
MpiHost::startProcesses
Result startProcesses(int argc, char **argv)
Start remote processes.
Definition: MpiHost.cpp:418
MpiHost::Packet::size
Size size
< Payload data
Definition: MpiHost.h:64
MpiHost
Implements a MPI backend for the host OS which communicates with mpiproxy servers.
Definition: MpiHost.h:39
MPI_Status
uint MPI_Status
Status holder.
Definition: mpi.h:41
MpiHost::receive
virtual Result receive(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
Synchronous receive data.
Definition: MpiHost.cpp:236
MpiHost::sendPacket
Result sendPacket(const Size nodeId, const void *packet, const Size size) const
Send UDP packet to a remote node.
Definition: MpiHost.cpp:506
MpiHost::Node::udpPort
u16 udpPort
< IP address of the node
Definition: MpiHost.h:54
MpiBackend.h
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h:56
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
MpiHost::send
virtual Result send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
Synchronous send data.
Definition: MpiHost.cpp:170
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
MpiHost::Node
Describes a remote CPU node accessible via MPI.
Definition: MpiHost.h:51
MPI_Datatype
MPI_Datatype
Named Predefined Datatypes.
Definition: mpi.h:46
MpiHost::MpiHost
MpiHost()
Constructor.
Definition: MpiHost.cpp:37
MpiHost::m_packetBuffers
Index< List< Packet * >, MaximumNodes > m_packetBuffers
Buffers incoming packets for later processing.
Definition: MpiHost.h:213
MpiHost::m_sock
int m_sock
UDP socket for communicating with remote nodes.
Definition: MpiHost.h:207
MpiBackend
Represents a Message Passing Interface (MPI) implementation backend.
Definition: MpiBackend.h:36
MpiHost::terminate
virtual Result terminate()
Terminate the backend.
Definition: MpiHost.cpp:105
MpiHost::Node::ipAddress
in_addr_t ipAddress
Definition: MpiHost.h:53
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
MpiHost::Node::coreId
u32 coreId
< UDP port of the node
Definition: MpiHost.h:55
MpiHost::Packet
Describes data received via UDP.
Definition: MpiHost.h:61
MpiHost::getCommSize
virtual Result getCommSize(MPI_Comm comm, int *size)
Retrieve communication size (total cores)
Definition: MpiHost.cpp:163
MpiProxy::Operation
Operation
Encodes various MPI operations.
Definition: MpiProxy.h:71
MpiHost::parseHostsFile
Result parseHostsFile(const char *hostsfile)
Parse the given hosts file.
Definition: MpiHost.cpp:315
MpiHost::getCommRank
virtual Result getCommRank(MPI_Comm comm, int *rank)
Retrieve communication rank (core id)
Definition: MpiHost.cpp:156
List.h
MpiHost::MaximumNodes
static const Size MaximumNodes
Maximum number of supported nodes.
Definition: MpiHost.h:44