escript Revision_
Coupler.h
Go to the documentation of this file.
1
2/*****************************************************************************
3*
4* Copyright (c) 2003-2020 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-2017 by Centre for Geoscience Computing (GeoComp)
14* Development from 2019 by School of Earth and Environmental Sciences
15**
16*****************************************************************************/
17
18
19/****************************************************************************/
20
21/* Paso: coupler */
22
23/****************************************************************************/
24
25/* Author: Lutz Gross, l.gross@uq.edu.au */
26
27/****************************************************************************/
28
29#ifndef __PASO_COUPLER_H__
30#define __PASO_COUPLER_H__
31
32#include "Paso.h"
33#include "PasoException.h"
34#include "SharedComponents.h"
35
36namespace paso {
37
38struct Connector;
39typedef boost::shared_ptr<Connector> Connector_ptr;
40typedef boost::shared_ptr<const Connector> const_Connector_ptr;
41
42template<typename Scalar> struct Coupler;
43template<typename T> using Coupler_ptr = boost::shared_ptr<Coupler<T> >;
44template<typename T> using const_Coupler_ptr = boost::shared_ptr<const Coupler<T> >;
45
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
98template<typename Scalar>
100{
101 Coupler(const_Connector_ptr, dim_t blockSize, escript::JMPI mpiInfo);
102 ~Coupler();
103
104 void startCollect(const Scalar* in);
105 Scalar* finishCollect();
106 void copyAll(Coupler_ptr<Scalar> target) const;
107 void fillOverlap(dim_t n, Scalar* x);
108 void max(dim_t n, Scalar* x);
109
110 inline const Scalar* borrowLocalData() const { return data; }
111
112 inline const Scalar* borrowRemoteData() const { return recv_buffer; }
113
115 {
116 return connector->send->numSharedComponents;
117 }
118
120 {
121 return connector->recv->numSharedComponents;
122 }
123
125 {
126 return getNumSharedComponents() * block_size;
127 }
128
130 {
131 return getNumOverlapComponents() * block_size;
132 }
133
134 inline dim_t getLocalLength() const
135 {
136 return connector->send->local_length;
137 }
138
141 bool in_use;
142
143 // unmanaged pointer to data to be sent
150};
151
152
153} // namespace paso
154
155#endif // __PASO_COUPLER_H__
156
int MPI_Request
Definition: EsysMPI.h:45
int MPI_Status
Definition: EsysMPI.h:47
PasoException exception class.
Definition: PasoException.h:34
index_t dim_t
Definition: DataTypes.h:66
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
Data Scalar(double value, const FunctionSpace &what, bool expanded)
A collection of factory functions for creating Data objects which contain data points of various shap...
Definition: DataFactory.cpp:49
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:76
Definition: BiCGStab.cpp:25
boost::shared_ptr< const Coupler< T > > const_Coupler_ptr
Definition: Coupler.h:44
boost::shared_ptr< const Connector > const_Connector_ptr
Definition: Coupler.h:40
boost::shared_ptr< Connector > Connector_ptr
Definition: Coupler.h:39
boost::shared_ptr< SharedComponents > SharedComponents_ptr
Definition: SharedComponents.h:37
boost::shared_ptr< Coupler< T > > Coupler_ptr
Definition: Coupler.h:43
#define PASO_DLL_API
Definition: paso/src/system_dep.h:29
Definition: Coupler.h:47
Connector(SharedComponents_ptr s, SharedComponents_ptr r)
Definition: Coupler.h:51
Connector_ptr copy() const
creates a copy
Definition: Coupler.h:62
SharedComponents_ptr recv
Definition: Coupler.h:49
Connector_ptr unroll(index_t block_size) const
Definition: Coupler.h:64
SharedComponents_ptr send
Definition: Coupler.h:48
Definition: Coupler.h:100
const Scalar * borrowLocalData() const
Definition: Coupler.h:110
dim_t getNumOverlapValues() const
Definition: Coupler.h:129
void max(dim_t n, Scalar *x)
Scalar * recv_buffer
Definition: Coupler.h:146
dim_t getLocalLength() const
Definition: Coupler.h:134
escript::JMPI mpi_info
Definition: Coupler.h:149
const_Connector_ptr connector
Definition: Coupler.h:139
bool in_use
Definition: Coupler.h:141
MPI_Request * mpi_requests
Definition: Coupler.h:147
const Scalar * borrowRemoteData() const
Definition: Coupler.h:112
Scalar * data
Definition: Coupler.h:144
dim_t getNumOverlapComponents() const
Definition: Coupler.h:119
MPI_Status * mpi_stati
Definition: Coupler.h:148
Scalar * send_buffer
Definition: Coupler.h:145
dim_t getNumSharedComponents() const
Definition: Coupler.h:114
dim_t getNumSharedValues() const
Definition: Coupler.h:124
dim_t block_size
Definition: Coupler.h:140
Definition: SharedComponents.h:41