schema.cpp

00001 /*
00002 * <schema.cpp>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
00004 * (C) OPAC Team, LIFL, 2002-2008
00005 *
00006 * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
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 <set>
00038 #include <cassert>
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 
00047 std :: vector <Node> the_schema;
00048 
00049 Node * my_node;
00050 
00051 static unsigned maxSpecifiedRunnerID = 0;
00052 
00053 
00054 RANK_ID getRankOfRunner (RUNNER_ID __key)
00055 {
00056 
00057   for (unsigned i = 0; i < the_schema.size (); i ++)
00058     for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
00059       if (the_schema [i].id_run [j] == __key)
00060         return the_schema [i].rk;
00061   assert (false);
00062   return 0;
00063 }
00064 
00065 static void loadNode (int __rk_sched)
00066 {
00067 
00068   Node node;
00069 
00070   node.rk_sched = __rk_sched;
00071 
00072   /* ATT: name*/
00073   node.rk = getRankFromName (getAttributeValue ("name"));
00074   /* ATT: num_workers */
00075   node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
00076 
00077   while (true)
00078     {
00079 
00080       /* TAG: <runner> | </node> */
00081       std :: string name = getNextNode ();
00082       assert (name == "runner" || name == "node");
00083       if (name == "runner")
00084         {
00085           /* TAG: </node> */
00086           node.id_run.push_back (atoi (getNextNode ().c_str ()));
00087           if ( node.id_run.back() > maxSpecifiedRunnerID )
00088             maxSpecifiedRunnerID = node.id_run.back();
00089           /* TAG: </runner> */
00090           assert (getNextNode () == "runner");
00091         }
00092       else
00093         {
00094           /* TAG: </node> */
00095           node.execution_id_run = node.id_run;
00096           the_schema.push_back (node);
00097           break;
00098         }
00099     }
00100 }
00101 
00102 static void loadGroup ()
00103 {
00104 
00105   std :: string name;
00106 
00107   /* ATT: scheduler*/
00108   int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
00109 
00110   while (true)
00111     {
00112 
00113       /* TAG: <node> | </group> */
00114       name = getNextNode ();
00115       assert (name == "node" || name == "group");
00116       if (name == "node")
00117         /* TAG: <node> */
00118         loadNode (rk_sched);
00119       else
00120         /* TAG: </group> */
00121         break;
00122     }
00123 }
00124 
00125 bool isScheduleNode ()
00126 {
00127 
00128   return my_node -> rk == my_node -> rk_sched;
00129 }
00130 
00131 void loadSchema (const char * __filename)
00132 {
00133 
00134   openXMLDocument (__filename);
00135 
00136   std :: string name;
00137 
00138   /* TAG: <schema> */
00139   name = getNextNode ();
00140   assert (name == "schema");
00141 
00142   the_schema.clear();
00143   maxSpecifiedRunnerID = 0;
00144 
00145   while (true)
00146     {
00147 
00148       /* TAG: <group> | </schema> */
00149       name = getNextNode ();
00150       assert (name == "group" || name == "schema");
00151       if (name == "group")
00152         /* TAG: <group> */
00153         loadGroup ();
00154       else
00155         /* TAG: </schema> */
00156         break;
00157     }
00158 
00159 
00160   std :: set<unsigned> uniqueRunnerIDs;
00161   unsigned nbUniqueIDs = 0;
00162   for (unsigned i = 0; i < the_schema.size (); i ++)
00163     {
00164       for (unsigned j = 0; j < the_schema [i].id_run.size(); j ++)
00165         {
00166           uniqueRunnerIDs.insert( the_schema [i].id_run[j] );
00167           /* In case a duplicate ID has been found */
00168           if ( uniqueRunnerIDs.size() == nbUniqueIDs )
00169             {
00170               the_schema [i].execution_id_run[j] = ++maxSpecifiedRunnerID;
00171             }
00172           nbUniqueIDs = uniqueRunnerIDs.size();
00173         }
00174     }
00175 
00176   /* Looking for my node */
00177   for (unsigned i = 0; i < the_schema.size (); i ++)
00178     {
00179       if (the_schema [i].rk == getNodeRank ())
00180         my_node = & (the_schema [i]);
00181     }
00182 
00183 
00184   /* About me */
00185   char mess [1000];
00186 
00187   sprintf (mess, "my rank is %d", my_node -> rk);
00188   printDebugMessage (mess);
00189 
00190   if (isScheduleNode ())
00191     printDebugMessage ("I'am a scheduler");
00192 
00193   for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
00194     {
00195       sprintf (mess, "I manage the runner %d", my_node -> id_run [i]);
00196       printDebugMessage (mess);
00197     }
00198 
00199   if (my_node -> num_workers)
00200     {
00201 
00202       sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
00203       printDebugMessage (mess);
00204     }
00205 
00206   closeXMLDocument ();
00207 }

Generated on Thu Mar 13 15:55:03 2008 for ParadisEO-PEO-ParallelanddistributedEvolvingObjects by  doxygen 1.4.7