00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <vector>
00010
00011 #include "runner.h"
00012 #include "reac_thread.h"
00013 #include "peo_debug.h"
00014 #include "messaging.h"
00015
00016 static unsigned num_act = 0;
00017
00018 static std :: vector <pthread_t *> ll_threads;
00019
00020 static std :: vector <Runner *> the_runners;
00021
00022 static unsigned num_runners = 0;
00023
00024 Runner :: Runner () {
00025
00026 id = ++ num_runners;
00027 the_runners.push_back (this);
00028 sem_init (& sem_start, 0, 0);
00029 num_act ++;
00030 }
00031
00032 extern int getNodeRank ();
00033
00034 extern int getNumberOfNodes ();
00035
00036 void unpackTerminationOfRunner () {
00037
00038 RUNNER_ID id;
00039 unpack (id);
00040 num_act --;
00041 printDebugMessage ("I'm noticed of the termination of a runner");
00042 if (! num_act) {
00043 printDebugMessage ("all the runners have terminated. Now stopping the reactive threads.");
00044 stopReactiveThreads ();
00045 }
00046 }
00047
00048 bool atLeastOneActiveRunner () {
00049
00050 return num_act;
00051 }
00052
00053 RUNNER_ID Runner :: getID () {
00054
00055 return id;
00056 }
00057
00058 void Runner :: start () {
00059
00060 setActive ();
00061 sem_post (& sem_start);
00062 run ();
00063 terminate ();
00064 }
00065
00066 void Runner :: notifySendingTermination () {
00067
00068
00069
00070
00071
00072
00073 printDebugMessage ("je suis informe que tout le monde a recu ma terminaison");
00074 setPassive ();
00075
00076 }
00077
00078 void Runner :: waitStarting () {
00079
00080 sem_wait (& sem_start);
00081 }
00082
00083 Runner * getRunner (RUNNER_ID __key) {
00084
00085 return dynamic_cast <Runner *> (getCommunicable (__key));
00086 }
00087
00088 void startRunners () {
00089
00090
00091 for (unsigned i = 0; i < the_runners.size (); i ++)
00092 if (the_runners [i] -> isLocal ()) {
00093 addThread (the_runners [i], ll_threads);
00094 the_runners [i] -> waitStarting ();
00095 }
00096 printDebugMessage ("launched the parallel runners");
00097 }
00098
00099
00100 void joinRunners () {
00101
00102
00103 joinThreads (ll_threads);
00104 }