visual.cc

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename: Visual.cc
00005  *
00006  *    Description:
00007  *
00008  *        Version:  1.0
00009  *        Created:  06/28/2010 3:31:47 PM
00010  *       Revision:  none
00011  *       Compiler:  gcc
00012  *
00013  *         Author:  Sharda Murthi, smurthi3@gatech.edu
00014  *        Company:  Georgia Institute of Technology
00015  *
00016  * =====================================================================================
00017  */
00018 
00019 #ifndef  _visual_cc_INC
00020 #define  _visual_cc_INC
00021 //#define DEBUG 0
00022 
00023 #include "visual.h"
00024 
00025 Visual::Visual()
00026 {
00027         topo_ptr = NULL;
00028         nodes = 0;
00029         links = 0;
00030 }
00031 
00032 Visual::Visual(Topology* topo, int n, int l, int g): topo_ptr(topo), nodes(n), links(l), grid_size(g)
00033 {
00034         link_ptr = new link_connection *[links]; // declaring an array of pointers
00035         for (uint l = 0; l < links; l++)
00036                 link_ptr[l] = new link_connection;
00037 
00038 #ifdef DEBUG
00039         std::cout << "In Parameterized Visual ctor\n";
00040         cout << "Nodes = " << nodes << "\t" << "Links = " << links << "\n";
00041 #endif
00042 }
00043 
00044 Visual::~Visual()
00045 {
00046         for ( uint l = 0; l < links; l++)
00047                 delete[] link_ptr[l];
00048 #ifdef DEBUG
00049         std::cout << "In Visual dtor\n";
00050 #endif
00051 }
00052 
00053 void Visual::create_new_connections() /* Function to get links as {link_id, <source, destination>} format */
00054 {
00055         map<uint , uint >::iterator it1;
00056         map<uint , uint >::iterator it2;
00057 
00058         it1 = topo_ptr->east_links.begin();
00059         uint k = 0;
00060 
00061         /* For East and West connections */
00062         for ( ; it1 != topo_ptr->east_links.end(); it1++ )
00063         {
00064 #ifdef DEBUG
00065                 cout << "in for loop east-west " << (*it1).second << " \n";
00066 #endif
00067                 it2 = topo_ptr->west_links.begin();
00068                 for (; it2 != topo_ptr->west_links.end(); it2++ ) // we got a match
00069                 {
00070                         if ( (*it1).second == (*it2).second )
00071                         {
00072 #ifdef DEBUG
00073                                 cout << "source = " << (*it2).first << "\n";
00074                                 cout << "destination = " << (*it1).first << "\n";
00075 #endif
00076                                 link_ptr[k]->link_id = (*it1).second;
00077                                 link_ptr[k]->source = (*it2).first;
00078                                 link_ptr[k]->destination = (*it1).first;
00079 
00080                                 new_east_links.push_back(link_ptr[k]);
00081                                 k++;
00082 
00083 #ifdef DEBUG
00084                                 cout << "source = " << (*it1).first << "\n";
00085                                 cout << "destination = " << (*it2).first << "\n";
00086 #endif
00087                                 link_ptr[k]->link_id = (*it1).second + 5000;
00088                                 link_ptr[k]->source = (*it1).first;
00089                                 link_ptr[k]->destination = (*it2).first;
00090 
00091                                 new_west_links.push_back(link_ptr[k]);
00092                                 k++;
00093                         }
00094                 }
00095         }
00096 
00097         /* For North and South connections */
00098 
00099         it1 = topo_ptr->north_links.begin();
00100 
00101         for ( ; it1 != topo_ptr->north_links.end(); it1++ )
00102         {
00103 #ifdef DEBUG
00104                 cout << "in for loop north-south " << (*it1).second << " \n";
00105 #endif
00106                 it2 = topo_ptr->south_links.begin();
00107                 for (; it2 != topo_ptr->south_links.end(); it2++ ) // we got a match
00108                 {
00109                         if ( (*it1).second == (*it2).second )
00110                         {
00111 #ifdef DEBUG
00112                                 cout << "source = " << (*it2).first << "\n";
00113                                 cout << "destination = " << (*it1).first << "\n";
00114 #endif
00115                                 link_ptr[k]->link_id = (*it1).second;
00116                                 link_ptr[k]->source = (*it2).first;
00117                                 link_ptr[k]->destination = (*it1).first;
00118 
00119                                 new_east_links.push_back(link_ptr[k]);
00120                                 k++;
00121 
00122 #ifdef DEBUG
00123                                 cout << "source = " << (*it1).first << "\n";
00124                                 cout << "destination = " << (*it2).first << "\n";
00125 #endif
00126                                 link_ptr[k]->link_id = (*it1).second + 5000;
00127                                 link_ptr[k]->source = (*it1).first;
00128                                 link_ptr[k]->destination = (*it2).first;
00129 
00130                                 new_west_links.push_back(link_ptr[k]);
00131                                 k++;
00132                         }
00133                 }
00134         }
00135 
00136 }
00137 
00138 void Visual::create_graphml()
00139 {
00140 #ifdef DEBUG
00141         std::cout << "Create graphml file function\n";
00142         cout << "cores and interfaces = " << concentration << "\t" << no_of_cores << "\n";
00143 #endif
00144         ofstream graphml_file;
00145         graphml_file.open("visualization/irisViewer/irisData/output.graphml");
00146 
00147     vector<uint>::iterator itr;
00148 
00149         graphml_file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << "\n";
00150         graphml_file << "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"" << "\n";
00151         graphml_file << "\t" << "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << "\n";
00152         graphml_file << "\t" << "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns" << "\n";
00153         graphml_file << "\t" << "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">" << "\n";
00154         graphml_file << "\t" << "<graph id=\"G\" edgedefault=\"directed\">" << "\n";
00155 
00156         graphml_file << "<!-- data schema -->\n";
00157         graphml_file << "<key id=\"name\" for=\"node\" attr.name=\"name\" attr.type=\"string\"/>" << "\n";
00158         graphml_file << "<key id=\"type\" for=\"node\" attr.name=\"type\" attr.type=\"string\"/>" << "\n";
00159         graphml_file << "<key id=\"name\" for=\"edge\" attr.name=\"name\" attr.type=\"string\"/>" << "\n";
00160 
00161         unsigned int i=0;
00162         static unsigned int j = 0; // edge count
00163         static unsigned int node_count = 0; // node count
00164         bool flag = false;
00165 
00166         for (; i < nodes; i++)
00167         {
00168                 flag = false;
00169                 graphml_file << "\t" << "<node id=\"n" << i << "\">" << "\n";
00170                 graphml_file << "\t \t" << "<data key=\"name\">" << i << "</data>\"" << "\n";
00171                 for (itr = mc_positions.begin(); itr!=mc_positions.end(); itr++)
00172             {
00173                         if ( i == *itr )
00174                         {
00175                                 graphml_file << "\t \t" << "<data key=\"type\">mc</data>\"" << "\n";
00176                                 flag = true;
00177                         }
00178             }
00179                 if (flag == false )
00180                         graphml_file << "\t \t" << "<data key=\"type\">router</data>\"" << "\n";
00181                 graphml_file << "\t" << "</node>" << "\n";
00182         }
00183 
00184         node_count = nodes;
00185 
00186         if ( grid_size == 2 )
00187         {
00188                 graphml_file << "\t" << "<edge source=\"n" << 0 << "\"" << " target=\"n" << 1 << "\">" << "\n";
00189                 graphml_file << "\t \t" << "<data key=\"name\">" << j << "</data>" << "\n";
00190                 graphml_file << "\t" << "</edge>" << "\n";
00191 
00192                 graphml_file << "\t" << "<edge source=\"n" << 1 << "\"" << " target=\"n" << 0 << "\">" << "\n";
00193                 graphml_file << "\t \t" << "<data key=\"name\">" << j++ << "</data>" << "\n";
00194                 graphml_file << "\t" << "</edge>" << "\n";
00195 
00196                 graphml_file << "\t" << "<edge source=\"n" << 2 << "\"" << " target=\"n" << 3 << "\">" << "\n";
00197                 graphml_file << "\t \t" << "<data key=\"name\">" << j << "</data>" << "\n";
00198                 graphml_file << "\t" << "</edge>" << "\n";
00199 
00200                 graphml_file << "\t" << "<edge source=\"n" << 3 << "\"" << " target=\"n" << 2 << "\">" << "\n";
00201                 graphml_file << "\t \t" << "<data key=\"name\">" << j++ << "</data>" << "\n";
00202                 graphml_file << "\t" << "</edge>" << "\n";
00203 
00204                 graphml_file << "\t" << "<edge source=\"n" << 0 << "\"" << " target=\"n" << 2 << "\">" << "\n";
00205                 graphml_file << "\t \t" << "<data key=\"name\">" << j << "</data>" << "\n";
00206                 graphml_file << "\t" << "</edge>" << "\n";
00207 
00208                 graphml_file << "\t" << "<edge source=\"n" << 2 << "\"" << " target=\"n" << 0 << "\">" << "\n";
00209                 graphml_file << "\t \t" << "<data key=\"name\">" << j++ << "</data>" << "\n";
00210                 graphml_file << "\t" << "</edge>" << "\n";
00211 
00212                 graphml_file << "\t" << "<edge source=\"n" << 1 << "\"" << " target=\"n" << 3 << "\">" << "\n";
00213                 graphml_file << "\t \t" << "<data key=\"name\">" << j << "</data>" << "\n";
00214                 graphml_file << "\t" << "</edge>" << "\n";
00215 
00216                 graphml_file << "\t" << "<edge source=\"n" << 3 << "\"" << " target=\"n" << 1 << "\">" << "\n";
00217                 graphml_file << "\t \t" << "<data key=\"name\">" << j++ << "</data>" << "\n";
00218                 graphml_file << "\t" << "</edge>" << "\n";
00219         }
00220         else
00221         {
00222                 vector<link_connection *>::iterator it;
00223 
00224                 graphml_file << "<!-- east links -->\n";
00225                 for ( it = new_east_links.begin(); it != new_east_links.end(); it++ )
00226                 {
00227                         graphml_file << "\t" << "<edge source=\"n" << (*it)->source << "\"" << " target=\"n" << (*it)->destination << "\">" << "\n";
00228                         graphml_file << "\t \t" << "<data key=\"name\">" << (*it)->link_id << "</data>" << "\n";
00229                         graphml_file << "\t" << "</edge>" << "\n";
00230                 }
00231 
00232                 graphml_file << "<!-- west links -->\n";
00233                 for ( it = new_west_links.begin(); it != new_west_links.end(); it++ )
00234                 {
00235                         graphml_file << "\t" << "<edge source=\"n" << (*it)->source << "\"" << " target=\"n" << (*it)->destination << "\">" << "\n";
00236                         graphml_file << "\t \t" << "<data key=\"name\">" << (*it)->link_id << "</data>" << "\n";
00237                         graphml_file << "\t" << "</edge>" << "\n";
00238                 }
00239 
00240                 graphml_file << "<!-- south links -->\n";
00241                 for ( it = new_south_links.begin(); it != new_south_links.end(); it++ )
00242                 {
00243                         graphml_file << "\t" << "<edge source=\"n" << (*it)->source << "\"" << " target=\"n" << (*it)->destination << "\">" << "\n";
00244                         graphml_file << "\t \t" << "<data key=\"name\">" << (*it)->link_id << "</data>" << "\n";
00245                         graphml_file << "\t" << "</edge>" << "\n";
00246                 }
00247 
00248                 graphml_file << "<!-- north links -->\n";
00249                 for ( it = new_north_links.begin(); it != new_north_links.end(); it++ )
00250                 {
00251                         graphml_file << "\t" << "<edge source=\"n" << (*it)->source << "\"" << " target=\"n" << (*it)->destination << "\">" << "\n";
00252                         graphml_file << "\t \t" << "<data key=\"name\">" << (*it)->link_id << "</data>" << "\n";
00253                         graphml_file << "\t" << "</edge>" << "\n";
00254                 }
00255         }
00256 
00257         /* now generating the links per node - interfaces and processors */
00258         uint start_interface = node_count;
00259 
00260         graphml_file << "<!-- interface edges -->\n";
00261         for ( i = 0; i < nodes; i++ )
00262         {
00263                 for ( uint k = 0; k < concentration ; k++ ) // generate all the interfaces
00264                 {
00265                         /* generate the interface node */
00266                         graphml_file << "\t" << "<node id=\"n" << node_count << "\">" << "\n";
00267                         graphml_file << "\t \t" << "<data key=\"name\">" << node_count << "</data>\"" << "\n";
00268                         graphml_file << "\t \t" << "<data key=\"type\">interface</data>\"" << "\n";
00269                         graphml_file << "\t" << "</node>" << "\n";
00270 
00271                         /* generate the interface edge */
00272                         graphml_file << "\t" << "<edge source=\"n" << i << "\"" << " target=\"n" << node_count << "\">" << "\n";
00273                         graphml_file << "\t \t" << "<data key=\"name\">" << j++ << "</data>" << "\n";
00274                         graphml_file << "\t" << "</edge>" << "\n";
00275 
00276                         graphml_file << "\t" << "<edge source=\"n" << node_count++ << "\"" << " target=\"n" << i << "\">" << "\n";
00277                         graphml_file << "\t \t" << "<data key=\"name\">" << j++ << "</data>" << "\n";
00278                         graphml_file << "\t" << "</edge>" << "\n";
00279                 }
00280         }
00281 
00282         uint end_interface = node_count;
00283 
00284         /* generating processors */
00285         graphml_file << "<!-- processor edges -->\n";
00286         for ( i = start_interface ; i < end_interface ; i++)
00287         {
00288                 for ( uint k = 0; k < no_of_cores ; k++ ) // generate all the interfaces
00289                 {
00290                         /* generate the processor node */
00291                         graphml_file << "\t" << "<node id=\"n" << node_count << "\">" << "\n";
00292                         graphml_file << "\t \t" << "<data key=\"name\">" << node_count << "</data>\"" << "\n";
00293                         graphml_file << "\t \t" << "<data key=\"type\">core</data>\"" << "\n";
00294                         graphml_file << "\t" << "</node>" << "\n";
00295 
00296                         /* generate the processor edge */
00297                         graphml_file << "\t" << "<edge source=\"n" << i << "\"" << " target=\"n" << node_count++ << "\">" << "\n";
00298                         graphml_file << "\t \t" << "<data key=\"name\">" << j++ << "</data>" << "\n";
00299                         graphml_file << "\t" << "</edge>" << "\n";
00300                 }
00301         }
00302 
00303         graphml_file << "\t" << "</graph>" << "\n";
00304         graphml_file << "</graphml>" << "\n";
00305         graphml_file.close();
00306 
00307         new_east_links.clear();
00308         new_west_links.clear();
00309         new_north_links.clear();
00310         new_south_links.clear();
00311 }
00312 
00313 
00314 #endif
00315 

Generated on Tue Oct 19 17:22:01 2010 for IRIS by  doxygen 1.5.8