00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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;
00032
00033 static std :: vector <pthread_t *> ll_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
00085
00086
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
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 }