Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
comm.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Multiscale Universal Interface Code Coupling Library *
3 * *
4 * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis *
5 * *
6 * This software is jointly licensed under the Apache License, Version 2.0 *
7 * and the GNU General Public License version 3, you may use it according *
8 * to either. *
9 * *
10 * ** Apache License, version 2.0 ** *
11 * *
12 * Licensed under the Apache License, Version 2.0 (the "License"); *
13 * you may not use this file except in compliance with the License. *
14 * You may obtain a copy of the License at *
15 * *
16 * http://www.apache.org/licenses/LICENSE-2.0 *
17 * *
18 * Unless required by applicable law or agreed to in writing, software *
19 * distributed under the License is distributed on an "AS IS" BASIS, *
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
21 * See the License for the specific language governing permissions and *
22 * limitations under the License. *
23 * *
24 * ** GNU General Public License, version 3 ** *
25 * *
26 * This program is free software: you can redistribute it and/or modify *
27 * it under the terms of the GNU General Public License as published by *
28 * the Free Software Foundation, either version 3 of the License, or *
29 * (at your option) any later version. *
30 * *
31 * This program is distributed in the hope that it will be useful, *
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
34 * GNU General Public License for more details. *
35 * *
36 * You should have received a copy of the GNU General Public License *
37 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
38 *****************************************************************************/
39 
48 #ifndef COMM_H_
49 #define COMM_H_
50 
51 #include <vector>
52 #include "message/message.h"
53 
54 namespace mui {
55 class communicator {
56 private:
57  // Comm is not copyable.
58  communicator( const communicator& ) = delete;
59  communicator& operator=( const communicator& ) = delete;
60 public:
62  virtual ~communicator() {}
63 
64  virtual int local_rank() const { return 0; }
65  virtual int local_size() const { return 1; }
66  virtual int remote_size() const { return 1; }
67  virtual std::string uri_host() const { return std::string(); }
68  virtual std::string uri_path() const { return std::string(); }
69  virtual std::string uri_protocol() const { return std::string(); }
70 
71  // send message
72  void send( message msg, const std::vector<bool> &is_sending ) {
73  if( is_sending.size() == static_cast<size_t>(remote_size()) )
74  return send_impl_(std::move(msg), is_sending);
75  else {
76  std::vector<bool> dest = is_sending;
77  dest.resize(remote_size(), true);
78  return send_impl_(std::move(msg), dest);
79  }
80  }
81  void send( message msg ) {
82  std::vector<bool> is_sending(remote_size(),true);
83  return send_impl_(std::move(msg),is_sending);
84  }
85 
86  // recv messages
88  return recv_impl_();
89  }
90 
91 
92 protected:
93  virtual void send_impl_( message msg, const std::vector<bool> &is_sending ) = 0;
94  virtual message recv_impl_() = 0;
95 };
96 }
97 
98 #endif
Definition: comm.h:55
communicator()
Definition: comm.h:61
message recv()
Definition: comm.h:87
virtual std::string uri_protocol() const
Definition: comm.h:69
virtual void send_impl_(message msg, const std::vector< bool > &is_sending)=0
virtual std::string uri_path() const
Definition: comm.h:68
virtual std::string uri_host() const
Definition: comm.h:67
virtual int local_rank() const
Definition: comm.h:64
virtual int remote_size() const
Definition: comm.h:66
virtual ~communicator()
Definition: comm.h:62
virtual int local_size() const
Definition: comm.h:65
virtual message recv_impl_()=0
void send(message msg)
Definition: comm.h:81
void send(message msg, const std::vector< bool > &is_sending)
Definition: comm.h:72
Structure to contain and manipulate data from internal data to MPI message.
Definition: comm.h:54
Definition: message.h:61