PaCO++  0.05
PaCO++_operation.cc
Go to the documentation of this file.
1 #include "PaCO++_operation.h"
2 #include "PaCO++_src.h"
3 
4 #include "com/paco_com.h"
5 #include "thread/paco_thread.h"
8 
9 #include <assert.h>
10 
11 #undef DEBUG_INTERNAL
12 
13 PaCO_operation::PaCO_operation(int _number_arguments)
14 {
15  // Default case : sequential client
16  _current_id = -1;
17  myRank = 0;
18  mytopo.total = 1;
20  typeClient = false;
21  termine = false;
22  termine2 = false;
23  client_id = -1;
24  number_arguments = _number_arguments;
27 #ifdef PACO_WARN_DISTLIB
30 #endif
31  for(int i=0; i<number_arguments; i++)
32  {
33  libraries_in[i] = NULL;
34  libraries_out[i] = NULL;
35 #ifdef PACO_WARN_DISTLIB
36  libraries_in_name[i]=NULL;
37  libraries_out_name[i]=NULL;
38 #endif
39  }
41  FabThread=0;
42  FabCom=0;
45  return_op = 0;
46 
47  // Exception handling
48  _exception = false;
49  _level = 0;
50 
51  // Timing
52 #ifdef PADICO
53  _ticks=(padico_timing_t*)malloc(sizeof(padico_timing_t)*10);
54 #endif
55 
56 }
57 
59 {
60 #ifdef PACO_WARN_DISTLIB
61  for(int i=0; i<number_arguments; i++)
62  {
63  if (libraries_in_name[i])
64  free(libraries_in_name[i]);
65  if (libraries_out_name[i])
66  free(libraries_out_name[i]);
67  }
68 #endif
69  delete libraries_in;
70  delete libraries_out;
71  delete my_mutex;
72  delete my_condition;
73  delete my_mutex2;
74  delete my_condition2;
75  delete my_mutex3;
76  // Memories must be deleted
77 }
78 
79 void
80 PaCO_operation::setClientId(CORBA::Short request_uid)
81 {
82  client_id = request_uid;
83 }
84 
85 void
87 {
88  myRank = op->myRank ;
89  mytopo = op->mytopo ;
91 
92  FabManager = op->FabManager;
93 
94  group = op->group;
95  my_com = op->my_com ;
96  FabCom = op->FabCom ;
97 
100 
101  // Client part
102  typeClient = op->typeClient ;
103  if (op->serveur_topo_aller.total > 0)
104  {
106  }
107  if (op->serveur_topo_retour.total > 0)
108  {
110  }
111 
112  // Server part
113  FabThread = op->FabThread ;
114  my_mutex = op->my_mutex ;
115  my_condition = op->my_condition ;
116  my_mutex2 = op->my_mutex2 ;
118  my_mutex3 = op->my_mutex3 ;
119 }
120 
121 void
123 {
124  myRank = op->myRank ;
125  mytopo = op->mytopo ;
126  number_stubs = op->number_stubs ;
127 
128  FabManager = op->FabManager;
129 
130  group = op->group ;
131  my_com = op->my_com ;
132  FabCom = op->FabCom ;
133 
136 
137  // Client part
138  typeClient = op->typeClient ;
139  if (op->serveur_topo_aller.total > 0)
140  {
142  }
143  // Server part
144  FabThread = op->FabThread ;
145  my_mutex = op->my_mutex ;
146  my_condition = op->my_condition ;
147  my_mutex2 = op->my_mutex2 ;
149  my_mutex3 = op->my_mutex3 ;
150 }
151 
152 void
154 {
158 
159  for(int i=0; i<number_arguments; i++)
160  {
161  if (libraries_in[i])
162  {
164  }
165  if (libraries_out[i])
166  {
168  }
169  }
170 }
171 
172 void
174 {
175  return_op = 1;
177  _mode = op->_mode;
180 
181  for(int i=0; i<number_arguments; i++)
182  {
183  if (libraries_in[i])
184  {
186  }
187  if (libraries_out[i])
188  {
190  }
191  }
192 }
193 
194 void
196 {
197  FabManager = fm;
198 }
199 
200 void
202 {
203  FabCom = fc;
204 }
205 
206 void
207 PaCO_operation::setLibCom(const string& LibCom, void * _group)
208 {
209  if (FabCom==0)
210  {
211  if (FabManager)
212  FabCom = FabManager->get_com(LibCom);
213  else
214  {
215  cerr << "Error: Unable to instantiate lib com "<<LibCom<<endl;
216  abort();
217  }
218  }
219 
220  group = _group;
222 
223  for(int i=0; i<number_arguments; i++)
224  {
225  if (libraries_in[i])
226  {
228  }
229  if (libraries_out[i])
230  {
232  }
233  }
234 }
235 
236 // void
237 // PaCO_operation::setMode(PaCO::distLoc_t mode, int param, const string& way) throw(BadWayString)
238 // {
239 // //_mode = mode;
240 // if (way == "inout")
241 // {
242 // libraries_in[param]->setMode(mode);
243 // libraries_out[param]->setMode(mode);
244 // }
245 // else if (way == "in")
246 // {
247 // libraries_in[param]->setMode(mode);
248 // }
249 // else if (way == "out")
250 // {
251 // libraries_out[param]->setMode(mode);
252 // }
253 // else
254 // {
255 // // Bad way string
256 // throw BadWayString(way);
257 // }
258 // }
259 
260 void
261 PaCO_operation::setDisLibArg(int arg_number, const string& lib_name, const string& way) throw(BadWayString)
262 {
263  if (way == "inout")
264  {
265  libraries_in [arg_number] = FabManager->get_distribution(lib_name)->create();
266  libraries_out[arg_number] = FabManager->get_distribution(lib_name)->create();
267 #ifdef PACO_WARN_DISTLIB
268  if (libraries_in_name[arg_number]) free(libraries_in_name[arg_number]);
269  if (libraries_out_name[arg_number]) free(libraries_out_name[arg_number]);
270  libraries_in_name [arg_number] = strdup(lib_name.c_str());
271  libraries_out_name [arg_number] = strdup(lib_name.c_str());
272 #endif
273  }
274  else if (way == "in")
275  {
276  libraries_in[arg_number] = FabManager->get_distribution(lib_name)->create();
277 #ifdef PACO_WARN_DISTLIB
278  if (libraries_in_name[arg_number]) free(libraries_in_name[arg_number]);
279  libraries_in_name [arg_number] = strdup(lib_name.c_str());
280 #endif
281  }
282  else if (way == "out")
283  {
284  libraries_out[arg_number] = FabManager->get_distribution(lib_name)->create();
285 #ifdef PACO_WARN_DISTLIB
286  if (libraries_out_name[arg_number]) free(libraries_out_name[arg_number]);
287  libraries_out_name [arg_number] = strdup(lib_name.c_str());
288 #endif
289  }
290  else
291  {
292  // Bad way string
293  throw BadWayString(way);
294  }
295 }
296 // void
297 // PaCO_operation::setTypeArg(int arg_number, Pattron * temp, const string& lib_name, const string& way) throw(BadWayString)
298 // {
299 // Fabrique * f = new Fabrique();
300 // f->enregistrer(temp);
301 // if (way == "inout")
302 // {
303 // libraries_in[arg_number] = FabDist->paco_create(lib_name,f);
304 // libraries_out[arg_number] = FabDist->paco_create(lib_name,f);
305 // }
306 // else if (way == "in")
307 // {
308 // libraries_in[arg_number] = FabDist->paco_create(lib_name,f);
309 // }
310 // else if (way == "out")
311 // {
312 // libraries_out[arg_number] = FabDist->paco_create(lib_name,f);
313 // }
314 // else
315 // {
316 // // Bad way string
317 // throw BadWayString(way);
318 // }
319 // }
320 
321 // void
322 // PaCO_operation::initArg(PaCO::PacoInitData_t data, int nb_param, const string& way) throw(BadWayString)
323 // {
324 // if (way == "in")
325 // {
326 // libraries_in[nb_param]->setGlobalDataConfiguration(data.gd);
327 // libraries_in[nb_param]->setLocalDataConfiguration (data.ld);
328 // }
329 // else if (way == "out")
330 // {
331 // libraries_out[nb_param]->setGlobalDataConfiguration(data.gd);
332 // libraries_out[nb_param]->setLocalDataConfiguration (data.ld);
333 // }
334 // else
335 // {
336 // // Bad way string
337 // throw BadWayString(way);
338 // }
339 // }
340 
341 void
342 PaCO_operation::init(int rank, int total)
343 {
344  myRank = rank;
345  mytopo.total = total;
346 }
347 
348 // int
349 // PaCO_operation::setDistribConfig(void * config, int number, const string& way) throw(BadWayString, BadWaySetStringDistribConfig)
350 // {
351 // if (way == "inout")
352 // {
353 // int ret_in = libraries_in[number]->setConfig(config);
354 // int ret_out = libraries_out[number]->setConfig(config);
355 // if (ret_in == ret_out)
356 // {
357 // return ret_in;
358 // }
359 // else
360 // {
361 // throw BadWaySetStringDistribConfig(way, ret_in, ret_out);
362 // }
363 // }
364 // else if (way == "in")
365 // {
366 // return libraries_in[number]->setConfig(config);
367 // }
368 // else if (way == "out")
369 // {
370 // return libraries_out[number]->setConfig(config);
371 // }
372 // else
373 // {
374 // // Bad way string
375 // throw BadWayString(way);
376 // }
377 // }
378 
379 // void *
380 // PaCO_operation::getDistribConfig(int number, const string& way) throw(BadWayString)
381 // {
382 // if (way == "in")
383 // {
384 // return libraries_in[number]->getConfig();
385 // }
386 // else if (way == "out")
387 // {
388 // return libraries_out[number]->getConfig();
389 // }
390 // else
391 // {
392 // // Bad way string
393 // throw BadWayString(way);
394 // }
395 // }
396 
397 void
399 {
400  typeClient = type;
401 }
402 
403 
404 void
405 PaCO_operation::setClientTopo(PaCO::PacoTopology_t _client_topo, const string& way) throw(BadWayString)
406 {
407  if (way == "in")
408  {
409  serveur_topo_retour = _client_topo;
410  }
411  else if (way == "out")
412  {
413  serveur_topo_aller = _client_topo;
414  }
415  else
416  {
417  // Bad way string
418  throw BadWayString(way);
419  }
420 }
421 
422 void
424 {
425  serveur_topo_retour = _client_topo;
426 }
427 
428 void
429 PaCO_operation::setServerTopo(PaCO::PacoTopology_t _serveur_topo, const string& way) throw(BadWayString)
430 {
431  if (way == "in")
432  {
433  serveur_topo_aller = _serveur_topo;
434  }
435  else if (way == "out")
436  {
437  serveur_topo_retour = _serveur_topo;
438  }
439  else
440  {
441  // Bad way string
442  throw BadWayString(way);
443  }
444 }
445 
446 void
448  {
449  // DO NOT FORGET TO CLEAR MEMORIES (WHAT ABOUT COMMUNICATION MATRICES??) !!!!
451 
452  if (return_op == 0)
453  {
454  for (int i = 0; i < number_arguments; i++)
455  {
456  if (libraries_in[i] != NULL)
457  {
461  }
462  if (libraries_out[i] != NULL)
463  {
467  }
468  }
469  }
470  }
471 
472 void
474 {
475  FabThread = ft;
476 }
477 
478 void
479 PaCO_operation::setLibThread(const string& LibThread)
480 {
481  if (FabThread==0)
482  {
483  if (FabManager)
484  FabThread = FabManager->get_thread(LibThread);
485  else
486  {
487  cerr << "Error: Unable to instantiate lib thread "<<LibThread<<endl;
488  abort();
489  }
490 
491  }
492 
498 }
499 
500 void
502 {
503  FabComScheduling = fcs;
504 }
505 
506 void
507 PaCO_operation::setLibComScheduling(const string& LibComScheduling)
508 {
509  if (FabComScheduling==0)
510  {
511  if (FabManager)
512  FabComScheduling = FabManager->get_comScheduling(LibComScheduling);
513  else
514  {
515  cerr << "Error: Unable to instantiate lib communication schedule "<<LibComScheduling<<endl;
516  abort();
517  }
518 
519  }
520 
521  if (my_comScheduling)
522  delete my_comScheduling;
524 }
525 
528 {
529  // lookup existing communication info
530  _com_info_map_t::iterator it2 = _com_info_map.find(id);
531  if (it2 != _com_info_map.end())
532  {
533 #ifdef DEBUG_INTERNAL
534  std::cerr <<"[INFO] found communication info for Id "<<id<<endl;
535 #endif
536  return _com_info_map[id];
537  }
538  else
539  {
540  return NULL;
541  }
542 }
543 
544 void
546 {
547  _current_id = -1; // _DO_NOT_USE_COMMUNICATION_MEMORY;
548 
549 #ifdef DEBUG_INTERNAL
550  std::cerr <<"[INFO] not using memory"<<endl;
551 #endif
552 
553 }
554 
555 void
557 {
558  if (id<0)
559  throw new InvalidArgument("useCommunicationMemeoryId expect an id >0");
560 
561 #ifdef DEBUG_INTERNAL
562  std::cerr <<"[INFO] using memory Id "<<id<<endl;
563 #endif
564 
565  // set current id
566  _current_id = id;
567 
568  // Beta patch
569  for(int i=0; i<number_arguments; i++)
570  {
571  if (libraries_in[i])
572  {
573  bool res=libraries_in[i]->setComId(id);
574  if (!res) {
575 #ifdef PACO_WARN_DISTLIB
576  std::cerr << "warning: argument #"<<i<<" with dist lib "<<libraries_in_name[i]<<" does not support comm cache\n";
577 #else
578  std::cerr << "warning: argument #"<<i<<" does not support comm cache\n";
579 #endif
580  }
581  }
582  }
583 }
584 
585 void
587 {
588  if (id<0)
589  throw new InvalidArgument("clearCommunicationMemeoryId expects an id >0");
590 
591 #ifdef DEBUG_INTERNAL
592  std::cerr <<"[INFO] clearing communication memory Id "<<id<<endl;
593 #endif
594 
595  _com_info_map_t::iterator it2 = _com_info_map.find(id);
596  if (it2 != _com_info_map.end())
597  {
598  delete _com_info_map[id];
599  _com_info_map.erase(it2);
600  }
601 
602  assert(my_comScheduling!=0);
604 }
605 
606 void
608 {
609  assert(my_comScheduling!=0);
611 }
612 
613 void
615 {
616  if (my_comScheduling)
618 }
virtual void setFabManager(paco_fabrique_manager *fm)
_com_info_map_t _com_info_map
virtual void setLibComScheduling(const string &LibComScheduling)
virtual void noCommunicationMemory()
virtual void setDestTopology(PaCO::PacoTopology_t topo)=0
virtual void setCommunicator(void *group)=0
paco_fabrique_comScheduling * get_comScheduling(const ::std::string &fabname)
virtual void setDisLibArg(int arg_number, const string &lib_name, const string &way)
virtual paco_comScheduling * create_comScheduling()=0
virtual void setTypeClient(bool type)
virtual void init_context(PaCO_operation *op)
virtual void clearAllSchedules()
virtual void setLibThread(const string &LibThread)
DistributionLibrary ** libraries_out
virtual void configureTopo()
PaCO::PacoTopology_t serveur_topo_retour
DistributionLibrary ** libraries_in
paco_mutex * my_mutex
virtual void clearScheduleId(long id)
virtual void clearScheduleMemoryId(long id)
virtual void init_context_proxy(PaCO_operation *op)
paco_mutex * my_mutex2
virtual bool setComId(long id)
virtual paco_mutex * paco_create_mutex()=0
virtual paco_condition * paco_create_condition(paco_mutex *mutex)=0
PaCO_operation(int _number_arguments)
PaCO::PacoTopology_t serveur_topo_aller
paco_fabrique_distribution * get_distribution(const ::std::string &fabname)
paco_fabrique_thread * FabThread
void clearAllScheduleMemory()
virtual ~PaCO_operation()
paco_fabrique_com * FabCom
paco_fabrique_comScheduling * FabComScheduling
paco_mutex * my_mutex3
virtual void init(int rank, int total)
virtual void init_return_context(PaCO_operation *op)
virtual DistributionLibrary * create()=0
unsigned long total
Definition: PaCO++.idl:35
CORBA::Short client_id
virtual void setComFab(paco_fabrique_com *fc)
virtual void setNodeRank(long Rank)=0
PaCO::PacoTopology_t mytopo
virtual void setLibCom(const string &LibCom, void *_group)
paco_comScheduling * my_comScheduling
std::vector< char * > libraries_in_name
std::vector< char * > libraries_out_name
virtual paco_com * paco_create(void *group)=0
virtual void init_context_args(PaCO_operation *op)
paco_fabrique_manager * paco_getFabriqueManager()
Definition: PaCO++_src.cc:28
virtual void setThreadFab(paco_fabrique_thread *ft)
_com_info_t * getComMemoryId(long id)
PaCO::distLoc_t _mode
virtual void setSourceTopology(PaCO::PacoTopology_t topo)=0
virtual void setServerTopo(PaCO::PacoTopology_t _serveur_topo, const string &way)
paco_condition * my_condition
paco_fabrique_manager * FabManager
paco_fabrique_thread * get_thread(const ::std::string &fabname)
virtual void setComSchedulingFab(paco_fabrique_comScheduling *ft)
virtual void setClientId(CORBA::Short request_uid)
paco_condition * my_condition2
virtual void useCommunicationMemoryId(long id)
virtual void setClientTopo(PaCO::PacoTopology_t _client_topo, const string &way)
paco_fabrique_com * get_com(const ::std::string &fabname)
virtual void clearCommunicationMemoryId(long id)