worker.cpp

00001 // "worker.cpp"
00002 
00003 // (c) OPAC Team, LIFL, August 2005
00004 
00005 /* 
00006    Contact: paradiseo-help@lists.gforge.inria.fr
00007 */
00008 
00009 #include <vector>
00010 
00011 #include "tags.h"
00012 #include "send.h"
00013 #include "node.h"
00014 #include "schema.h"
00015 #include "worker.h"
00016 #include "mess.h"
00017 #include "../../core/peo_debug.h"
00018 
00019 static std :: vector <Worker *> key_to_worker (1); /* Vector of registered workers */
00020 
00021 Worker * getWorker (WORKER_ID __key) {
00022 
00023   return key_to_worker [__key];  
00024 }
00025 
00026 Worker :: Worker () {
00027   
00028   toto = false;
00029   id = key_to_worker.size ();
00030   key_to_worker.push_back (this);
00031 }
00032 
00033 void Worker :: packResult () {
00034   
00035   pack (serv_id);
00036   serv -> packResult ();    
00037 }
00038 
00039 void Worker :: unpackData () {
00040 
00041   printDebugMessage ("unpacking the ID. of the service.");
00042   unpack (serv_id);
00043   serv = getService (serv_id); 
00044   printDebugMessage ("found the service.");
00045   serv -> unpackData (); 
00046   printDebugMessage ("unpacking the data.");
00047   setActive ();
00048 }
00049 
00050 void Worker :: packTaskDone () {
00051 
00052   pack (getNodeRank ());
00053   pack (id);
00054 }
00055 
00056 void Worker :: notifySendingResult () {
00057 
00058   /* Notifying the scheduler of the termination */
00059   toto = true;
00060   wakeUp ();
00061 }
00062 
00063 void Worker :: notifySendingTaskDone () {
00064 
00065   setPassive ();
00066 }
00067   
00068 void Worker :: setSource (int __rank) {
00069 
00070   src = __rank;
00071 }
00072 
00073 void Worker :: start () {
00074 
00075   while (true) {
00076     
00077     sleep (); 
00078 
00079     if (! atLeastOneActiveRunner ())
00080       break;
00081     
00082     if (toto) {
00083       send (this, my_node -> rk_sched, TASK_DONE_TAG);  
00084       toto = false;
00085     }
00086     else {
00087 
00088       printDebugMessage ("executing the task.");
00089       serv -> execute ();   
00090       send (this, src, TASK_RESULT_TAG);    
00091     }
00092   }
00093 }

Generated on Thu Jul 5 13:43:30 2007 for ParadisEO-PEO by  doxygen 1.4.7