- Main Page
- Namespaces
- Classes
- Files

- Search for |

# schema.cpp

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 // "schema.cpp"
    00004
    00005 // (c) OPAC Team, LIFL, August 2005
    00006
    00007 /* This library is free software; you can redistribute it and/or
    00008    modify it under the terms of the GNU Lesser General Public
    00009    License as published by the Free Software Foundation; either
    00010    version 2 of the License, or (at your option) any later version.
    00011
    00012    This library is distributed in the hope that it will be useful,
    00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015    Lesser General Public License for more details.
    00016
    00017    You should have received a copy of the GNU Lesser General Public
    00018    License along with this library; if not, write to the Free Software
    00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    00020
    00021    Contact: paradiseo-help@lists.gforge.inria.fr
    00022 */
    00023
    00024 #include <iostream>
    00025 #include <assert.h>
    00026
    00027 #include "schema.h"
    00028 #include "xml_parser.h"
    00029 #include "comm.h"
    00030 #include "node.h"
    00031 #include "../../core/peo_debug.h"
    00032
    00033 std :: vector <Node> the_schema;
    00034
    00035 Node * my_node;
    00036
    00037 RANK_ID getRankOfRunner (RUNNER_ID __key) {
    00038
    00039   for (unsigned i = 0; i < the_schema.size (); i ++)
    00040     for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
    00041       if (the_schema [i].id_run [j] == __key)
    00042         return the_schema [i].rk;
    00043   assert (false);
    00044   return 0;
    00045 }
    00046
    00047 static void loadNode (int __rk_sched) {
    00048
    00049   Node node;
    00050
    00051   node.rk_sched = __rk_sched;
    00052
    00053   /* ATT: name*/
    00054   node.rk = getRankFromName (getAttributeValue ("name"));
    00055   /* ATT: num_workers */
    00056   node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
    00057
    00058   while (true) {
    00059
    00060     /* TAG: <runner> | </node> */
    00061     std :: string name = getNextNode ();
    00062     assert (name == "runner" || name == "node");
    00063     if (name == "runner") {
    00064       /* TAG: </node> */
    00065       node.id_run.push_back (atoi (getNextNode ().c_str ()));
    00066       /* TAG: </runner> */
    00067       assert (getNextNode () == "runner");
    00068     }
    00069     else {
    00070       /* TAG: </node> */
    00071       the_schema.push_back (node);
    00072       break;
    00073     }
    00074   }
    00075 }
    00076
    00077 static void loadGroup () {
    00078
    00079   std :: string name;
    00080
    00081   /* ATT: scheduler*/
    00082   int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
    00083
    00084   while (true) {
    00085
    00086     /* TAG: <node> | </group> */
    00087     name = getNextNode ();
    00088     assert (name == "node" || name == "group");
    00089     if (name == "node")
    00090       /* TAG: <node> */
    00091       loadNode (rk_sched);
    00092     else
    00093       /* TAG: </group> */
    00094       break;
    00095   }
    00096 }
    00097
    00098 bool isScheduleNode () {
    00099
    00100   return my_node -> rk == my_node -> rk_sched;
    00101 }
    00102
    00103 void loadSchema (const char * __filename) {
    00104
    00105   openXMLDocument (__filename);
    00106
    00107   std :: string name;
    00108
    00109   /* TAG: <schema> */
    00110   name = getNextNode ();
    00111   assert (name == "schema");
    00112
    00113   while (true) {
    00114
    00115     /* TAG: <group> | </schema> */
    00116     name = getNextNode ();
    00117     assert (name == "group" || name == "schema");
    00118     if (name == "group")
    00119       /* TAG: <group> */
    00120       loadGroup ();
    00121     else
    00122       /* TAG: </schema> */
    00123       break;
    00124   }
    00125
    00126   /* Looking for my node */
    00127   for (unsigned i = 0; i < the_schema.size (); i ++)
    00128     if (the_schema [i].rk == getNodeRank ())
    00129       my_node = & (the_schema [i]);
    00130
    00131   /* About me */
    00132   char mess [1000];
    00133
    00134   sprintf (mess, "my rank is %d", my_node -> rk);
    00135   printDebugMessage (mess);
    00136   if (isScheduleNode ())
    00137     printDebugMessage ("I'am a scheduler");
    00138   for (unsigned i = 0; i < my_node -> id_run.size (); i ++) {
    00139     sprintf (mess, "I manage the runner %d", my_node -> id_run [i]);
    00140     printDebugMessage (mess);
    00141   }
    00142   if (my_node -> num_workers) {
    00143
    00144     sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
    00145     printDebugMessage (mess);
    00146   }
    00147
    00148   closeXMLDocument ();
    00149 }
    00150