00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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;
00045
00046 static std :: vector <pthread_t *> ll_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
00098
00099
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
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 }