Difference between termination messages Kill (stops the worker) and Terminate (waits for another task).

This commit is contained in:
Benjamin Bouvier 2012-07-10 14:48:46 +02:00
commit 606eef08d8

View file

@ -31,7 +31,8 @@ namespace eo
namespace Message namespace Message
{ {
const int Continue = 0; const int Continue = 0;
const int Finish = 1; const int Finish = 1; // TODO commentaire : différence entre finir une tâche et arrêter le worker à expliciter.
const int Kill = 2;
} }
const int DEFAULT_MASTER = 0; const int DEFAULT_MASTER = 0;
@ -239,6 +240,7 @@ namespace eo
~FinallyBlock() ~FinallyBlock()
{ {
# ifndef NDEBUG # ifndef NDEBUG
eo::log << eo::debug;
eo::log << "[M" << comm.rank() << "] Frees all the idle." << std::endl; eo::log << "[M" << comm.rank() << "] Frees all the idle." << std::endl;
# endif # endif
// frees all the idle workers // frees all the idle workers
@ -264,7 +266,6 @@ namespace eo
assignmentAlgo.confirm( wrkRank ); assignmentAlgo.confirm( wrkRank );
} }
timerStat.stop("master_wait_for_all_responses"); timerStat.stop("master_wait_for_all_responses");
# ifndef NDEBUG # ifndef NDEBUG
eo::log << "[M" << comm.rank() << "] Leaving master task." << std::endl; eo::log << "[M" << comm.rank() << "] Leaving master task." << std::endl;
# endif # endif
@ -321,7 +322,6 @@ namespace eo
s.append( " in eoMpi loop"); s.append( " in eoMpi loop");
throw std::runtime_error( s ); throw std::runtime_error( s );
} }
} }
void worker( ) void worker( )
@ -330,27 +330,32 @@ namespace eo
# ifndef NDEBUG # ifndef NDEBUG
eo::log << eo::debug; eo::log << eo::debug;
# endif # endif
timerStat.start("worker_wait_for_order");
comm.recv( masterRank, Channel::Commands, order );
timerStat.stop("worker_wait_for_order");
while( true ) while( true )
{ {
# ifndef NDEBUG # ifndef NDEBUG
eo::log << "[W" << comm.rank() << "] Waiting for an order..." << std::endl; eo::log << "[W" << comm.rank() << "] Waiting for an order..." << std::endl;
# endif # endif
timerStat.start("worker_wait_for_order"); if ( order == Message::Kill )
comm.recv( masterRank, Channel::Commands, order );
timerStat.stop("worker_wait_for_order");
if ( order == Message::Finish )
{ {
# ifndef NDEBUG # ifndef NDEBUG
eo::log << "[W" << comm.rank() << "] Leaving worker task." << std::endl; eo::log << "[W" << comm.rank() << "] Leaving worker task." << std::endl;
# endif # endif
return; return;
} else } else if( order == Message::Continue )
{ {
# ifndef NDEBUG # ifndef NDEBUG
eo::log << "[W" << comm.rank() << "] Processing task..." << std::endl; eo::log << "[W" << comm.rank() << "] Processing task..." << std::endl;
# endif # endif
processTask( ); processTask( );
} }
timerStat.start("worker_wait_for_order");
comm.recv( masterRank, Channel::Commands, order );
timerStat.stop("worker_wait_for_order");
} }
} }