- Main Page
- Namespaces
- Classes
- Files

- Search for |

# runner.cpp

    00001 /*
    00002 * <runner.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 <vector>
    00038
    00039 #include "runner.h"
    00040 #include "reac_thread.h"
    00041 #include "peo_debug.h"
    00042 #include "messaging.h"
    00043
    00044 static unsigned num_act = 0; /* Number of active runners */
    00045
    00046 static std :: vector <pthread_t *> ll_threads; /* Low-level runner threads */
    00047
    00048 static std :: vector <Runner *> the_runners;
    00049
    00050 static unsigned num_runners = 0;
    00051
    00052 Runner :: Runner () {
    00053
    00054   id = ++ num_runners;
    00055   the_runners.push_back (this);
    00056   sem_init (& sem_start, 0, 0);
    00057   num_act ++;
    00058 }
    00059
    00060 extern int getNodeRank ();
    00061
    00062 extern int getNumberOfNodes ();
    00063
    00064 void unpackTerminationOfRunner () {
    00065
    00066   RUNNER_ID id;
    00067   unpack (id);
    00068   num_act --;
    00069   printDebugMessage ("I'm noticed of the termination of a runner");
    00070   if (! num_act) {
    00071     printDebugMessage ("all the runners have terminated. Now stopping the reactive threads.");
    00072     stopReactiveThreads ();
    00073   }
    00074 }
    00075
    00076 bool atLeastOneActiveRunner () {
    00077
    00078   return num_act;
    00079 }
    00080
    00081 RUNNER_ID Runner :: getID () {
    00082
    00083   return id;
    00084 }
    00085
    00086 void Runner :: start () {
    00087
    00088   setActive ();
    00089   sem_post (& sem_start);
    00090   run ();
    00091   terminate ();
    00092 }
    00093
    00094 void Runner :: notifySendingTermination () {
    00095
    00096   /*
    00097   char b [1000];
    00098   sprintf (b, "Il reste encore %d !!!!!!!!!!!!", n);
    00099   printDebugMessage (b);
    00100   */
    00101   printDebugMessage ("je suis informe que tout le monde a recu ma terminaison");
    00102   setPassive ();
    00103
    00104 }
    00105
    00106 void Runner :: waitStarting () {
    00107
    00108   sem_wait (& sem_start);
    00109 }
    00110
    00111 Runner * getRunner (RUNNER_ID __key) {
    00112
    00113   return dynamic_cast <Runner *> (getCommunicable (__key));
    00114 }
    00115
    00116 void startRunners () {
    00117
    00118   /* Runners */
    00119   for (unsigned i = 0; i < the_runners.size (); i ++)
    00120     if (the_runners [i] -> isLocal ()) {
    00121       addThread (the_runners [i], ll_threads);
    00122       the_runners [i] -> waitStarting ();
    00123     }
    00124   printDebugMessage ("launched the parallel runners");
    00125 }
    00126
    00127
    00128 void joinRunners () {
    00129
    00130
    00131   joinThreads (ll_threads);
    00132 }