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

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

Parent Directory Parent Directory | Revision Log Revision Log


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


1 ksteube 1313
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 uqaeller 6939 * Copyright (c) 2003-2020 by The University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
7     * Primary Business: Queensland, Australia
8 jfenwick 6112 * Licensed under the Apache License, version 2.0
9     * http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1811 *
11 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 * Development 2012-2013 by School of Earth Sciences
13 uqaeller 6939 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14     * Development from 2019 by School of Earth and Environmental Sciences
15     **
16 jfenwick 3981 *****************************************************************************/
17 ksteube 1313
18 ksteube 1811
19 caltinay 4801 /****************************************************************************/
20 ksteube 1313
21 caltinay 4873 /* Paso: coupler */
22 ksteube 1313
23 caltinay 4801 /****************************************************************************/
24 ksteube 1313
25 jfenwick 2608 /* Author: Lutz Gross, l.gross@uq.edu.au */
26 ksteube 1313
27 caltinay 4801 /****************************************************************************/
28 ksteube 1313
29 caltinay 4801 #ifndef __PASO_COUPLER_H__
30     #define __PASO_COUPLER_H__
31 ksteube 1313
32 caltinay 6001 #include "Paso.h"
33 caltinay 5996 #include "PasoException.h"
34 ksteube 1313 #include "SharedComponents.h"
35    
36 caltinay 4801 namespace paso {
37 gross 1552
38 caltinay 4817 struct Connector;
39     typedef boost::shared_ptr<Connector> Connector_ptr;
40     typedef boost::shared_ptr<const Connector> const_Connector_ptr;
41    
42 caltinay 6581 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 caltinay 4817
46     PASO_DLL_API
47 caltinay 4801 struct Connector
48     {
49 caltinay 4816 SharedComponents_ptr send;
50     SharedComponents_ptr recv;
51 gross 1552
52 caltinay 4817 Connector(SharedComponents_ptr s, SharedComponents_ptr r)
53     {
54 caltinay 6173 if (s->local_length != r->local_length) {
55     throw PasoException("Connector: local length of send and recv "
56     "SharedComponents must match.");
57 caltinay 4817 }
58     send = s;
59     recv = r;
60     }
61 ksteube 1313
62 caltinay 4817 /// creates a copy
63     inline Connector_ptr copy() const { return unroll(1); }
64 ksteube 1313
65 caltinay 4817 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 caltinay 6172 send->neighbour, send->shared, send->offsetInShared,
72 caltinay 6173 block_size, 0));
73 ksteube 1313
74 caltinay 4817 new_recv_shcomp.reset(new SharedComponents(recv->local_length,
75 caltinay 6172 recv->neighbour, recv->shared, recv->offsetInShared,
76 caltinay 6173 block_size, 0));
77 caltinay 4817 } else {
78     new_send_shcomp = send;
79     new_recv_shcomp = recv;
80     }
81 caltinay 5996 out.reset(new Connector(new_send_shcomp, new_recv_shcomp));
82 caltinay 4817 return out;
83     }
84 ksteube 1313
85 caltinay 4817 //inline debug() const
86     //{
87 caltinay 6172 // for (int i=0; i<recv->neighbour.size(); ++i)
88 caltinay 4817 // printf("Coupler: %d receive %d data at %d from %d\n",
89     // s->mpi_info->rank,recv->offsetInShared[i+1]-recv->offsetInShared[i],
90 caltinay 6172 // recv->offsetInShared[i],recv->neighbour[i]);
91     // for (int i=0; i<send->neighbour.size(); ++i)
92 caltinay 4817 // printf("Coupler: %d send %d data at %d to %d\n",
93     // s->mpi_info->rank,send->offsetInShared[i+1]-send->offsetInShared[i],
94 caltinay 6172 // send->offsetInShared[i],send->neighbour[i]);
95 caltinay 4817 //}
96     };
97 phornby 2068
98    
99 caltinay 6581 template<typename Scalar>
100 caltinay 4817 struct Coupler
101     {
102 caltinay 6173 Coupler(const_Connector_ptr, dim_t blockSize, escript::JMPI mpiInfo);
103 caltinay 4817 ~Coupler();
104 phornby 2068
105 caltinay 6581 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 phornby 2068
111 caltinay 6581 inline const Scalar* borrowLocalData() const { return data; }
112 caltinay 4801
113 caltinay 6581 inline const Scalar* borrowRemoteData() const { return recv_buffer; }
114 phornby 2068
115 caltinay 4817 inline dim_t getNumSharedComponents() const
116     {
117     return connector->send->numSharedComponents;
118     }
119 gross 1552
120 caltinay 4817 inline dim_t getNumOverlapComponents() const
121     {
122     return connector->recv->numSharedComponents;
123     }
124 phornby 2068
125 caltinay 4817 inline dim_t getNumSharedValues() const
126     {
127     return getNumSharedComponents() * block_size;
128     }
129 phornby 2068
130 caltinay 4817 inline dim_t getNumOverlapValues() const
131     {
132     return getNumOverlapComponents() * block_size;
133     }
134 phornby 2068
135 caltinay 4817 inline dim_t getLocalLength() const
136     {
137     return connector->send->local_length;
138     }
139 phornby 2068
140 caltinay 5148 const_Connector_ptr connector;
141 caltinay 4817 dim_t block_size;
142     bool in_use;
143 phornby 2068
144 caltinay 4817 // unmanaged pointer to data to be sent
145 caltinay 6581 Scalar* data;
146     Scalar* send_buffer;
147     Scalar* recv_buffer;
148 caltinay 4817 MPI_Request* mpi_requests;
149     MPI_Status* mpi_stati;
150 caltinay 6172 escript::JMPI mpi_info;
151 caltinay 4817 };
152 phornby 2068
153    
154 caltinay 4801 } // namespace paso
155    
156     #endif // __PASO_COUPLER_H__
157    

  ViewVC Help
Powered by ViewVC 1.1.26