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 "Paso.h"
32 #include "PasoException.h"
33 #include "SharedComponents.h"
34 
35 namespace paso {
36 
37 struct Connector;
38 typedef boost::shared_ptr<Connector> Connector_ptr;
39 typedef boost::shared_ptr<const Connector> const_Connector_ptr;
40 
41 struct Coupler;
42 typedef boost::shared_ptr<Coupler> Coupler_ptr;
43 typedef boost::shared_ptr<const Coupler> const_Coupler_ptr;
44 
46 struct Connector
47 {
50 
52  {
53  if (s->local_length != r->local_length) {
54  throw PasoException("Connector: local length of send and recv "
55  "SharedComponents must match.");
56  }
57  send = s;
58  recv = r;
59  }
60 
62  inline Connector_ptr copy() const { return unroll(1); }
63 
64  inline Connector_ptr unroll(index_t block_size) const
65  {
66  SharedComponents_ptr new_send_shcomp, new_recv_shcomp;
67  Connector_ptr out;
68  if (block_size > 1) {
69  new_send_shcomp.reset(new SharedComponents(send->local_length,
70  send->neighbour, send->shared, send->offsetInShared,
71  block_size, 0));
72 
73  new_recv_shcomp.reset(new SharedComponents(recv->local_length,
74  recv->neighbour, recv->shared, recv->offsetInShared,
75  block_size, 0));
76  } else {
77  new_send_shcomp = send;
78  new_recv_shcomp = recv;
79  }
80  out.reset(new Connector(new_send_shcomp, new_recv_shcomp));
81  return out;
82  }
83 
84  //inline debug() const
85  //{
86  // for (int i=0; i<recv->neighbour.size(); ++i)
87  // printf("Coupler: %d receive %d data at %d from %d\n",
88  // s->mpi_info->rank,recv->offsetInShared[i+1]-recv->offsetInShared[i],
89  // recv->offsetInShared[i],recv->neighbour[i]);
90  // for (int i=0; i<send->neighbour.size(); ++i)
91  // printf("Coupler: %d send %d data at %d to %d\n",
92  // s->mpi_info->rank,send->offsetInShared[i+1]-send->offsetInShared[i],
93  // send->offsetInShared[i],send->neighbour[i]);
94  //}
95 };
96 
97 
99 struct Coupler
100 {
101  Coupler(const_Connector_ptr, dim_t blockSize, escript::JMPI mpiInfo);
102  ~Coupler();
103 
104  void startCollect(const double* in);
105  double* finishCollect();
106  void copyAll(Coupler_ptr target) const;
107  void fillOverlap(dim_t n, double* x);
108  void max(dim_t n, double* x);
109 
110  inline const double* borrowLocalData() const { return data; }
111 
112  inline const double* borrowRemoteData() const { return recv_buffer; }
113 
115  {
116  return connector->send->numSharedComponents;
117  }
118 
120  {
121  return connector->recv->numSharedComponents;
122  }
123 
124  inline dim_t getNumSharedValues() const
125  {
126  return getNumSharedComponents() * block_size;
127  }
128 
129  inline dim_t getNumOverlapValues() const
130  {
131  return getNumOverlapComponents() * block_size;
132  }
133 
134  inline dim_t getLocalLength() const
135  {
136  return connector->send->local_length;
137  }
138 
139  const_Connector_ptr connector;
141  bool in_use;
142 
143  // unmanaged pointer to data to be sent
144  double* data;
145  double* send_buffer;
146  double* recv_buffer;
150 };
151 
152 
153 } // namespace paso
154 
155 #endif // __PASO_COUPLER_H__
156 
dim_t getLocalLength() const
Definition: Coupler.h:134
#define PASO_DLL_API
Definition: Paso.h:58
boost::shared_ptr< const Coupler > const_Coupler_ptr
Definition: Coupler.h:43
const double * borrowLocalData() const
Definition: Coupler.h:110
Connector_ptr copy() const
creates a copy
Definition: Coupler.h:62
SharedComponents_ptr recv
Definition: Coupler.h:49
boost::shared_ptr< SharedComponents > SharedComponents_ptr
Definition: SharedComponents.h:35
int MPI_Status
Definition: EsysMPI.h:44
dim_t getNumOverlapValues() const
Definition: Coupler.h:129
bool in_use
Definition: Coupler.h:141
Definition: Coupler.h:99
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:71
double * send_buffer
Definition: Coupler.h:145
MPI_Request * mpi_requests
Definition: Coupler.h:147
Connector(SharedComponents_ptr s, SharedComponents_ptr r)
Definition: Coupler.h:51
dim_t block_size
Definition: Coupler.h:140
escript::JMPI mpi_info
Definition: Coupler.h:149
Definition: Coupler.h:46
MPI_Status * mpi_stati
Definition: Coupler.h:148
Definition: AMG.cpp:45
double * data
Definition: Coupler.h:144
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:59
dim_t getNumSharedValues() const
Definition: Coupler.h:124
dim_t getNumOverlapComponents() const
Definition: Coupler.h:119
double * recv_buffer
Definition: Coupler.h:146
Connector_ptr unroll(index_t block_size) const
Definition: Coupler.h:64
SharedComponents_ptr send
Definition: Coupler.h:48
dim_t getNumSharedComponents() const
Definition: Coupler.h:114
int MPI_Request
Definition: EsysMPI.h:42
Definition: SharedComponents.h:40
boost::shared_ptr< Coupler > Coupler_ptr
Definition: Coupler.h:41
boost::shared_ptr< Connector > Connector_ptr
Definition: Coupler.h:37
boost::shared_ptr< const Connector > const_Connector_ptr
Definition: Coupler.h:39
PasoException exception class.
Definition: PasoException.h:32
const_Connector_ptr connector
Definition: Coupler.h:139
const double * borrowRemoteData() const
Definition: Coupler.h:112
index_t dim_t
Definition: DataTypes.h:64