PaCO++  0.05
Identity.cc
Go to the documentation of this file.
1 #include "Identity.h"
2 #include <iostream>
3 
4 #define SRC_TOPOLOGY 1
5 #define DST_TOPOLOGY 2
6 #define ELEMENT_SIZE 4
7 #define LOCAL_SIZE 8
8 
9 #define CORRECT_CONFIG 15
10 
11 #undef DEBUG_INTERNAL
12 #undef DEBUG_INTERNAL2
13 
17 
19 {
20  // Common
21  _config = 0;
22 
23  // By default 1->1 :)
24  _sTopo.total=1;
25  _dTopo.total=1;
26  _nodeRank=0;
27 
28  // Client side
29  _clientBuffer=NULL;
30 
31  // Server side
32  _serverDescr=NULL;
33  _serverBuffer=NULL;
34 }
35 
37 {
38 }
39 
40 void
42 {
43 #ifdef DEBUG_INTERNAL
44  std::cerr << "-- setSourceTopology: " << topo.total << std::endl;
45 #endif
47  _sTopo = topo;
48 }
49 
52 {
53  std::cerr << "****** Why is the method " << __FUNCTION__ << "called?\n";
54  abort();
55  return _sTopo;
56 }
57 
58 void
60 {
61 #ifdef DEBUG_INTERNAL
62  std::cerr << "-- setDestTopology: " << topo.total << std::endl;
63 #endif
65  _dTopo = topo;
66 
67 }
68 
71 {
72  std::cerr << "****** Why is the method " << __FUNCTION__ << "called?\n";
73  abort();
74  return _dTopo;
75 }
76 
77 void
79 {
80 #ifdef DEBUG_INTERNAL
81  std::cerr << "-- setNodeRank: " << Rank << std::endl;
82 #endif
83  _nodeRank = Rank;
84 }
85 
86 long
88 {
89  return _nodeRank;
90 }
91 
92 void
93 Identity::setEltSize(unsigned long size)
94 {
95 #ifdef DEBUG_INTERNAL
96  std::cerr << "-- setEltSize: " << size << std::endl;
97 #endif
99  _unitsize = size;
100 }
101 
102 void
103 Identity::setLocalNbElt(unsigned long elt_nb)
104 {
105 #ifdef DEBUG_INTERNAL
106  std::cerr << "-- setLocalNbElt: " << elt_nb << std::endl;
107 #endif
108  _config |= LOCAL_SIZE;
109  _clientDescr.llen = _llen = elt_nb;
110 }
111 
112 
113 PieceToSend*
114 Identity::computePiecesToSend(unsigned& size_out)
115 {
116 
117  PieceToSend * sched;
118 
119 #ifdef DEBUG_INTERNAL
120  std::cerr << "computePiecesToSend-------------------- in\n";
121  std::cerr << __FUNCTION__ << ": config = "<<_config<<endl;
122 #endif
123 
124  if (_config != CORRECT_CONFIG) {
125  std::cerr << "Identity: incorrect configuration state "<< _config<<"/"<<CORRECT_CONFIG<<endl;
126  abort();
127  }
128 
129  sched = new PieceToSend[1];
130  size_out = 1;
131 
132  sched[0].sourceNode = _nodeRank; // my self :)
133  sched[0].destNode = _nodeRank; // the corresponding node
134  sched[0].size = _llen; // msg size
135  sched[0].id = (void*) -1; /* not used */
136 
137 
138 #ifdef DEBUG_INTERNAL
139  std::cerr << "computePiecesToSend-------------------- done\n";
140 #endif
141 
142  return sched;
143 }
144 
145 void
146 Identity::setDataPtr(void* dataPtr)
147 {
148  _clientBuffer = (char *) dataPtr;
149 #ifdef DEBUG_INTERNAL
150  cerr << "-- _clientBuffer set to "<<dataPtr<<endl;
151 #endif
152 }
153 
154 void *
155 Identity::getClientData(void *pid, int dnode, long & remaining_size_octet, long & returned_length_element, bool & end)
156 {
157  if (remaining_size_octet < _llen) {
158  std::cerr << "Identity: not yet implemented !\n";
159  abort();
160  }
161 
162 #ifdef DEBUG_INTERNAL
163  std::cerr << __FUNCTION__ << ": getClientData returns #elt: "<<_llen<<endl;
164 #endif
165 
166  remaining_size_octet-= _llen;
167  returned_length_element= _llen;
168  end=true;
169 
170  return _clientBuffer;
171 }
172 
173 void
174 Identity::clientFree() // always called at the end of an invocation (reset some variables)
175 {
176 
177 #ifdef DEBUG_INTERNAL
178  std::cerr << "-- clientFree\n";
179 #endif
180 }
181 
182 void *
184 {
185 #ifdef DEBUG_INTERNAL
186  std::cerr << "-- descr:llen: "<<_clientDescr.llen<<std::endl;
187 #endif
188  return &_clientDescr;
189 }
190 
191 bool
192 Identity::insertData(void* rcptBuf, unsigned long element_nb)
193 {
194  // cp from recpBuf to _serverBuffer
195 #ifdef DEBUG_INTERNAL
196  std::cerr << "-- insertData "<<endl;
197 #endif
198 
199  if (element_nb != _llen) {
200  std::cerr << "Identity: not yet implemented !\n";
201  abort();
202  }
203 
204  unsigned long llen = element_nb*_unitsize;
205  memcpy(_serverBuffer, rcptBuf, llen);
206 
207  return true;
208 }
209 
210 void *
211 Identity::getServerData(long & length) // in element !
212 {
213  length= _llen;
214 #ifdef DEBUG_INTERNAL
215  std::cerr << "-- getServerData: ptr : "<<(void*)_serverBuffer<<" #element:"<<length<<std::endl;
216 #endif
217  return (void*) _serverBuffer;
218 }
219 
220 void
221 Identity::setDescr(void * descr)
222 {
223  std::cerr << "-- insertData "<<endl;
224 
226 
227  // Descr already received
228 
229  if ( _serverBuffer == NULL)
230  {
231  // 1st time -> allocate memory & init
232  //this->setEltSize(_descr->usz); BUG: usz can be different in client and server (32bit vs 64bit)
233  unsigned long len = _serverDescr->llen*_unitsize;
235 
236 #ifdef DEBUG_INTERNAL
237  fprintf(stderr, "-- setDescr: stopo: %ld\tdtopo: %ld\n",_sTopo.total, _dTopo.total);
238  fprintf(stderr, " setDescr: local len: %ld", _serverDescr->llen);
239 #endif
240  _serverBuffer = (char*) malloc(len);
241 #ifdef DEBUG_INTERNAL
242  std::cerr << "-- serverMalloc: "<<(void*)_serverBuffer<<" - "<<_llen<<endl;
243 #endif
244  _serverToReceived = len;
245  }
246 }
247 
248 void
250 {
251 #ifdef DEBUG_INTERNAL
252  std::cerr << "-- serverFree: "<<(void*)_serverBuffer<<endl;
253 #endif
254  free(_serverBuffer);
255  _serverBuffer=NULL; // the orb (or the user) need to free the memory!
256 }
257 
virtual PieceToSend * computePiecesToSend(unsigned &size)
Definition: Identity.cc:114
#define CORRECT_CONFIG
Definition: Identity.cc:9
IdentityLib::IdentityDescr * _serverDescr
Definition: Identity.h:38
PaCO::PacoTopology_t _dTopo
Definition: Identity.h:22
char * _serverBuffer
Definition: Identity.h:36
virtual void setDescr(void *descr)
Definition: Identity.cc:221
#define SRC_TOPOLOGY
Definition: Identity.cc:4
virtual void * getClientData(void *pid, int server_node, long &size, long &length, bool &end)
Definition: Identity.cc:155
virtual void serverFree()
Definition: Identity.cc:249
PaCO::PacoTopology_t _sTopo
Definition: Identity.h:21
virtual PaCO::PacoTopology_t getDestTopology()
Definition: Identity.cc:70
virtual void setDestTopology(PaCO::PacoTopology_t topo)
Definition: Identity.cc:59
char * _clientBuffer
Definition: Identity.h:30
unsigned _config
Definition: Identity.h:19
Identity()
Definition: Identity.cc:18
virtual PaCO::PacoTopology_t getSourceTopology()
Definition: Identity.cc:51
virtual void setDataPtr(void *dataPtr)
Definition: Identity.cc:146
virtual ~Identity()
Definition: Identity.cc:36
virtual void * getDescr()
Definition: Identity.cc:183
virtual void setNodeRank(long Rank)
Definition: Identity.cc:78
unsigned long total
Definition: PaCO++.idl:35
unsigned _unitsize
Definition: Identity.h:26
#define LOCAL_SIZE
Definition: Identity.cc:7
IdentityLib::IdentityDescr _clientDescr
Definition: Identity.h:31
virtual bool insertData(void *rcptBuf, unsigned long element_nb)
Definition: Identity.cc:192
virtual void clientFree()
Definition: Identity.cc:174
unsigned _llen
Definition: Identity.h:25
#define ELEMENT_SIZE
Definition: Identity.cc:6
void setEltSize(unsigned long size)
Definition: Identity.cc:93
virtual void * getServerData(long &length)
Definition: Identity.cc:211
unsigned _nodeRank
Definition: Identity.h:24
virtual long getNodeRank()
Definition: Identity.cc:87
#define DST_TOPOLOGY
Definition: Identity.cc:5
virtual void setSourceTopology(PaCO::PacoTopology_t topo)
Definition: Identity.cc:41
void setLocalNbElt(unsigned long elt_nb)
Definition: Identity.cc:103
unsigned long _serverToReceived
Definition: Identity.h:35