- Main Page
- Namespaces
- Classes
- Files

- Search for |

# schema.cpp

    00001 // "schema.cpp"
    00002
    00003 // (c) OPAC Team, LIFL, August 2005
    00004
    00005 /*
    00006    Contact: paradiseo-help@lists.gforge.inria.fr
    00007 */
    00008
    00009 #include <iostream>
    00010 #include <assert.h>
    00011
    00012 #include "schema.h"
    00013 #include "xml_parser.h"
    00014 #include "comm.h"
    00015 #include "node.h"
    00016 #include "../../core/peo_debug.h"
    00017
    00018 std :: vector <Node> the_schema;
    00019
    00020 Node * my_node;
    00021
    00022 RANK_ID getRankOfRunner (RUNNER_ID __key) {
    00023
    00024   for (unsigned i = 0; i < the_schema.size (); i ++)
    00025     for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
    00026       if (the_schema [i].id_run [j] == __key)
    00027         return the_schema [i].rk;
    00028   assert (false);
    00029   return 0;
    00030 }
    00031
    00032 static void loadNode (int __rk_sched) {
    00033
    00034   Node node;
    00035
    00036   node.rk_sched = __rk_sched;
    00037
    00038   /* ATT: name*/
    00039   node.rk = getRankFromName (getAttributeValue ("name"));
    00040   /* ATT: num_workers */
    00041   node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
    00042
    00043   while (true) {
    00044
    00045     /* TAG: <runner> | </node> */
    00046     std :: string name = getNextNode ();
    00047     assert (name == "runner" || name == "node");
    00048     if (name == "runner") {
    00049       /* TAG: </node> */
    00050       node.id_run.push_back (atoi (getNextNode ().c_str ()));
    00051       /* TAG: </runner> */
    00052       assert (getNextNode () == "runner");
    00053     }
    00054     else {
    00055       /* TAG: </node> */
    00056       the_schema.push_back (node);
    00057       break;
    00058     }
    00059   }
    00060 }
    00061
    00062 static void loadGroup () {
    00063
    00064   std :: string name;
    00065
    00066   /* ATT: scheduler*/
    00067   int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
    00068
    00069   while (true) {
    00070
    00071     /* TAG: <node> | </group> */
    00072     name = getNextNode ();
    00073     assert (name == "node" || name == "group");
    00074     if (name == "node")
    00075       /* TAG: <node> */
    00076       loadNode (rk_sched);
    00077     else
    00078       /* TAG: </group> */
    00079       break;
    00080   }
    00081 }
    00082
    00083 bool isScheduleNode () {
    00084
    00085   return my_node -> rk == my_node -> rk_sched;
    00086 }
    00087
    00088 void loadSchema (const char * __filename) {
    00089
    00090   openXMLDocument (__filename);
    00091
    00092   std :: string name;
    00093
    00094   /* TAG: <schema> */
    00095   name = getNextNode ();
    00096   assert (name == "schema");
    00097
    00098   while (true) {
    00099
    00100     /* TAG: <group> | </schema> */
    00101     name = getNextNode ();
    00102     assert (name == "group" || name == "schema");
    00103     if (name == "group")
    00104       /* TAG: <group> */
    00105       loadGroup ();
    00106     else
    00107       /* TAG: </schema> */
    00108       break;
    00109   }
    00110
    00111   /* Looking for my node */
    00112   for (unsigned i = 0; i < the_schema.size (); i ++)
    00113     if (the_schema [i].rk == getNodeRank ())
    00114       my_node = & (the_schema [i]);
    00115
    00116   /* About me */
    00117   char mess [1000];
    00118
    00119   sprintf (mess, "my rank is %d", my_node -> rk);
    00120   printDebugMessage (mess);
    00121   if (isScheduleNode ())
    00122     printDebugMessage ("I'am a scheduler");
    00123   for (unsigned i = 0; i < my_node -> id_run.size (); i ++) {
    00124     sprintf (mess, "I manage the runner %d", my_node -> id_run [i]);
    00125     printDebugMessage (mess);
    00126   }
    00127   if (my_node -> num_workers) {
    00128
    00129     sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
    00130     printDebugMessage (mess);
    00131   }
    00132
    00133   closeXMLDocument ();
    00134 }
    00135