FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
snl_fei_SubdMsgHandler.cpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #include <fei_macros.hpp>
10 
13 #include <fei_SharedIDs.hpp>
14 #include <fei_TemplateUtils.hpp>
15 
16 #undef fei_file
17 #define fei_file "snl_fei::SubdMsgHandler"
18 #include <fei_ErrMacros.hpp>
19 
21  fei::SharedIDs<int>* sharedIDTable,
22  fei::SharedIDs<int>* subdomainIDTable)
23  :sendPattern_(NULL),
24  recvPattern_(NULL),
25  recordCollection_(recordCollection),
26  sharedIDTable_(sharedIDTable),
27  subdomainIDTable_(subdomainIDTable),
28  sendProcs_(0, 32),
29  recvProcs_(0, 32)
30 {
31 }
32 
34 {
35 }
36 
38 {
39  fei::copyKeysToVector(sendPattern_->getMap(), sendProcs_);
40  return(sendProcs_);
41 }
42 
44 {
45  fei::copyKeysToVector(recvPattern_->getMap(), recvProcs_);
46  return(recvProcs_);
47 }
48 
50  int& messageLength)
51 {
52  fei::comm_map::row_type* list = sendPattern_->getRow(destProc);
53  if (list == NULL) {
54  FEI_COUT << "SubdMsdHandler: destProc: " << destProc << ", list is NULL."<<FEI_ENDL;
55  return(-1);
56  }
57 
58  messageLength = list->size();
59 
60  return( 0 );
61 }
62 
64  std::vector<int>& message)
65 {
66  int len = sendPattern_->getRow(destProc)->size();
67  message.resize(len);
68  int* msgPtr = &message[0];
69 
70  fei::comm_map::row_type* ids = sendPattern_->getRow(destProc);
71  fei::comm_map::row_type::const_iterator
72  id_iter = ids->begin(),
73  id_end = ids->end();
74 
75  int offset = 0;
76  for(; id_iter != id_end; ++id_iter) {
77  int ID = *id_iter;
78  fei::Record<int>* rec = recordCollection_->getRecordWithID(ID);
79  if (rec == NULL) {
80  ERReturn(-1);
81  }
82 
83  if (rec->isInLocalSubdomain_) {
84  msgPtr[offset++] = 1;
85  }
86  else {
87  msgPtr[offset++] = 0;
88  }
89  }
90 
91  return(0);
92 }
93 
95  std::vector<int>& message)
96 {
97  fei::comm_map::row_type* ids = recvPattern_->getRow(srcProc);
98  fei::comm_map::row_type::const_iterator
99  id_iter = ids->begin(),
100  id_end = ids->end();
101 
102  int* msgPtr = &message[0];
103 
104  if (message.size() != ids->size()) {
105  ERReturn(-1);
106  }
107 
108  int offset = 0;
109  for(; id_iter != id_end; ++id_iter) {
110  int ID = *id_iter;
111 
112  bool isInRemoteSubdomain = msgPtr[offset++] > 1 ? true : false;
113 
114  if (isInRemoteSubdomain) {
115  subdomainIDTable_->addSharedID(ID, 1, &srcProc);
116  }
117  }
118 
119  return(0);
120 }
121 
#define FEI_COUT
int getSendMessage(int destProc, std::vector< int > &message)
std::vector< int > & getSendProcs()
std::vector< int > & getRecvProcs()
void copyKeysToVector(const MAP_TYPE &map_obj, std::vector< int > &keyvector)
#define ERReturn(a)
SubdMsgHandler(RecordCollection *recordCollection, fei::SharedIDs< int > *sharedIDTable, fei::SharedIDs< int > *subdomainIDTable)
#define FEI_ENDL
int processRecvMessage(int srcProc, std::vector< int > &message)
int getSendMessageLength(int destProc, int &messageLength)
bool isInLocalSubdomain_
Definition: fei_Record.hpp:162