PaCO++  0.05
BasicBC.cc
Go to the documentation of this file.
1 #include "BasicBC.h"
2 #include <iostream>
3 
4 #define SRC_TOPOLOGY 1
5 #define DST_TOPOLOGY 2
6 #define ELEMENT_SIZE 4
7 #define TOTAL_SIZE 8
8 #define DISTRIBUTION_TYPE 16
9 
10 #undef DEBUG_INTERNAL
11 #undef DEBUG_INTERNAL2
12 
14 
15 // Compute the owner of a bloc accoring a cyclic distribution
16 static inline unsigned OwnerBloc(const unsigned bid, const unsigned nbprocs) {
17  return bid % nbprocs;
18 }
19 
21 
22 // Compute the id of a proc owning an element
23 inline static unsigned getProcRangeInf(unsigned low, unsigned bsz) {
24  return low / bsz; // first remote node
25 }
26 
27 // Compue the id of the proc owning the previous element
28 inline static unsigned getProcRangeSup(unsigned high, unsigned bsz) {
29  return (high-1) / bsz; // last remote node
30 }
31 
33 
34 // Compute the number of bloc a given processor owns accoring to a cyclic distribution
35 static inline unsigned NumberOfBlocProc(const unsigned glen, const unsigned nbprocs,
36  const unsigned bsz, const unsigned rank) {
37  unsigned nbbloc = (glen + bsz - 1 ) / bsz;
38  return (nbbloc / nbprocs) + (rank < (nbbloc % nbprocs ) ) ;
39 }
40 
42 
43 // Compute the number of element of a given bloc (local bloc pos)
44 // on a proc of given rank according to a cyclic distribution
45 static inline unsigned BlocNumberOfElementProc(const unsigned glen, const unsigned rank,
46  const unsigned nbprocs, const unsigned bsz,
47  const unsigned pos) {
48 
49  unsigned long low = ( pos * nbprocs + rank ) * bsz;
50  unsigned long end = low + bsz;
51  unsigned long high = (glen < end ? glen : end);
52 
53  return ( high - low );
54 
55 }
56 
58 
59 // compute the global low bounds of local bloc number pos
60 static inline unsigned computeBlocBoundInf(const unsigned bsz, const unsigned rank,
61  const unsigned nbprocs, const unsigned pos) {
62  return ( pos * nbprocs + rank) * bsz;
63 }
64 
66 
67 // Compute the global bounds (low & high) of a given bloc (local bloc pos)
68 // on a proc of given rank according to a cyclic distribution
69 static inline void computeBlocBounds(unsigned long *low, unsigned long *high,
70  const unsigned glen, const unsigned rank,
71  const unsigned nbprocs, const unsigned bsz,
72  const unsigned pos) {
73  unsigned long start = (pos * nbprocs + rank) * bsz;
74  unsigned long end = start + bsz;
75  *low = start;
76  *high = ((glen <= end)?glen:end); // min
77 }
78 
80 
81 // Compute the number of element own by the processor of rank rank
82 static inline unsigned TotalNumberOfElementProc(const unsigned glen, const unsigned rank,
83  const unsigned nbprocs, const unsigned bsz) {
84 
85  unsigned nbblocfull = NumberOfBlocProc(glen, nbprocs, bsz, rank) - 1;
86  // Is the last full ?
87  unsigned long low = ( nbblocfull * nbprocs + rank ) * bsz;
88  unsigned long end = low + bsz;
89  unsigned long high = (glen < end ? glen : end);
90 
91  return nbblocfull * bsz + ( high - low );
92 }
93 
95 
96 // Compute the size in octet of a bloc according to the given parameter
97 //
98 static inline unsigned blocSize(const unsigned glen, const unsigned nbprocs,
99  const BasicBC_param_t& param) {
100  switch(param.type)
101  {
102  case BASICBC_BLOC:
103  {
104  unsigned nbbloc = (glen + param.unitsize - 1) / param.unitsize;
105  return ((nbbloc + nbprocs - 1 ) / nbprocs) * param.unitsize;
106  }
107  case BASICBC_CYCLIC: return param.unitsize; break;
108  case BASICBC_BLOCCYCLIC: return param.blocsize*param.unitsize; break;
109  }
110  return 0;
111 }
112 
116 
118 {
119  // Common
120  _config = 0;
121 
122  // By default 1->1 :)
123  _sTopo.total=1;
124  _dTopo.total=1;
126  _nodeRank=0;
127 
128  // Client side
129  _clientBuffer=NULL;
131 
132  this->internalSetComId(-1); // set anonymous & init iterator, infolists & _cur_id
133 
134  // Server side
135  _serverDescr=NULL;
136  _serverBuffer=NULL;
137 }
138 
140 {
141  for(info_list_map_t::iterator it=_info_list_map.begin(); it!=_info_list_map.end(); ++it)
142  this->internalFreeComId(it);
143  _info_list_map.clear();
144 }
145 
146 void
148 {
149 #ifdef DEBUG_INTERNAL
150  std::cerr << "-- setSourceTopology: " << topo.total << std::endl;
151 #endif
153  _sTopo = topo;
154 }
155 
158 {
159  std::cerr << "****** Why is the method " << __FUNCTION__ << "called?\n";
160  abort();
161  return _sTopo;
162 }
163 
164 void
166 {
167 #ifdef DEBUG_INTERNAL
168  std::cerr << "-- setDestTopology: " << topo.total << std::endl;
169 #endif
171 
172  if ( _dTopo.total == topo.total ) return ; // Nothing change !!!!
173 
174  // Delete old entries wrt to old state
175  info_list_map_t::iterator it = _info_list_map.find(_cur_id);
176  this->internalFreeComId(it);
177  _info_list_map.erase(it);
178 
179  // Change the state of the object
180  _dTopo = topo;
181 
182  // Set new entries
183  this->internalSetComId(_cur_id);
184 
185  // BUG: MUST ALSO DELETE ALL ENTRIES IN _info_list_map
186 
187 }
188 
191 {
192  std::cerr << "****** Why is the method " << __FUNCTION__ << "called?\n";
193  abort();
194  return _dTopo;
195 }
196 
197 void
199 {
200 #ifdef DEBUG_INTERNAL
201  std::cerr << "-- setNodeRank: " << Rank << std::endl;
202 #endif
203  _nodeRank = Rank;
204 }
205 
206 long
208 {
209  return _nodeRank;
210 }
211 
212 void
213 BasicBC::setBlocSize(unsigned long size)
214 {
215 #ifdef DEBUG_INTERNAL
216  std::cerr << "-- setBlocSize: " << size << std::endl;
217 #endif
219  switch(size) {
220  case 0:
221 #ifdef DEBUG_INTERNAL
222  cout << "Selecting a BLOC distribution\n";
223 #endif
225  _clientDescr.bsz = 0;
226  break;
227  case 1:
228 #ifdef DEBUG_INTERNAL
229  cout << "Selecting a CYCLIC distribution\n";
230 #endif
232  _clientDescr.bsz = 1;
233  break;
234  default:
235 #ifdef DEBUG_INTERNAL
236  cout << "Selecting a BLOCCYCLIC with bsz= " << size << " \n";
237 #endif
239  _clientDescr.bsz = _param.blocsize = size;
240  }
241 }
242 
243 void
244 BasicBC::setEltSize(unsigned long size)
245 {
246 #ifdef DEBUG_INTERNAL
247  std::cerr << "-- setEltSize: " << size << std::endl;
248 #endif
250  _param.unitsize = size;
251 }
252 
253 void
254 BasicBC::setTotalNbElt(unsigned long elt_nb)
255 {
256 #ifdef DEBUG_INTERNAL
257  std::cerr << "-- setTotalNbElt: " << elt_nb << std::endl;
258 #endif
259  _config |= TOTAL_SIZE;
260  _clientDescr.glen = _glen = elt_nb;
261 }
262 
263 
264 PieceToSend*
265 BasicBC::computePiecesToSend(unsigned& size_out)
266 {
267  /*
268  * store src/dst/sz/start
269  *
270  * where start is a local offset to apply to the vector
271  *
272  */
273 
274  PieceToSend * sched;
275  unsigned long golen = _glen*_param.unitsize;
276 
277  // We need to compute _lstart and _llen
278  _sbsz = blocSize( golen, _sTopo.total, _param);
280  _lstart = (_lstart < golen ? _lstart:golen);
282 
283 #ifdef DEBUG_INTERNAL
284  // std::cerr << "In computePiecesToSend-------------------- all in octet !\n";
285 
286  fprintf(stderr, "-- stopo: %ld\tdtopo: %ld\n", _sTopo.total, _dTopo.total);
287  fprintf(stderr, "-- golen: %ld\ttype: %d\tsd.start %d\tllen: %d\n", golen,
289 #endif
290 
291  if (_sTopo.total == _dTopo.total) {
292 #ifdef DEBUG_INTERNAL
293  fprintf(stderr, "-- easy: n<->n case !\n");
294 #endif
295  size_out = 1;
296  sched = new PieceToSend[1];
297  sched[0].sourceNode = _nodeRank; // my self :)
298  sched[0].destNode = _nodeRank; // the corresponding node
299  sched[0].size = _llen; // msg size
300 
301  info_t* inf = new info_t();
302 
303  inf->gstart = _lstart/_param.unitsize; // used start as id -> same at server side
304  inf->lstart = 0; // do not apply any offset to local ptr
305  inf->msg_size = _llen;
306  inf->sent_size = 0;
307 
308  // add inf to the list
309  _infolists[_nodeRank]->push_back(inf);
310  // sched points to the list
311  sched[0].id = (void*) _infolists[_nodeRank];
312 
313 #ifdef DEBUG_INTERNAL
314  fprintf(stderr, "-- %2d -> %2d : gstart:%2u lstart:%2u len:%2d\n",
315  sched[0].sourceNode, sched[0].destNode, inf->gstart, inf->lstart, inf->msg_size);
316 #endif
317 
318  } else {
319  if (_param.type == BASICBC_BLOC ) {
320  // that's a standard bloc redistribution
321 #ifdef DEBUG_INTERNAL
322  fprintf(stderr, "-- medium: n<->m bloc redistribution case !\n");
323 #endif
324 
325  unsigned long slow;
326  unsigned long shigh;
327  computeBlocBounds(&slow, &shigh, golen, _nodeRank, _sTopo.total, _sbsz, 0);
328 
329 #ifdef DEBUG_INTERNAL
330  std::cerr << "-- sbsz: "<<_sbsz<<" sbounds: "<<slow<<" - "<<shigh<<endl;
331 #endif
332 
333  unsigned dbsz = blocSize(golen, _dTopo.total, _param);
334 
335 #ifdef DEBUG_INTERNAL
336  std::cerr << "-- dbsz: "<<dbsz<<endl;
337 #endif
338 
339  unsigned fpid, lpid;
340  fpid = getProcRangeInf(slow, dbsz);
341  lpid = getProcRangeSup(shigh, dbsz);
342 
343 #ifdef DEBUG_INTERNAL
344  fprintf(stderr, "-- loop from %d to %d width dtotal: %ld\n", fpid, lpid, _dTopo.total);
345 #endif
346 
347  // for each dest bloc
348  size_out = lpid-fpid+1;
349  sched = new PieceToSend[size_out];
350  for(unsigned i=fpid; i <= lpid; i++) {
351  PieceToSend& s = sched[i-fpid];
352  s.sourceNode = _nodeRank;
353  s.destNode = i;
354 
355  info_t* inf = new info_t();
356 
357  unsigned tmp = i*dbsz;
358  unsigned tmp2;
359  tmp2 = ( slow >= tmp)?slow:tmp; // max : global offset in octet as ID
360  inf->gstart = tmp2 / _param.unitsize;
361  inf->lstart = tmp2 - _lstart;
362 
363  tmp += dbsz;
364  unsigned end = ( shigh <= tmp)?shigh:tmp; // min
365 
366  inf->msg_size = s.size = end - tmp2;
367  inf->sent_size = 0;
368 
369  // add inf to the list
370  _infolists[i-fpid]->push_back(inf);
371  // sched points to the list
372  s.id = (void*) _infolists[i-fpid];
373 
374 #ifdef DEBUG_INTERNAL
375  fprintf(stderr, "-- %2d -> %2d : gstart:%2u lstart:%2u len:%2d\n",
376  s.sourceNode, s.destNode, inf->gstart, inf->lstart, inf->msg_size);
377 #endif
378  }
379  } else {
380  // it is a bloccyclic distribution
381 
382 #ifdef DEBUG_INTERNAL
383  fprintf(stderr, "-- hard: n<->m bloccyclic redistribution case !\n");
384 #endif
385 
386  unsigned stbsz = _sbsz * _sTopo.total;
387  unsigned nbbloc = NumberOfBlocProc(golen, _sTopo.total, _sbsz, _nodeRank);
388 
389 #ifdef DEBUG_INTERNAL
390  std::cerr << "-- sbsz: "<<_sbsz<<" nbbloc: "<<nbbloc<<endl;
391 #endif
392 
393  // for each src bloc, find a dst node
394  // But only one struct for each dst -> pre-count
395 
396  // should be equal to the number of real dest !
397  size_out = 0;
398  unsigned *tmp_dnb = (unsigned*) calloc(_dTopo.total, sizeof(unsigned)); // zeroed array
399  PieceToSend **tmp_dor = (PieceToSend**) calloc(_dTopo.total, sizeof(PieceToSend*)); // zeroed array
400  for(unsigned b=0; b<nbbloc; b++) {
401  unsigned gb = b * _sTopo.total + _nodeRank; // global bloc id
402  unsigned drank = OwnerBloc(gb, _dTopo.total);
403  if (tmp_dnb[drank]++ == 0) // detect if it is the 1st time
404  size_out++;
405  }
406  // Allocating output
407  sched = new PieceToSend[size_out];
408  unsigned cur=0;
409  for(unsigned i=0; i<_dTopo.total; i++) {
410  sched[cur].sourceNode = _nodeRank;
411  sched[cur].destNode = i;
412  sched[cur].size = 0;
413  sched[cur].id = (void*) _infolists[i];
414  tmp_dor[i] = &sched[cur]; // an index if valid only if tmp_dnb[index]>0 !!!!
415  cur+= (tmp_dnb[i]>0?1:0); // increment order only if this dest is not zero
416  }
417 
418 #ifdef DEBUG_INTERNAL
419  cerr << "-- size_out: "<<size_out<<endl;
420 #endif
421 
422  for(unsigned b=0; b<nbbloc; b++) {
423  unsigned gb = b * _sTopo.total + _nodeRank; // global bloc id
424  unsigned drank = OwnerBloc(gb, _dTopo.total);
425 
426  PieceToSend* s = tmp_dor[drank];
427 
428  // Allocate new element
429  info_t* inf = new info_t();
430 
431  inf->gstart = ((stbsz*b) + (_nodeRank*_sbsz))/ _param.unitsize;
432  inf->lstart = b * _sbsz;
433  inf->msg_size = BlocNumberOfElementProc(golen, _nodeRank, _sTopo.total, _sbsz, b);
434  inf->sent_size = 0;
435 
436  // Accumulate msg length in PieceToSend
437  s->size += inf->msg_size;
438 
439  // insert it in the list
440  info_list_t* ilsp = (info_list_t*) s->id; // pointer to a list
441  ilsp->push_back(inf);
442 
443 
444 #ifdef DEBUG_INTERNAL
445  fprintf(stderr, "-- %2d -> %2d : gstart:%2u lstart:%2u len:%2d\n",
446  s->sourceNode, s->destNode, inf->gstart, inf->lstart, inf->msg_size);
447 #endif
448  }
449  }
450  }
451 
452 #ifdef DEBUG_INTERNAL
453  // std::cerr << "computePiecesToSend-------------------- done\n";
454 #endif
455 
456  return sched;
457 }
458 
459 void
460 BasicBC::setDataPtr(void* dataPtr)
461 {
462  _clientBuffer = (char *) dataPtr;
463 #ifdef DEBUG_INTERNAL
464  cerr << "-- _clientBuffer set to "<<dataPtr<<endl;
465 #endif
466 }
467 
468 void *
469 BasicBC::getClientData(void *pid, int dnode, long & remaining_size_octet, long & returned_length_element, bool & end)
470 {
471  info_list_t* ilsp = (info_list_t*) pid;
472 
473 #ifdef DEBUG_INTERNAL2
474  std::cerr << "-- getClientData : _clientBuffer=" << (void*) _clientBuffer << std::endl;
475  std::cerr << "-- getClientData : " << dnode << " " << remaining_size_octet << std::endl;
476 #endif
477 
478  if (_descr_to_be_cleaned) {
479  _descr_to_be_cleaned = false;
480  _clientDescr.ids.length(0);
481  }
482 
483  // look for 1st one not "empty"
484  long rst_data=0;
485  info_list_t::const_iterator ci;
486  for(ci=ilsp->begin(); ci!=ilsp->end(); ++ci) {
487  rst_data = (*ci)->msg_size - (*ci)->sent_size;
488  if (rst_data>0)
489  break;
490  }
491 
492  // No more element: return immediatly
493  if (ci == ilsp->end())
494  {
495 #ifdef DEBUG_INTERNAL2
496  std::cerr << "-- getClientData0 : no more block for this argument\n";
497 #endif
498  returned_length_element = 0;
499  end = true;
500  return NULL;
501  }
502  // No more data of this element but there are more
503  if (rst_data == 0)
504  {
505 #ifdef DEBUG_INTERNAL2
506  std::cerr << "-- getClientData0 : no more data for this bloc\n";
507 #endif
508  returned_length_element = 0;
509  end = false;
510  return NULL;
511  }
512  // *ci assumed ok here (else return above !!)
513  info_t* info = *ci;
514 
515  // More asked data as I can provide -> give all the data of this bloc
516  if (remaining_size_octet >= rst_data)
517  {
518  unsigned descr_len = _clientDescr.ids.length();
519  _clientDescr.ids.length(descr_len+1);
520  _clientDescr.ids[descr_len] = info->gstart+(info->sent_size/_param.unitsize);
521 
522  unsigned start = info->lstart+info->sent_size;
523  info->sent_size += rst_data;
524  returned_length_element = rst_data / _param.unitsize; // should divide;
525  remaining_size_octet -= rst_data;
526  end = (remaining_size_octet == 0);
527 
528 #ifdef DEBUG_INTERNAL2
529  std::cerr << "-- getClientData1 : gstart:"<<_clientDescr.ids[descr_len]<<" #element:"<<returned_length_element<<endl;
530 #endif
531 
532  return (void *)&_clientBuffer[start];
533  }
534  else
535  {
536  // I have more data than requested
537  unsigned descr_len = _clientDescr.ids.length();
538  _clientDescr.ids.length(descr_len+1);
539  _clientDescr.ids[descr_len] = info->gstart+(info->sent_size/_param.unitsize);
540 
541  unsigned start = info->lstart+info->sent_size;
542  returned_length_element = (remaining_size_octet+_param.unitsize-1)/_param.unitsize; // max
543  unsigned mlen = returned_length_element*_param.unitsize;
544  info->sent_size += mlen;
545  remaining_size_octet -= mlen;
546  end = true;
547 
548 
549 #ifdef DEBUG_INTERNAL2
550  std::cerr << "-- getClientData1 : gstart:"<<_clientDescr.ids[descr_len]<<" #element:"<<returned_length_element<<endl;
551 #endif
552 
553  return (void *)&_clientBuffer[start];
554  }
555 }
556 
557 void
558 BasicBC::clientFree() // always called at the end of an invocation (reset some variables)
559 {
560 
561 #ifdef DEBUG_INTERNAL
562  std::cerr << "-- clientFree\n";
563 #endif
564  if (_cur_id == -1) {
565  this->clear_info_list();
566  } else {
567  this->reset_info_list();
568  }
569 }
570 
571 void *
573 {
574 #ifdef DEBUG_INTERNAL
575  std::cerr << "-- descr: glen: "<<_clientDescr.glen<<" #element: "<<_clientDescr.ids.length()<<" bsz: "<<_clientDescr.bsz;
576  for(unsigned i=0;i<_clientDescr.ids.length();i++) {
577  std::cerr<<" "<<_clientDescr.ids[i];
578  }
579  std::cerr<<std::endl;
580 #endif
581  _descr_to_be_cleaned = true;
582  return &_clientDescr;
583 }
584 
585 bool
586 BasicBC::insertData(void* rcptBuf, unsigned long element_nb)
587 {
588  // We are receiving one bloc
589  unsigned gstart = _serverDescr->ids[_descr_ids_counter++]; // in octet !!!
590  unsigned lstart;
591  unsigned llen = element_nb*_param.unitsize;
592 
593  // Need to compute lstart :(
594  if (_param.type == BASICBC_BLOC ) {
595  lstart = (gstart*_param.unitsize)/ _dbsz; // bloc number
596  lstart = (gstart*_param.unitsize) - (lstart*_dbsz);
597  } else {
598  lstart = (gstart*_param.unitsize)/ _dbsz; // bloc number
599  lstart /= _dTopo.total; // local number
600  }
601 
602  char* rptr = &_serverBuffer[lstart];
603 #ifdef DEBUG_INTERNAL
604  std::cerr << " gstart: "<< gstart<<" lstart: "<<lstart<<" #element " << element_nb<<" llen: "<<llen<<std::endl;
605 #endif
606  memcpy(rptr, rcptBuf, llen);
607 
608  _serverToReceived -= llen;
609 #ifdef DEBUG_INTERNAL
610  std::cerr << " #missing data"<<_serverToReceived<<std::endl;
611 #endif
612  return (_serverToReceived == 0);
613 }
614 
615 void *
616 BasicBC::getServerData(long & length) // in element !
617 {
618  length= _llen / _param.unitsize;
619 #ifdef DEBUG_INTERNAL
620  std::cerr << "-- getServerData: ptr : "<<(void*)_serverBuffer<<" #element:"<<length<<std::endl;
621 #endif
622  return (void*) _serverBuffer;
623 }
624 
625 void
626 BasicBC::setDescr(void * descr)
627 {
630 
631  // Descr already received
632 
633  if ( _serverBuffer == NULL)
634  {
635  // 1st time -> allocate memory & init
636  //this->setEltSize(_descr->usz); BUG: usz can be different in client and server (32bit vs 64bit)
637  unsigned long golen = _serverDescr->glen*_param.unitsize;
639  this->setBlocSize(_serverDescr->bsz);
640  _dbsz = blocSize( golen, _dTopo.total, _param);
642 
643 #ifdef DEBUG_INTERNAL
644  fprintf(stderr, "-- setDescr: stopo: %ld\tdtopo: %ld\n",_sTopo.total, _dTopo.total);
645  fprintf(stderr, " setDescr: golen: %ld\tllen %d\tbsz:%ld\n", _serverDescr->glen, _llen, _serverDescr->bsz);
646 #endif
647  _serverBuffer = (char*) malloc(_llen);
648 #ifdef DEBUG_INTERNAL
649  std::cerr << "-- serverMalloc: "<<(void*)_serverBuffer<<" - "<<_llen<<endl;
650 #endif
652  }
653 }
654 
655 void
657 {
658 #ifdef DEBUG_INTERNAL
659  std::cerr << "-- serverFree: "<<(void*)_serverBuffer<<endl;
660 #endif
661  free(_serverBuffer);
662  _serverBuffer=NULL; // the orb (or the user) need to free the memory!
663 }
664 
665 void
666 BasicBC::internalSetComId(long id) // called by constructor
667 {
668  info_list_map_t::iterator it = _info_list_map.find(id);
669 
670  if (it == _info_list_map.end() ) {
671 #ifdef DEBUG_INTERNAL
672  cerr << "setComiI: set 1st time communication id "<<id<<endl;
673 #endif
674  // we must allocate a new one
675  this->allocate_new_info_list();
676 #ifdef DEBUG_INTERNAL
677  cerr << "setComId: allocating a new _infolists: "<<_infolists<<endl;
678 #endif
680  } else {
681 #ifdef DEBUG_INTERNAL
682  cerr << "setComId: set (not 1st time) communication id "<<id<<endl;
683 #endif
684  _infolists = it->second;
685  }
686 
687  _cur_id = id;
688 }
689 
690 bool
692 {
693  if (_cur_id == id) return true; // already initialized
694 
695  this->internalSetComId(id);
696 
697  return true;
698 }
699 
700 
701 void
702 BasicBC::internalFreeComId(info_list_map_t::iterator& it)
703 {
704  if (it == _info_list_map.end() ) {
705 #ifdef DEBUG_INTERNAL
706  cerr << "freeComid: communication id not found (ignoring)\n";
707 #endif
708  } else {
709 #ifdef DEBUG_INTERNAL
710  cerr << "freeComid: freeing communication "<<endl;
711 #endif
712  info_list_t** info = it->second;
713  // for each destNode
714  for(unsigned i=0; i< _dTopo.total; i++) {
715  // for each element of the list
716  info_list_t *ilp = info[i];
717  for(info_list_t::const_iterator ci=ilp->begin(); ci!=ilp->end(); ++ci)
718  delete (*ci);
719  info[i] -> clear();
720  delete info[i];
721  }
722  }
723 }
724 
725 bool
727 {
728  if (id == -1) {
729 #ifdef DEBUG_INTERNAL
730  cerr << "freeComId: not allowed to free com id -1 (ignoring)\n";
731 #endif
732  return true;
733  }
734 
735  if (_cur_id == id) {
736 #ifdef DEBUG_INTERNAL
737  cerr << "freeComId: not allowed to free current com (ignoring)\n";
738 #endif
739  return true;
740  }
741 
742 #ifdef DEBUG_INTERNAL
743  cerr << "freeComid: communication id: "<<id<<endl;
744 #endif
745 
746  info_list_map_t::iterator it = _info_list_map.find(id);
747  this->internalFreeComId(it);
748  _info_list_map.erase(it);
749 
750  return true;
751 }
752 
753 void
755 {
757  for(unsigned i=0;i<_dTopo.total;i++)
758  _infolists[i]=new info_list_t();
759 }
760 
761 void
763 {
764 #ifdef DEBUG_INTERNAL
765  std::cerr << "-- reset info list\n";
766 #endif
767  // for each destNode
768  for(unsigned i=0; i< _dTopo.total; i++) {
769  // for each element of the list
770  info_list_t *ilp = _infolists[i];
771  for(info_list_t::const_iterator ci=ilp->begin(); ci!=ilp->end(); ++ci)
772  (*ci)->sent_size = 0;
773  }
774 }
775 
776 void
778 {
779 #ifdef DEBUG_INTERNAL
780  std::cerr << "-- clear info list\n";
781 #endif
782  // for each destNode
783  for(unsigned i=0; i< _dTopo.total; i++) {
784  // for each element of the list
785  info_list_t *ilp = _infolists[i];
786  for(info_list_t::const_iterator ci=ilp->begin(); ci!=ilp->end(); ++ci)
787  delete (*ci);
788  _infolists[i] -> clear();
789  }
790 }
unsigned long _serverToReceived
Definition: BasicBC.h:83
PaCO::PacoTopology_t _dTopo
Definition: BasicBC.h:45
virtual long getNodeRank()
Definition: BasicBC.cc:207
unsigned _lstart
Definition: BasicBC.h:53
info_list_map_t _info_list_map
Definition: BasicBC.h:72
static unsigned TotalNumberOfElementProc(const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz)
Definition: BasicBC.cc:82
#define ELEMENT_SIZE
Definition: BasicBC.cc:6
long _cur_id
Definition: BasicBC.h:74
#define DEBUG_INTERNAL2
Definition: Controlled.cc:13
virtual void setDescr(void *descr)
Definition: BasicBC.cc:626
unsigned _glen
Definition: BasicBC.h:50
void setTotalNbElt(unsigned long elt_nb)
Definition: BasicBC.cc:254
virtual PaCO::PacoTopology_t getSourceTopology()
Definition: BasicBC.cc:157
unsigned long blocsize
Definition: BasicBC.h:28
static unsigned OwnerBloc(const unsigned bid, const unsigned nbprocs)
Definition: BasicBC.cc:16
virtual void clientFree()
Definition: BasicBC.cc:558
static unsigned blocSize(const unsigned glen, const unsigned nbprocs, const BasicBC_param_t &param)
Definition: BasicBC.cc:98
info_list_t ** _infolists
Definition: BasicBC.h:75
unsigned long unitsize
Definition: BasicBC.h:27
#define DISTRIBUTION_TYPE
Definition: BasicBC.cc:8
unsigned _nodeRank
Definition: BasicBC.h:48
static void computeBlocBounds(unsigned long *low, unsigned long *high, const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz, const unsigned pos)
Definition: BasicBC.cc:69
BasicBC_param_t _param
Definition: BasicBC.h:47
static unsigned NumberOfBlocProc(const unsigned glen, const unsigned nbprocs, const unsigned bsz, const unsigned rank)
Definition: BasicBC.cc:35
char * _clientBuffer
Definition: BasicBC.h:78
unsigned msg_size
Definition: BasicBC.h:66
void allocate_new_info_list()
Definition: BasicBC.cc:754
static unsigned BlocNumberOfElementProc(const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz, const unsigned pos)
Definition: BasicBC.cc:45
virtual void setNodeRank(long Rank)
Definition: BasicBC.cc:198
#define TOTAL_SIZE
Definition: BasicBC.cc:7
bool _descr_to_be_cleaned
Definition: BasicBC.h:77
virtual bool setComId(long id)
Definition: BasicBC.cc:691
virtual void serverFree()
Definition: BasicBC.cc:656
virtual ~BasicBC()
Definition: BasicBC.cc:139
virtual void * getDescr()
Definition: BasicBC.cc:572
static unsigned getProcRangeInf(unsigned low, unsigned bsz)
Definition: BasicBC.cc:23
BasicBC_distri_type_t type
Definition: BasicBC.h:26
void setBlocSize(unsigned long bsz)
Definition: BasicBC.cc:213
void setEltSize(unsigned long size)
Definition: BasicBC.cc:244
virtual void * getServerData(long &length)
Definition: BasicBC.cc:616
unsigned long total
Definition: PaCO++.idl:35
void internalFreeComId(info_list_map_t::iterator &it)
Definition: BasicBC.cc:702
#define DST_TOPOLOGY
Definition: BasicBC.cc:5
unsigned lstart
Definition: BasicBC.h:65
static unsigned computeBlocBoundInf(const unsigned bsz, const unsigned rank, const unsigned nbprocs, const unsigned pos)
Definition: BasicBC.cc:60
unsigned _llen
Definition: BasicBC.h:51
virtual PieceToSend * computePiecesToSend(unsigned &size)
Definition: BasicBC.cc:265
unsigned _config
Definition: BasicBC.h:42
BasicBCLib::BasicBCDescr _clientDescr
Definition: BasicBC.h:79
PaCO::PacoTopology_t _sTopo
Definition: BasicBC.h:44
unsigned _dbsz
Definition: BasicBC.h:55
list< info_t * > info_list_t
Definition: BasicBC.h:69
virtual void setSourceTopology(PaCO::PacoTopology_t topo)
Definition: BasicBC.cc:147
BasicBC()
Definition: BasicBC.cc:117
BasicBCLib::BasicBCDescr * _serverDescr
Definition: BasicBC.h:87
virtual bool freeComId(long id)
Definition: BasicBC.cc:726
virtual PaCO::PacoTopology_t getDestTopology()
Definition: BasicBC.cc:190
virtual void setDataPtr(void *dataPtr)
Definition: BasicBC.cc:460
virtual void setDestTopology(PaCO::PacoTopology_t topo)
Definition: BasicBC.cc:165
virtual void * getClientData(void *pid, int server_node, long &size, long &length, bool &end)
Definition: BasicBC.cc:469
static unsigned getProcRangeSup(unsigned high, unsigned bsz)
Definition: BasicBC.cc:28
char * _serverBuffer
Definition: BasicBC.h:85
void internalSetComId(long id)
Definition: BasicBC.cc:666
void clear_info_list()
Definition: BasicBC.cc:777
#define SRC_TOPOLOGY
Definition: BasicBC.cc:4
unsigned _sbsz
Definition: BasicBC.h:54
unsigned _descr_ids_counter
Definition: BasicBC.h:84
unsigned gstart
Definition: BasicBC.h:64
void reset_info_list()
Definition: BasicBC.cc:762
virtual bool insertData(void *rcptBuf, unsigned long element_nb)
Definition: BasicBC.cc:586
unsigned sent_size
Definition: BasicBC.h:67