- Main Page
- Namespaces
- Classes
- Files

- Search for |

# runner.cpp

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