Allium  0.1.0
comm.hpp
1 // Copyright 2020 Hannah Rittich
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ALLIUM_IPC_COMM_HPP
16 #define ALLIUM_IPC_COMM_HPP
17 
18 #include <mpi.h>
19 #include <vector>
20 #include <allium/mesh/range.hpp>
21 
22 namespace allium {
26  class Comm {
27  public:
31  Comm(::MPI_Comm handle);
32 
33  bool operator!= (const Comm& other) {
34  return m_handle != other.m_handle;
35  }
36 
37  static Comm world();
38 
39  int rank() const;
40  int size() const;
41 
42  // === Communicator Management =========================================
43 
44  Comm dup() const;
45  Comm split(int color, int key) const;
46  void free();
47 
48  // === IPC =============================================================
49  void barrier(void);
50 
54  struct RecvInfo {
55  int source;
56  int tag;
57  int elements;
58  };
59 
60  RecvInfo recv(Range<2>& p, int src, int tag);
61  RecvInfo recv(int* data, int max_elements, int src, int tag);
62 
63  void send(const Range<2>& p, int dest, int tag);
64  void send(int* data, int elements, int dest, int tag);
65 
66  std::vector<long long> sum_exscan(std::vector<long long> buf);
67 
68  MPI_Comm handle() { return m_handle; }
69  private:
70  MPI_Comm m_handle;
71  };
72 }
73 
74 #endif
Wraps an MPI communicator to make MPI easier to use.
Definition: comm.hpp:26
Comm(::MPI_Comm handle)
Create a Comm from an MPI_Comm handle.
Definition: comm.cpp:19
An n-d range.
Definition: range.hpp:28
Information about the data that was just received.
Definition: comm.hpp:54