escript  Revision_
Coupler.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 /****************************************************************************/
19 
20 /* Paso: coupler */
21 
22 /****************************************************************************/
23 
24 /* Author: Lutz Gross, l.gross@uq.edu.au */
25 
26 /****************************************************************************/
27 
28 #ifndef __PASO_COUPLER_H__
29 #define __PASO_COUPLER_H__
30 
31 #include "SharedComponents.h"
32 
33 namespace paso {
34 
35 struct Connector;
36 typedef boost::shared_ptr<Connector> Connector_ptr;
37 typedef boost::shared_ptr<const Connector> const_Connector_ptr;
38 
39 struct Coupler;
40 typedef boost::shared_ptr<Coupler> Coupler_ptr;
41 typedef boost::shared_ptr<const Coupler> const_Coupler_ptr;
42 
44 struct Connector
45 {
49 
51  {
53  if (s->mpi_info != r->mpi_info) {
55  "Connector: send and recv MPI communicators don't match.");
56  } else if (s->local_length != r->local_length) {
58  "Connector: local length of send and recv SharedComponents must match.");
59  }
60  send = s;
61  recv = r;
62  mpi_info = s->mpi_info;
63  }
64 
66  ~Connector() { }
67 
69  inline Connector_ptr copy() const { return unroll(1); }
70 
71  inline Connector_ptr unroll(index_t block_size) const
72  {
73  SharedComponents_ptr new_send_shcomp, new_recv_shcomp;
74  Connector_ptr out;
75  if (block_size > 1) {
76  new_send_shcomp.reset(new SharedComponents(send->local_length,
77  send->numNeighbors, send->neighbor,
78  send->shared, send->offsetInShared,
79  block_size, 0, mpi_info));
80 
81  new_recv_shcomp.reset(new SharedComponents(recv->local_length,
82  recv->numNeighbors, recv->neighbor,
83  recv->shared, recv->offsetInShared,
84  block_size, 0, mpi_info));
85  } else {
86  new_send_shcomp = send;
87  new_recv_shcomp = recv;
88  }
89  if (Esys_noError())
90  out.reset(new Connector(new_send_shcomp, new_recv_shcomp));
91  return out;
92  }
93 
94  //inline debug() const
95  //{
96  // for (int i=0; i<recv->numNeighbors; ++i)
97  // printf("Coupler: %d receive %d data at %d from %d\n",
98  // s->mpi_info->rank,recv->offsetInShared[i+1]-recv->offsetInShared[i],
99  // recv->offsetInShared[i],recv->neighbor[i]);
100  // for (int i=0; i<send->numNeighbors; ++i)
101  // printf("Coupler: %d send %d data at %d to %d\n",
102  // s->mpi_info->rank,send->offsetInShared[i+1]-send->offsetInShared[i],
103  // send->offsetInShared[i],send->neighbor[i]);
104  //}
105 };
106 
107 
109 struct Coupler
110 {
111  Coupler(const_Connector_ptr, dim_t blockSize);
112  ~Coupler();
113 
114  void startCollect(const double* in);
115  double* finishCollect();
116  void copyAll(Coupler_ptr target) const;
117  void fillOverlap(dim_t n, double* x);
118  void max(dim_t n, double* x);
119 
120  inline const double* borrowLocalData() const { return data; }
121 
122  inline const double* borrowRemoteData() const { return recv_buffer; }
123 
125  {
126  return connector->send->numSharedComponents;
127  }
128 
130  {
131  return connector->recv->numSharedComponents;
132  }
133 
134  inline dim_t getNumSharedValues() const
135  {
136  return getNumSharedComponents() * block_size;
137  }
138 
139  inline dim_t getNumOverlapValues() const
140  {
141  return getNumOverlapComponents() * block_size;
142  }
143 
144  inline dim_t getLocalLength() const
145  {
146  return connector->send->local_length;
147  }
148 
149  const_Connector_ptr connector;
151  bool in_use;
152 
153  // unmanaged pointer to data to be sent
154  double* data;
155  double* send_buffer;
156  double* recv_buffer;
160 };
161 
162 
163 } // namespace paso
164 
165 #endif // __PASO_COUPLER_H__
166 
#define PASO_DLL_API
Definition: Paso.h:41
boost::shared_ptr< const Coupler > const_Coupler_ptr
Definition: Coupler.h:41
bool Esys_noError(void)
Definition: error.cpp:49
void Esys_resetError(void)
Definition: error.cpp:33
SharedComponents_ptr recv
Definition: Coupler.h:47
boost::shared_ptr< SharedComponents > SharedComponents_ptr
Definition: SharedComponents.h:35
bool in_use
Definition: Coupler.h:151
Definition: Coupler.h:109
dim_t getNumSharedComponents() const
Definition: Coupler.h:124
dim_t getLocalLength() const
Definition: Coupler.h:144
void Esys_setError(Esys_ErrorCodeType err, __const char *msg)
Definition: error.cpp:38
double * send_buffer
Definition: Coupler.h:155
MPI_Request * mpi_requests
Definition: Coupler.h:157
Connector(SharedComponents_ptr s, SharedComponents_ptr r)
Definition: Coupler.h:50
dim_t getNumSharedValues() const
Definition: Coupler.h:134
dim_t block_size
Definition: Coupler.h:150
Definition: Coupler.h:44
MPI_Status * mpi_stati
Definition: Coupler.h:158
Definition: AMG.cpp:38
int MPI_Request
Definition: Esys_MPI.h:39
double * data
Definition: Coupler.h:154
Connector_ptr copy() const
creates a copy
Definition: Coupler.h:69
dim_t getNumOverlapComponents() const
Definition: Coupler.h:129
esysUtils::JMPI mpi_info
Definition: Coupler.h:48
double * recv_buffer
Definition: Coupler.h:156
SharedComponents_ptr send
Definition: Coupler.h:46
Definition: error.h:55
~Connector()
destructor
Definition: Coupler.h:66
int index_t
Definition: types.h:24
dim_t getNumOverlapValues() const
Definition: Coupler.h:139
Definition: SharedComponents.h:40
boost::shared_ptr< Coupler > Coupler_ptr
Definition: Coupler.h:39
esysUtils::JMPI mpi_info
Definition: Coupler.h:159
boost::shared_ptr< Connector > Connector_ptr
Definition: Coupler.h:35
const double * borrowRemoteData() const
Definition: Coupler.h:122
index_t dim_t
Definition: types.h:27
int MPI_Status
Definition: Esys_MPI.h:41
Connector_ptr unroll(index_t block_size) const
Definition: Coupler.h:71
boost::shared_ptr< const Connector > const_Connector_ptr
Definition: Coupler.h:37
const_Connector_ptr connector
Definition: Coupler.h:149
boost::shared_ptr< JMPI_ > JMPI
Definition: Esys_MPI.h:79
const double * borrowLocalData() const
Definition: Coupler.h:120