Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NetworkIO.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
28 #ifndef GALOIS_RUNTIME_NETWORKTHREAD_H
29 #define GALOIS_RUNTIME_NETWORKTHREAD_H
30 
31 #include <cstdint>
32 #include <vector>
33 #include <tuple>
34 #include <memory>
35 #include <cassert>
36 #include <cstring>
37 #include <deque>
38 #include <string>
39 #include <fstream>
40 #include <unistd.h>
41 #include <mpi.h>
44 
45 namespace galois {
46 namespace runtime {
47 
52 class NetworkIO {
53 protected:
60  static void handleError(int rc) {
61  if (rc != MPI_SUCCESS) {
62  MPI_Abort(MPI_COMM_WORLD, rc);
63  }
64  }
65 
68 
70  std::atomic<size_t>& inflightSends;
71  std::atomic<size_t>& inflightRecvs;
72 
73  // using vTy = std::vector<uint8_t>;
75 
76 public:
80  struct message {
81  uint32_t host;
82  uint32_t tag;
84 
86  message() : host(~0), tag(~0) {}
90  message(uint32_t h, uint32_t t, vTy&& d)
91  : host(h), tag(t), data(std::move(d)) {}
92 
95  bool valid() const { return !data.empty(); }
96  };
97 
102  NetworkIO(MemUsageTracker& tracker, std::atomic<size_t>& sends,
103  std::atomic<size_t>& recvs)
104  : memUsageTracker(tracker), inflightSends(sends), inflightRecvs(recvs) {}
105 
107  virtual ~NetworkIO();
109  virtual void enqueue(message m) = 0;
113  virtual message dequeue() = 0;
115  virtual void progress() = 0;
116 };
117 
124 std::tuple<std::unique_ptr<NetworkIO>, uint32_t, uint32_t>
126  std::atomic<size_t>& sends, std::atomic<size_t>& recvs);
127 // #ifdef GALOIS_USE_LCI
128 // /**
129 // * Creates/returns a network IO layer that uses LWCI to do communication.
130 // *
131 // * @returns tuple with pointer to the LWCI IO layer, this host's ID, and the
132 // * total number of hosts in the system
133 // */
134 // std::tuple<std::unique_ptr<NetworkIO>, uint32_t, uint32_t>
135 // makeNetworkIOLWCI(galois::runtime::MemUsageTracker& tracker,
136 // std::atomic<size_t>& sends, std::atomic<size_t>& recvs);
137 // #endif
138 
139 } // namespace runtime
140 } // namespace galois
141 
142 #endif
virtual message dequeue()=0
Checks to see if a message is here for this host to receive.
Message structure for sending data across the network.
Definition: NetworkIO.h:80
bool empty() const
Definition: PODResizeableArray.h:127
uint32_t tag
tag on message indicating distinct communication phases
Definition: NetworkIO.h:82
Class that tracks memory usage (mainly of send and receive buffers).
Definition: MemUsage.h:38
virtual void enqueue(message m)=0
Queues a message for sending out. Takes ownership of data buffer.
message()
Default constructor initializes host and tag to large numbers.
Definition: NetworkIO.h:86
MemUsageTracker & memUsageTracker
memory usage tracker
Definition: NetworkIO.h:67
vTy data
data portion of message
Definition: NetworkIO.h:83
Class for the network IO layer which is responsible for doing sends/receives of data.
Definition: NetworkIO.h:52
bool valid() const
A message is valid if there is data to be sent.
Definition: NetworkIO.h:95
virtual ~NetworkIO()
Default destructor does nothing.
Definition: Network.cpp:43
Contains MemUsageTracker, a class that tracks memory usage throughout runtime of a program of send/re...
NetworkIO(MemUsageTracker &tracker, std::atomic< size_t > &sends, std::atomic< size_t > &recvs)
The default constructor takes a memory usage tracker and saves it.
Definition: NetworkIO.h:102
message(uint32_t h, uint32_t t, vTy &&d)
Definition: NetworkIO.h:90
std::atomic< size_t > & inflightRecvs
Definition: NetworkIO.h:71
std::atomic< size_t > & inflightSends
Number of inflight sends and receives.
Definition: NetworkIO.h:70
static void handleError(int rc)
Wrapper for dealing with MPI error codes.
Definition: NetworkIO.h:60
uint32_t host
destination of this message
Definition: NetworkIO.h:81
std::tuple< std::unique_ptr< NetworkIO >, uint32_t, uint32_t > makeNetworkIOMPI(galois::runtime::MemUsageTracker &tracker, std::atomic< size_t > &sends, std::atomic< size_t > &recvs)
Creates/returns a network IO layer that uses MPI to do communication.
Definition: NetworkIOMPI.cpp:239
virtual void progress()=0
Make progress. Other functions don&#39;t have to make progress.