- Main Page
- Namespaces
- Classes
- Files

- Search for |

# schema.cpp

    00001 /*
    00002 * <schema.cpp>
    00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
    00004 * (C) OPAC Team, LIFL, 2002-2007
    00005 *
    00006 * Sebastien Cahon, Alexandru-Adrian Tantar
    00007 *
    00008 * This software is governed by the CeCILL license under French law and
    00009 * abiding by the rules of distribution of free software.  You can  use,
    00010 * modify and/ or redistribute the software under the terms of the CeCILL
    00011 * license as circulated by CEA, CNRS and INRIA at the following URL
    00012 * "http://www.cecill.info".
    00013 *
    00014 * As a counterpart to the access to the source code and  rights to copy,
    00015 * modify and redistribute granted by the license, users are provided only
    00016 * with a limited warranty  and the software's author,  the holder of the
    00017 * economic rights,  and the successive licensors  have only  limited liability.
    00018 *
    00019 * In this respect, the user's attention is drawn to the risks associated
    00020 * with loading,  using,  modifying and/or developing or reproducing the
    00021 * software by the user in light of its specific status of free software,
    00022 * that may mean  that it is complicated to manipulate,  and  that  also
    00023 * therefore means  that it is reserved for developers  and  experienced
    00024 * professionals having in-depth computer knowledge. Users are therefore
    00025 * encouraged to load and test the software's suitability as regards their
    00026 * requirements in conditions enabling the security of their systems and/or
    00027 * data to be ensured and,  more generally, to use and operate it in the
    00028 * same conditions as regards security.
    00029 * The fact that you are presently reading this means that you have had
    00030 * knowledge of the CeCILL license and that you accept its terms.
    00031 *
    00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
    00033 * Contact: paradiseo-help@lists.gforge.inria.fr
    00034 *
    00035 */
    00036
    00037 #include <iostream>
    00038 #include <assert.h>
    00039
    00040 #include "schema.h"
    00041 #include "xml_parser.h"
    00042 #include "comm.h"
    00043 #include "node.h"
    00044 #include "../../core/peo_debug.h"
    00045
    00046 std :: vector <Node> the_schema;
    00047
    00048 Node * my_node;
    00049
    00050 RANK_ID getRankOfRunner (RUNNER_ID __key) {
    00051
    00052   for (unsigned i = 0; i < the_schema.size (); i ++)
    00053     for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
    00054       if (the_schema [i].id_run [j] == __key)
    00055         return the_schema [i].rk;
    00056   assert (false);
    00057   return 0;
    00058 }
    00059
    00060 static void loadNode (int __rk_sched) {
    00061
    00062   Node node;
    00063
    00064   node.rk_sched = __rk_sched;
    00065
    00066   /* ATT: name*/
    00067   node.rk = getRankFromName (getAttributeValue ("name"));
    00068   /* ATT: num_workers */
    00069   node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
    00070
    00071   while (true) {
    00072
    00073     /* TAG: <runner> | </node> */
    00074     std :: string name = getNextNode ();
    00075     assert (name == "runner" || name == "node");
    00076     if (name == "runner") {
    00077       /* TAG: </node> */
    00078       node.id_run.push_back (atoi (getNextNode ().c_str ()));
    00079       /* TAG: </runner> */
    00080       assert (getNextNode () == "runner");
    00081     }
    00082     else {
    00083       /* TAG: </node> */
    00084       the_schema.push_back (node);
    00085       break;
    00086     }
    00087   }
    00088 }
    00089
    00090 static void loadGroup () {
    00091
    00092   std :: string name;
    00093
    00094   /* ATT: scheduler*/
    00095   int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
    00096
    00097   while (true) {
    00098
    00099     /* TAG: <node> | </group> */
    00100     name = getNextNode ();
    00101     assert (name == "node" || name == "group");
    00102     if (name == "node")
    00103       /* TAG: <node> */
    00104       loadNode (rk_sched);
    00105     else
    00106       /* TAG: </group> */
    00107       break;
    00108   }
    00109 }
    00110
    00111 bool isScheduleNode () {
    00112
    00113   return my_node -> rk == my_node -> rk_sched;
    00114 }
    00115
    00116 void loadSchema (const char * __filename) {
    00117
    00118   openXMLDocument (__filename);
    00119
    00120   std :: string name;
    00121
    00122   /* TAG: <schema> */
    00123   name = getNextNode ();
    00124   assert (name == "schema");
    00125
    00126   while (true) {
    00127
    00128     /* TAG: <group> | </schema> */
    00129     name = getNextNode ();
    00130     assert (name == "group" || name == "schema");
    00131     if (name == "group")
    00132       /* TAG: <group> */
    00133       loadGroup ();
    00134     else
    00135       /* TAG: </schema> */
    00136       break;
    00137   }
    00138
    00139   /* Looking for my node */
    00140   for (unsigned i = 0; i < the_schema.size (); i ++)
    00141     if (the_schema [i].rk == getNodeRank ())
    00142       my_node = & (the_schema [i]);
    00143
    00144   /* About me */
    00145   char mess [1000];
    00146
    00147   sprintf (mess, "my rank is %d", my_node -> rk);
    00148   printDebugMessage (mess);
    00149   if (isScheduleNode ())
    00150     printDebugMessage ("I'am a scheduler");
    00151   for (unsigned i = 0; i < my_node -> id_run.size (); i ++) {
    00152     sprintf (mess, "I manage the runner %d", my_node -> id_run [i]);
    00153     printDebugMessage (mess);
    00154   }
    00155   if (my_node -> num_workers) {
    00156
    00157     sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
    00158     printDebugMessage (mess);
    00159   }
    00160
    00161   closeXMLDocument ();
    00162 }
    00163