/[escript]/trunk/paso/src/Coupler.h
ViewVC logotype

Contents of /trunk/paso/src/Coupler.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (5 weeks, 2 days ago) by uqaeller
File MIME type: text/plain
File size: 4701 byte(s)
Updated the copyright header.


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

  ViewVC Help
Powered by ViewVC 1.1.26