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 "tags.h"
00040 #include "send.h"
00041 #include "node.h"
00042 #include "schema.h"
00043 #include "worker.h"
00044 #include "mess.h"
00045 #include "../../core/peo_debug.h"
00046
00047 static std :: vector <Worker *> key_to_worker (1);
00048
00049 Worker * getWorker (WORKER_ID __key) {
00050
00051 return key_to_worker [__key];
00052 }
00053
00054 Worker :: Worker () {
00055
00056 toto = false;
00057 id = key_to_worker.size ();
00058 key_to_worker.push_back (this);
00059 }
00060
00061 void Worker :: packResult () {
00062
00063 pack (serv_id);
00064 serv -> packResult ();
00065 }
00066
00067 void Worker :: unpackData () {
00068
00069 printDebugMessage ("unpacking the ID. of the service.");
00070 unpack (serv_id);
00071 serv = getService (serv_id);
00072 printDebugMessage ("found the service.");
00073 serv -> unpackData ();
00074 printDebugMessage ("unpacking the data.");
00075 setActive ();
00076 }
00077
00078 void Worker :: packTaskDone () {
00079
00080 pack (getNodeRank ());
00081 pack (id);
00082 }
00083
00084 void Worker :: notifySendingResult () {
00085
00086
00087 toto = true;
00088 wakeUp ();
00089 }
00090
00091 void Worker :: notifySendingTaskDone () {
00092
00093 setPassive ();
00094 }
00095
00096 void Worker :: setSource (int __rank) {
00097
00098 src = __rank;
00099 }
00100
00101 void Worker :: start () {
00102
00103 while (true) {
00104
00105 sleep ();
00106
00107 if (! atLeastOneActiveRunner ())
00108 break;
00109
00110 if (toto) {
00111 send (this, my_node -> rk_sched, TASK_DONE_TAG);
00112 toto = false;
00113 }
00114 else {
00115
00116 printDebugMessage ("executing the task.");
00117 serv -> execute ();
00118 send (this, src, TASK_RESULT_TAG);
00119 }
00120 }
00121 }