worker.cpp

00001 
00002 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00003 
00004 // "worker.cpp"
00005 
00006 // (c) OPAC Team, LIFL, August 2005
00007 
00008 /* This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Lesser General Public
00010    License as published by the Free Software Foundation; either
00011    version 2 of the License, or (at your option) any later version.
00012    
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Lesser General Public License for more details.
00017    
00018    You should have received a copy of the GNU Lesser General Public
00019    License along with this library; if not, write to the Free Software
00020    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00021    
00022    Contact: paradiseo-help@lists.gforge.inria.fr
00023 */
00024 
00025 #include <vector>
00026 
00027 #include "tags.h"
00028 #include "send.h"
00029 #include "node.h"
00030 #include "schema.h"
00031 #include "worker.h"
00032 #include "mess.h"
00033 #include "../../core/peo_debug.h"
00034 
00035 static std :: vector <Worker *> key_to_worker (1); /* Vector of registered workers */
00036 
00037 Worker * getWorker (WORKER_ID __key) {
00038 
00039   return key_to_worker [__key];  
00040 }
00041 
00042 Worker :: Worker () {
00043   
00044   toto = false;
00045   id = key_to_worker.size ();
00046   key_to_worker.push_back (this);
00047 }
00048 
00049 void Worker :: packResult () {
00050   
00051   pack (serv_id);
00052   serv -> packResult ();    
00053 }
00054 
00055 void Worker :: unpackData () {
00056 
00057   printDebugMessage ("unpacking the ID. of the service.");
00058   unpack (serv_id);
00059   serv = getService (serv_id); 
00060   printDebugMessage ("found the service.");
00061   serv -> unpackData (); 
00062   printDebugMessage ("unpacking the data.");
00063   setActive ();
00064 }
00065 
00066 void Worker :: packTaskDone () {
00067 
00068   pack (getNodeRank ());
00069   pack (id);
00070 }
00071 
00072 void Worker :: notifySendingResult () {
00073 
00074   /* Notifying the scheduler of the termination */
00075   toto = true;
00076   wakeUp ();
00077 }
00078 
00079 void Worker :: notifySendingTaskDone () {
00080 
00081   setPassive ();
00082 }
00083   
00084 void Worker :: setSource (int __rank) {
00085 
00086   src = __rank;
00087 }
00088 
00089 void Worker :: start () {
00090 
00091   while (true) {
00092     
00093     sleep (); 
00094 
00095     if (! atLeastOneActiveRunner ())
00096       break;
00097     
00098     if (toto) {
00099       send (this, my_node -> rk_sched, TASK_DONE_TAG);  
00100       toto = false;
00101     }
00102     else {
00103 
00104       printDebugMessage ("executing the task.");
00105       serv -> execute ();   
00106       send (this, src, TASK_RESULT_TAG);    
00107     }
00108   }
00109 }

Generated on Sat Dec 30 14:55:29 2006 for ParadisEO-PEO by  doxygen 1.4.7