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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4817 - (hide annotations)
Fri Mar 28 08:04:09 2014 UTC (5 years, 2 months ago) by caltinay
File MIME type: text/plain
File size: 4919 byte(s)
Coupler/Connector shared ptrs.

1 ksteube 1313
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 4657 * Copyright (c) 2003-2014 by University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
7     * Primary Business: Queensland, Australia
8     * Licensed under the Open Software License version 3.0
9     * http://www.opensource.org/licenses/osl-3.0.php
10     *
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     * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 *
15     *****************************************************************************/
16 ksteube 1313
17 ksteube 1811
18 caltinay 4801 /****************************************************************************/
19 ksteube 1313
20     /* Paso: coupler */
21    
22 caltinay 4801 /****************************************************************************/
23 ksteube 1313
24 jfenwick 2608 /* Author: Lutz Gross, l.gross@uq.edu.au */
25 ksteube 1313
26 caltinay 4801 /****************************************************************************/
27 ksteube 1313
28 caltinay 4801 #ifndef __PASO_COUPLER_H__
29     #define __PASO_COUPLER_H__
30 ksteube 1313
31     #include "SharedComponents.h"
32    
33 caltinay 4801 namespace paso {
34 gross 1552
35 caltinay 4817 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    
43     PASO_DLL_API
44 caltinay 4801 struct Connector
45     {
46 caltinay 4816 SharedComponents_ptr send;
47     SharedComponents_ptr recv;
48 caltinay 4801 Esys_MPIInfo* mpi_info;
49 gross 1552
50 caltinay 4817 Connector(SharedComponents_ptr s, SharedComponents_ptr r)
51     {
52     Esys_resetError();
53     if (s->mpi_info != r->mpi_info) {
54     Esys_setError(SYSTEM_ERROR,
55     "Connector: send and recv MPI communicators don't match.");
56     } else if (s->local_length != r->local_length) {
57     Esys_setError(SYSTEM_ERROR,
58     "Connector: local length of send and recv SharedComponents must match.");
59     }
60     send = s;
61     recv = r;
62     mpi_info = Esys_MPIInfo_getReference(s->mpi_info);
63     }
64 ksteube 1313
65 caltinay 4817 /// destructor
66     ~Connector() { Esys_MPIInfo_free(mpi_info); }
67 ksteube 1313
68 caltinay 4817 /// creates a copy
69     inline Connector_ptr copy() const { return unroll(1); }
70 ksteube 1313
71 caltinay 4817 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 ksteube 1313
81 caltinay 4817 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 ksteube 1313
94 caltinay 4817 //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 phornby 2068
107    
108     PASO_DLL_API
109 caltinay 4817 struct Coupler
110     {
111     Coupler(Connector_ptr, dim_t blockSize);
112     ~Coupler();
113 phornby 2068
114 caltinay 4817 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 phornby 2068
120 caltinay 4817 inline const double* borrowLocalData() const { return data; }
121 caltinay 4801
122 caltinay 4817 inline const double* borrowRemoteData() const { return recv_buffer; }
123 phornby 2068
124 caltinay 4817 inline dim_t getNumSharedComponents() const
125     {
126     return connector->send->numSharedComponents;
127     }
128 gross 1552
129 caltinay 4817 inline dim_t getNumOverlapComponents() const
130     {
131     return connector->recv->numSharedComponents;
132     }
133 phornby 2068
134 caltinay 4817 inline dim_t getNumSharedValues() const
135     {
136     return getNumSharedComponents() * block_size;
137     }
138 phornby 2068
139 caltinay 4817 inline dim_t getNumOverlapValues() const
140     {
141     return getNumOverlapComponents() * block_size;
142     }
143 phornby 2068
144 caltinay 4817 inline dim_t getLocalLength() const
145     {
146     return connector->send->local_length;
147     }
148 phornby 2068
149 caltinay 4817 Connector_ptr connector;
150     dim_t block_size;
151     bool in_use;
152 phornby 2068
153 caltinay 4817 // unmanaged pointer to data to be sent
154     double* data;
155     double* send_buffer;
156     double* recv_buffer;
157     MPI_Request* mpi_requests;
158     MPI_Status* mpi_stati;
159     Esys_MPIInfo* mpi_info;
160     };
161 phornby 2068
162    
163 caltinay 4801 } // namespace paso
164    
165     #endif // __PASO_COUPLER_H__
166    

  ViewVC Help
Powered by ViewVC 1.1.26