PaCO++  0.05
paco_libgraph_comScheduling.cc
Go to the documentation of this file.
00001 #include "paco_libgraph_comScheduling.h"
00002 
00003 #undef INFO_INTERNAL
00004 
00005 paco_comScheduling_libgraph::paco_comScheduling_libgraph()
00006 {
00007   _beta=0;
00008   _k=0;
00009   _g = NULL;
00010   _client_nodes = NULL;
00011   _server_nodes = NULL;
00012 }
00013 
00014 
00015 paco_comScheduling_libgraph::~paco_comScheduling_libgraph()
00016 {
00017   if (_g) delete _g;
00018   if (_client_nodes) delete[] _client_nodes;
00019   if (_server_nodes) delete[] _server_nodes;
00020 }
00021 
00022 
00023 void 
00024 paco_comScheduling_libgraph::set_beta(unsigned int beta)
00025 {
00026   if (_beta == beta) return;
00027 
00028   _beta = beta;
00029   // beta change -> clear all schedule memory
00030   clearAllSchedules();
00031 }
00032 
00033 void 
00034 paco_comScheduling_libgraph::set_k(unsigned int k)
00035 {
00036   if (_k == k) return;
00037 
00038   _k = k;
00039   // k change -> clear all schedule memory
00040   clearAllSchedules();
00041 }
00042 
00043 unsigned int
00044 paco_comScheduling_libgraph::get_beta()
00045 {
00046   return _beta;
00047 }
00048 
00049 unsigned int
00050 paco_comScheduling_libgraph::get_k()
00051 {
00052   return _k;
00053 }
00054 
00055 void 
00056 paco_comScheduling_libgraph::initializeBigraph(PaCO::PacoTopology_t* srctopo, PaCO::PacoTopology_t* dsttopo)
00057 {
00058 #ifdef INFO_INTERNAL
00059   std::cerr<<__FUNCTION__<<" with beta:"<<_libgraph_beta<<" k:"<<_libgraph_k<<endl;
00060 #endif
00061 
00062   // Removing old instances
00063   if (_g) delete _g;
00064   if (_client_nodes) delete[] _client_nodes;
00065   if (_server_nodes) delete[] _server_nodes;
00066 
00067   // Creating new instances
00068   _g = new bigraph();
00069 
00070   // Setting up the parametter of the graph
00071   if ((_beta==0)||(_k==0)) {
00072     std::cerr<< "ERROR: libgraph not initialized -- Specifiy k & beta !!"<<endl;
00073   }
00074     
00075   _g->set_beta(_beta);
00076   _g->set_k(_k);
00077 
00078   _client_nodes = new node*[srctopo->total];
00079   _server_nodes = new node*[dsttopo->total];
00080         
00081   for (unsigned i = 0; i < srctopo->total; i++)
00082     {
00083       _client_nodes[i] = _g->add_node(true);
00084     }
00085   for (unsigned i = 0; i < dsttopo->total; i++)
00086     {
00087       _server_nodes[i] = _g->add_node(false);
00088     }
00089 }
00090 
00091 paco_comSchedule* 
00092 paco_comScheduling_libgraph::computeScheduling(unsigned rank, 
00093                       PaCO::PacoTopology_t* srctopo, PaCO::PacoTopology_t* dsttopo,
00094                       unsigned **com_matrix, void** info_vector[])
00095 {
00096   // 1. setup a new bigraph
00097   initializeBigraph(srctopo, dsttopo);
00098 
00099   // 2. fill the bigraph
00100   for (unsigned i = 0; i < srctopo->total; i++)
00101     {
00102       if (i!= rank)
00103    for (unsigned j = 0; j < dsttopo->total; j++)
00104      {
00105        _g->add_edge(_client_nodes[i], _server_nodes[j], com_matrix[i][j]);
00106 #ifdef INFO_INTERNAL
00107        std::cerr << "edge: "<<_client_nodes[i] << " -> "<<_server_nodes[j] << " : "<< com_matrix[i][j]<<endl;
00108 #endif
00109      }
00110       else
00111    for (unsigned j = 0; j < dsttopo->total; j++)
00112      {
00113        _g->add_edge(_client_nodes[i],_server_nodes[j], com_matrix[i][j], info_vector[j]);
00114 #ifdef INFO_INTERNAL
00115        std::cerr << "edge: "<<_client_nodes[i] << " -> "<<_server_nodes[j] << " : "<< com_matrix[i][j]<<" ("<<info_vector[j]<<")\n";
00116 #endif
00117      }
00118     }
00119  
00120   _g->remove_empty_nodes();
00121   
00122   paco_comSchedule_libgraph* schedule_info = new paco_comSchedule_libgraph(new kbps_approximation(_g));
00123 
00124   schedule_info->get_kbps()->compute_poly2();
00125   schedule_info->get_kbps()->serialize();
00126   schedule_info->build_idx();
00127   
00128   return schedule_info;
00129 }