Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_SerialDistributor.cpp
Go to the documentation of this file.
1 
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 
44 #include "Epetra_SerialComm.h"
45 
46 
47 //==============================================================================
48 // Epetra_SerialDistributor constructor
50  : Epetra_Object("Epetra::SerialDistributor"),
51  nrecvs_(0),
52  nsends_(0)
53 {
54  (void)Comm;
55 }
56 
57 //==============================================================================
59  : Epetra_Object("Epetra::SerialDistributor"),
60  nrecvs_(Plan.nrecvs_),
61  nsends_(Plan.nsends_)
62 {
63 }
64 
65 //==============================================================================
66 // Epetra_SerialDistributor destructor
68 }
69 
70 
71 //==============================================================================
72 //---------------------------------------------------------------------------
73 //CreateFromSends Method
74 // - create communication plan given a known list of procs to send to
75 //---------------------------------------------------------------------------
76 int Epetra_SerialDistributor::CreateFromSends( const int & NumExportIDs,
77  const int * ExportPIDs,
78  bool Deterministic,
79  int & NumRemoteIDs )
80 {
81  (void)Deterministic;
82  NumRemoteIDs = 0;
83 
84  //In a SerialDistributor, myproc == 0 by definition.
85  int myproc = 0;
86 
87  //basically just do a sanity check.
88  for(int i=0; i<NumExportIDs; ++i) {
89  if (ExportPIDs[i] != myproc) {
90  std::cerr << "Epetra_SerialDistributor::CreateFromSends: ExportPIDs["<<i
91  <<"]=="<<ExportPIDs[i]<<", not allowed for serial case."<< std::endl;
92  return(-1);
93  }
94  ++NumRemoteIDs;
95  }
96 
97  nrecvs_ = NumRemoteIDs;
98 
99  return(0);
100 }
101 
102 //==============================================================================
103 //---------------------------------------------------------------------------
104 //CreateFromRecvs Method
105 // - create communication plan given a known list of procs to recv from
106 //---------------------------------------------------------------------------
107 int Epetra_SerialDistributor::CreateFromRecvs( const int & NumRemoteIDs,
108  const int * RemoteGIDs,
109  const int * RemotePIDs,
110  bool Deterministic,
111  int & NumExportIDs,
112  int *& ExportGIDs,
113  int *& ExportPIDs )
114 {
115  (void)NumRemoteIDs;
116  (void)RemoteGIDs;
117  (void)RemotePIDs;
118  (void)Deterministic;
119  (void)NumExportIDs;
120  (void)ExportGIDs;
121  (void)ExportPIDs;
122  EPETRA_CHK_ERR(-1); // This method should never be called
123  return(-1);
124 }
125 
126 //==============================================================================
127 //---------------------------------------------------------------------------
128 //CreateFromRecvs Method
129 // - create communication plan given a known list of procs to recv from
130 //---------------------------------------------------------------------------
131 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
132 int Epetra_SerialDistributor::CreateFromRecvs( const int & NumRemoteIDs,
133  const long long * RemoteGIDs,
134  const int * RemotePIDs,
135  bool Deterministic,
136  int & NumExportIDs,
137  long long *& ExportGIDs,
138  int *& ExportPIDs )
139 {
140  (void)NumRemoteIDs;
141  (void)RemoteGIDs;
142  (void)RemotePIDs;
143  (void)Deterministic;
144  (void)NumExportIDs;
145  (void)ExportGIDs;
146  (void)ExportPIDs;
147  EPETRA_CHK_ERR(-1); // This method should never be called
148  return(-1);
149 }
150 #endif
151 
152 //==============================================================================
153 // GSComm_Comm Do method
154 int Epetra_SerialDistributor::Do(char * export_objs,
155  int obj_size,
156  int & len_import_objs,
157  char *& import_objs )
158 {
159  len_import_objs = obj_size*nrecvs_;
160  if (len_import_objs > 0) {
161  import_objs = new char[len_import_objs];
162  }
163 
164  for(int i=0; i<len_import_objs; ++i) import_objs[i] = export_objs[i];
165 
166  return(0);
167 }
168 
169 //==============================================================================
170 // GSComm_Comm DoReverse method
171 int Epetra_SerialDistributor::DoReverse(char * export_objs,
172  int obj_size,
173  int & len_import_objs,
174  char *& import_objs )
175 {
176  (void)export_objs;
177  (void)obj_size;
178  (void)len_import_objs;
179  (void)import_objs;
180  EPETRA_CHK_ERR(-1); // This method should never be called
181  return(-1);
182 }
183 //==============================================================================
184 //---------------------------------------------------------------------------
185 //Do_Posts Method
186 //---------------------------------------------------------------------------
187 int Epetra_SerialDistributor::DoPosts(char * export_objs,
188  int obj_size,
189  int & len_import_objs,
190  char *& import_objs )
191 {
192  (void)export_objs;
193  (void)obj_size;
194  (void)len_import_objs;
195  (void)import_objs;
196  EPETRA_CHK_ERR(-1); // This method should never be called
197  return(-1);
198 }
199 //==============================================================================
200 //---------------------------------------------------------------------------
201 //Do_Waits Method
202 //---------------------------------------------------------------------------
204 {
205  EPETRA_CHK_ERR(-1); // This method should never be called
206  return(-1);
207 }
208 
209 //==============================================================================
210 //---------------------------------------------------------------------------
211 //DoReverse_Posts Method
212 //---------------------------------------------------------------------------
214  int obj_size,
215  int & len_import_objs,
216  char *& import_objs )
217 {
218  (void)export_objs;
219  (void)obj_size;
220  (void)len_import_objs;
221  (void)import_objs;
222  EPETRA_CHK_ERR(-1); // This method should never be called
223  return(-1);
224 }
225 
226 //==============================================================================
227 //---------------------------------------------------------------------------
228 //DoReverse_Waits Method
229 //---------------------------------------------------------------------------
231 {
232  EPETRA_CHK_ERR(-1); // This method should never be called
233  return(-1);
234 }
235 
236 //==============================================================================
237 // GSComm_Comm Do method
238 int Epetra_SerialDistributor::Do(char * export_objs,
239  int obj_size,
240  int *& sizes,
241  int & len_import_objs,
242  char *& import_objs )
243 {
244  (void)export_objs;
245  (void)obj_size;
246  (void)sizes;
247  (void)len_import_objs;
248  (void)import_objs;
249  EPETRA_CHK_ERR(-1); // This method should never be called
250  return(-1);
251 }
252 
253 //==============================================================================
254 // GSComm_Comm DoReverse method
255 int Epetra_SerialDistributor::DoReverse(char * export_objs,
256  int obj_size,
257  int *& sizes,
258  int & len_import_objs,
259  char *& import_objs )
260 {
261  (void)export_objs;
262  (void)obj_size;
263  (void)sizes;
264  (void)len_import_objs;
265  (void)import_objs;
266  EPETRA_CHK_ERR(-1); // This method should never be called
267  return(-1);
268 }
269 //==============================================================================
270 //---------------------------------------------------------------------------
271 //Do_Posts Method
272 //---------------------------------------------------------------------------
273 int Epetra_SerialDistributor::DoPosts(char * export_objs,
274  int obj_size,
275  int *& sizes,
276  int & len_import_objs,
277  char *& import_objs )
278 {
279  (void)export_objs;
280  (void)obj_size;
281  (void)sizes;
282  (void)len_import_objs;
283  (void)import_objs;
284  EPETRA_CHK_ERR(-1); // This method should never be called
285  return(-1);
286 }
287 
288 //==============================================================================
289 //---------------------------------------------------------------------------
290 //DoReverse_Posts Method
291 //---------------------------------------------------------------------------
293  int obj_size,
294  int *& sizes,
295  int & len_import_objs,
296  char *& import_objs )
297 {
298  (void)export_objs;
299  (void)obj_size;
300  (void)sizes;
301  (void)len_import_objs;
302  (void)import_objs;
303  EPETRA_CHK_ERR(-1); // This method should never be called
304  return(-1);
305 }
306 
307 //==============================================================================
308 void Epetra_SerialDistributor::Print(std::ostream & os) const
309 {
310  os << "Trivial Distributor" << std::endl;
311  return;
312 }
int DoReversePosts(char *export_objs, int obj_size, int &len_import_objs, char *&import_objs)
Do reverse post of buffer of export objects (can do other local work before executing Waits) ...
int CreateFromRecvs(const int &NumRemoteIDs, const int *RemoteGIDs, const int *RemotePIDs, bool Deterministic, int &NumExportIDs, int *&ExportGIDs, int *&ExportPIDs)
Create Distributor object using list of Remote global IDs and corresponding PIDs. ...
Epetra_SerialDistributor: The Epetra Serial implementation of the Epetra_Distributor Gather/Scatter S...
#define EPETRA_CHK_ERR(a)
int Do(char *export_objs, int obj_size, int &len_import_objs, char *&import_objs)
Execute plan on buffer of export objects in a single step.
Epetra_Object: The base Epetra class.
Definition: Epetra_Object.h:57
Epetra_SerialDistributor(const Epetra_SerialComm &Comm)
Constructor.
virtual void Print(std::ostream &os) const
virtual ~Epetra_SerialDistributor()
Epetra_Comm Destructor.
int DoPosts(char *export_objs, int obj_size, int &len_import_objs, char *&import_objs)
Post buffer of export objects (can do other local work before executing Waits)
Epetra_SerialComm: The Epetra Serial Communication Class.
int CreateFromSends(const int &NumExportIDs, const int *ExportPIDs, bool Deterministic, int &NumRemoteIDs)
Create Distributor object using list of process IDs to which we export.
int DoReverseWaits()
Wait on a reverse set of posts.
int DoReverse(char *export_objs, int obj_size, int &len_import_objs, char *&import_objs)
Execute reverse of plan on buffer of export objects in a single step.
int DoWaits()
Wait on a set of posts.