PaCO++  0.05
GaBro.cc
Go to the documentation of this file.
1 #include "GaBro.h"
2 #include <iostream>
3 
5 {
6  // Common
7  _data_size = -1;
8  _data_elt_nb = -1;
9  _my_rank = 0;
10  _server_nb_nodes = 1;
11 
12  // Client side
13  _client_buffer = NULL;
14  _pos = NULL;
15  _elt_node_nb = -1;
16  _node_pos = -1;
17 
18  this->setComId(-1);
19 
20  // Server side
21  _server_buffer = NULL;
22  _nb_rcp = NULL;
23  _current_rcp = -1;
24  _total_data_nb = -1;
25  _node_data_nb = -1;
26  _current_data_size = -1;
27  _current_pos = -1;
28 }
29 
31 {
32  delete _pos;
33  delete _nb_rcp;
34  for(info_list_map_t::iterator it=_info_list_map.begin(); it!=_info_list_map.end(); ++it)
35  {
36  info_t* info = it->second;
37  delete info;
38  _info_list_map.erase(it);
39  }
40  _info_list_map.clear();
41 }
42 
43 void
45 {
46  _srcTopo = topo;
47  _nb_rcp = new long[_srcTopo.total];
48  for (unsigned int i=0; i<_srcTopo.total; i++)
49  {
50  _nb_rcp[i] = -1;
51  }
52 }
53 
56 {
57  return _srcTopo;
58 }
59 
60 void
62 {
63  _destTopo = topo;
64  _server_nb_nodes = topo.total;
65  // _cur_info->_server_nb_nodes = _server_nb_nodes;
66  _pos = new int[_server_nb_nodes];
67  for (int i=0; i<_server_nb_nodes; i++)
68  {
69  _pos[i] = 0;
70  }
71 }
72 
75 {
76  return _destTopo;
77 }
78 
79 void
81 {
82  _my_rank = Rank;
83  _descr.sender = Rank;
84 }
85 
86 long
88 {
89  return _my_rank;
90 }
91 
92 void
94 {
95  _data_size = size;
96  // _cur_info->_data_size = _data_size;
97 }
98 
99 void
101 {
102  _data_elt_nb = elt_nb;
104 }
105 
106 void
107 GaBro::setNodeNbElt(long elt_node_nb)
108 {
109  _elt_node_nb = elt_node_nb;
110  // _cur_info->_elt_node_nb = _elt_node_nb;
112 }
113 
114 void
115 GaBro::setNodePos(long node_pos)
116 {
117  _node_pos = node_pos;
119 }
120 
121 PieceToSend*
123 {
124  size = _server_nb_nodes;
125  // Compute total data length
126  long total_length = _data_size * _elt_node_nb;
127  // We send at each server node the same data
128  PieceToSend * local_vector = new PieceToSend[_server_nb_nodes];
129  for (int i = 0; i < _server_nb_nodes; i++)
130  {
131  local_vector[i].sourceNode = _my_rank;
132  local_vector[i].destNode = i;
133  local_vector[i].size = total_length;
134  }
135  return local_vector;
136 }
137 
138 void
139 GaBro::setDataPtr(void* dataPtr)
140 {
141  _client_buffer = (char *) dataPtr;
142 }
143 
144 void *
145 GaBro::getClientData(void* pid, int server_node, long & size, long & length, bool & end)
146 {
147  void * result = NULL;
148  end = true;
149  //std:cerr << _data_size << " " << _data_elt_nb << " " << _pos[server_node] << endl;
150  long rst_data = (_data_size * _elt_node_nb) - _pos[server_node];
151  //std:cerr << "Size : " << size << endl;
152  //std:cerr << "Rst_data : " << rst_data << endl;
153  if (size == rst_data)
154  {
155  length = size / _data_size;
156  _descr.current_data_size = size;
157  result = (void *)&_client_buffer[_pos[server_node]];
158  _pos[server_node] = _pos[server_node] + size;
159  size = 0;
160  }
161  else if (size > rst_data)
162  {
163  length = rst_data / _data_size;
164  _descr.current_data_size = rst_data;
165  result = (void *)&_client_buffer[_pos[server_node]];
166  _pos[server_node] = _pos[server_node] + rst_data;
167  size = size - rst_data;
168  }
169  else if (size < rst_data)
170  {
171  length = size / _data_size;
172  _descr.current_data_size = size;
173  result = (void *)&_client_buffer[_pos[server_node]];
174  _pos[server_node] = _pos[server_node] + size;
175  size = 0;
176  }
177  return result;
178 }
179 
180 void
182 {
183  for (int i=0; i<_server_nb_nodes; i++)
184  {
185  _pos[i] = 0;
186  }
187 }
188 
189 void *
191 {
192  return &_descr;
193 }
194 
195 bool
196 GaBro::insertData(void* rcptBuf, unsigned long element_nb)
197 {
198 
199  bool ret = true;
200  if (element_nb != 0)
201  {
202  if (_server_buffer == NULL)
203  {
204  _server_buffer = (char *)malloc(_data_size * _total_data_nb);
205  }
206  // Copy the buffer !!!
207 // cerr << "current_pos : " << _current_pos << endl;
208 // cerr << "data_size : " << _data_size << endl;
209 // cerr << "nb_rcp[_current_rcp] " << _nb_rcp[_current_rcp] << endl;
210 
211  long current_sender_pos = (_current_pos * _data_size) + ((_data_size * _node_data_nb) - _nb_rcp[_current_rcp]);
212 // cerr << "current_sender_pos : " << current_sender_pos << endl;
213  memcpy((void *)&(_server_buffer[current_sender_pos]), rcptBuf, _current_data_size);
215  }
216  for (unsigned int i=0; i<_srcTopo.total; i++)
217  {
218  if (_nb_rcp[i] != 0)
219  {
220  ret = false;
221  }
222  }
223  return ret;
224 }
225 
226 void *
227 GaBro::getServerData(long & length)
228 {
229  length = _total_data_nb;
230  return _server_buffer;
231 }
232 
233 void
234 GaBro::setDescr(void * descr)
235 {
236  _descr = *((GaBroLib::GaBroDescr*) descr);
237  if (_current_rcp == -1)
238  {
239  // First piece reception !
241  }
246  //std:cerr << _current_data_size << endl;
247  if (_nb_rcp[_current_rcp] == -1)
248  {
250  }
251 }
252 
253 void
255 {
256  _current_rcp = -1;
257  _current_pos = -1;
258  _server_buffer = NULL;
259  for (unsigned int i=0; i<_srcTopo.total; i++)
260  {
261  _nb_rcp[i] = -1;
262  }
263 }
264 
265 bool
267 {
268  info_t * _infolists;
269  info_list_map_t::iterator it = _info_list_map.find(id);
270  if (it == _info_list_map.end())
271  {
272  _infolists = new info_t();
273  _infolists->_data_size = _data_size;
274  _infolists->_elt_node_nb = _elt_node_nb;
275  _infolists->_server_nb_nodes = _server_nb_nodes;
276  _infolists->_data_elt_nb = _data_elt_nb;
277  _infolists->_node_pos = _node_pos;
278  _info_list_map[id] = _infolists;
279  }
280  else
281  {
282  _infolists = it->second;
283  }
284  _cur_info = _infolists;
285  _cur_id = id;
286  _data_size = _infolists->_data_size;
287  _elt_node_nb = _infolists->_elt_node_nb;
288  _data_elt_nb = _infolists->_data_elt_nb;
289  _server_nb_nodes = _infolists->_server_nb_nodes;
290  _node_pos = _infolists->_node_pos;
291 
295 
296  //std:cerr << _data_size << " " << _elt_node_nb << " " << _server_nb_nodes <<endl;
297  return true;
298 }
299 
300 bool
302 {
303  if (id == -1) {
304  // cerr << "freeComId: not allowed to free com id -1 (ignoring)\n";
305  return true;
306  }
307  if (_cur_id == id) {
308  // cerr << "freeComId: not allowed to free current com (ignoring)\n";
309  return true;
310  }
311  // cerr << "freeComid: communication id: "<<id<<endl;
312  info_list_map_t::iterator it = _info_list_map.find(id);
313  if (it != _info_list_map.end() )
314  {
315  info_t* info = it->second;
316  delete info;
317  _info_list_map.erase(it);
318  }
319  return true;
320 }
long _cur_id
Definition: GaBro.h:77
long * _nb_rcp
Definition: GaBro.h:82
info_list_map_t _info_list_map
Definition: GaBro.h:75
virtual bool insertData(void *rcptBuf, unsigned long element_nb)
Definition: GaBro.cc:196
long _my_rank
Definition: GaBro.h:57
long _server_nb_nodes
Definition: GaBro.h:58
long _data_elt_nb
Definition: GaBro.h:56
virtual void * getDescr()
Definition: GaBro.cc:190
virtual PaCO::PacoTopology_t getDestTopology()
Definition: GaBro.cc:74
char * _server_buffer
Definition: GaBro.h:81
long _node_pos
Definition: GaBro.h:64
virtual void clientFree()
Definition: GaBro.cc:181
virtual void setDescr(void *descr)
Definition: GaBro.cc:234
virtual void setSourceTopology(PaCO::PacoTopology_t topo)
Definition: GaBro.cc:44
long _data_size
Definition: GaBro.h:67
GaBro()
Definition: GaBro.cc:4
long _data_elt_nb
Definition: GaBro.h:70
PaCO::PacoTopology_t _destTopo
Definition: GaBro.h:49
char * _client_buffer
Definition: GaBro.h:61
virtual bool freeComId(long id)
Definition: GaBro.cc:301
long _current_data_size
Definition: GaBro.h:87
PaCO::PacoTopology_t _srcTopo
Definition: GaBro.h:48
void setNodeNbElt(long elt_node_nb)
Definition: GaBro.cc:107
long _current_pos
Definition: GaBro.h:84
long _server_nb_nodes
Definition: GaBro.h:69
void setEltSize(long size)
Definition: GaBro.cc:93
void setNodePos(long node_pos)
Definition: GaBro.cc:115
long _elt_node_nb
Definition: GaBro.h:63
int * _pos
Definition: GaBro.h:62
unsigned long total
Definition: PaCO++.idl:35
virtual PieceToSend * computePiecesToSend(unsigned &size)
Definition: GaBro.cc:122
long _elt_node_nb
Definition: GaBro.h:68
virtual void * getClientData(void *pid, int server_node, long &size, long &length, bool &end)
Definition: GaBro.cc:145
long _node_pos
Definition: GaBro.h:71
virtual PaCO::PacoTopology_t getSourceTopology()
Definition: GaBro.cc:55
virtual void setNodeRank(long Rank)
Definition: GaBro.cc:80
virtual ~GaBro()
Definition: GaBro.cc:30
void setTotalNbElt(long elt_nb)
Definition: GaBro.cc:100
virtual void serverFree()
Definition: GaBro.cc:254
int _current_rcp
Definition: GaBro.h:83
info_t * _cur_info
Definition: GaBro.h:78
GaBroLib::GaBroDescr _descr
Definition: GaBro.h:52
virtual bool setComId(long id)
Definition: GaBro.cc:266
long _data_size
Definition: GaBro.h:55
long _total_data_nb
Definition: GaBro.h:85
virtual void setDestTopology(PaCO::PacoTopology_t topo)
Definition: GaBro.cc:61
virtual void setDataPtr(void *dataPtr)
Definition: GaBro.cc:139
virtual void * getServerData(long &length)
Definition: GaBro.cc:227
virtual long getNodeRank()
Definition: GaBro.cc:87
long _node_data_nb
Definition: GaBro.h:86