Changeset 3855 in Sophya


Ignore:
Timestamp:
Aug 12, 2010, 1:02:24 AM (15 years ago)
Author:
ansari
Message:

Ajout attribut nombre de threads ds ParallelTaskInterface, Reza 12/08/2010

Location:
trunk/SophyaLib/SysTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/SysTools/parlex.cc

    r3730 r3855  
    1111
    1212/*!
     13  \class ParallelTaskInterface
     14  \ingroup SysTools
     15  \brief Interface definition for parallel task object.
     16
     17  The pure virtual method execute() should be redefined by the classes
     18  inheriting from ParallelTaskInterface
     19*/ 
     20ParallelTaskInterface::ParallelTaskInterface()
     21{
     22  setNbParallelThreads(0);
     23}
     24ParallelTaskInterface::~ParallelTaskInterface()
     25{
     26}
     27/*!
     28  \brief Define the number of parallel threads running to perform the task
     29
     30  This method is called by ParallelExecutor object. If subclasses overwrite this method,
     31  base class method should be called to set the value of nbparallel_ attribute.
     32*/
     33void ParallelTaskInterface::setNbParallelThreads(int nbparthr)
     34{
     35  nbparallel_=nbparthr;
     36}
     37
     38/*!
    1339  \class ParallelTaskFunction
    1440  \ingroup SysTools
    1541  \brief ParallelTaskInterface implementation for functions
     42
     43  The function which are executed by the ParallelTaskFunction execute() method should
     44  conform to the prototype:  int func(int tid, int nparthr)
     45
     46  tid (counting from zero) is the thread rank, and nparthr the number of parallel threads
     47  executing in the context
    1648*/ 
    1749//! Constructor with the specification of the function to be executed
     
    2254int ParallelTaskFunction::execute(int tid)
    2355{
    24   return parfunc_(tid);
     56  return parfunc_(tid, getNbParallelThreads());
    2557}
    2658
     
    184216    vrc_[i] = 0;
    185217  }
     218  ptask.setNbParallelThreads( nthr );
    186219}
    187220
     
    195228{
    196229  if (vptask.size()<1) throw ParmError("ParallelExecutor(vector<ptask>/Error vptask.size()<1");
     230  int nthr= (int)nThreads();
    197231  for(size_t i=0; i<vpext_.size(); i++) {
    198232    vpext_[i] = new ParalExThread( (*vptask[i]), i);
     233    vptask[i]->setNbParallelThreads(nthr);
    199234    vrc_[i] = 0;
    200235  }
     
    219254  for(size_t i=0; i<vpext_.size(); i++)
    220255    vpext_[i]->setParallelTask(ptask);
     256  ptask.setNbParallelThreads( (int)nThreads() );
    221257  return;
    222258}
     
    229265  if (vptask.size()!=vpext_.size())
    230266    throw SzMismatchError("ParallelExecutor::SetParallelTask(vector<ptask>) - vptask.size()!=vpext.size()");
    231   for(size_t i=0; i<vpext_.size(); i++)
     267  int nthr= (int)nThreads();
     268  for(size_t i=0; i<vpext_.size(); i++) {
    232269    vpext_[i]->setParallelTask(*vptask[i]);
     270    vptask[i]->setNbParallelThreads(nthr);
     271  }
    233272  return;
    234273}
  • trunk/SophyaLib/SysTools/parlex.h

    r3718 r3855  
    55
    66// Classes pour execution de taches paralleles en utilisant les threads
    7 //    R. Ansari       UPS+LAL IN2P3/CNRS  2005
     7//    R. Ansari       UPS+LAL IN2P3/CNRS  2009-2010
    88
    99#include "zthread.h"
     
    1717//  s'executer en parallele
    1818//--------------------------------------------------------------------
    19 /*!
    20   \class ParallelTaskInterface
    21   \ingroup SysTools
    22   \brief Interface definition for parallel task object.
    23 
    24   The pure virtual method execute() should be redefined by the classes
    25   inheriting from ParallelTaskInterface
    26 */ 
    2719class ParallelTaskInterface {
    2820public:
    29   explicit       ParallelTaskInterface()  { }
    30   virtual        ~ParallelTaskInterface() { }
     21  explicit       ParallelTaskInterface();
     22  virtual        ~ParallelTaskInterface();
    3123  /*! This method should perform the actual computation. The parameter tid
    3224    is used by the ParallelExecutor class to identify the thread calling the method
    3325  */
    3426  virtual int    execute(int tid) = 0;
     27  //! Define the number of parallel threads running to perform the task (set by ParallelExecutor object)
     28  virtual void   setNbParallelThreads(int nbparthr);
     29  //! Return the number of parallel threads running to perform the task
     30  inline  int    getNbParallelThreads() { return nbparallel_; }
     31protected:
     32  int nbparallel_;   // total number of parallel threads which will perform the job
    3533};
    3634
    3735//---- Implementation de ParallelTaskInterface pour l'execution des fonctions
    38 typedef int (* ParalExFunction) (int);
     36//! Prototype for functions which executed by ParallelTaskFunction objects
     37typedef int (* ParalExFunction) (int,int);
    3938//----
    40 class ParallelTaskFunction {
     39  class ParallelTaskFunction : public ParallelTaskInterface {
    4140public:
    4241  explicit       ParallelTaskFunction(ParalExFunction f);
     
    116115  //! Return RC for the ParalleTask.execute() of thread i
    117116  inline  int     getRC(size_t i) { return vrc_[i]; }
    118   //! Return the execption condition for the ParalleTask.execute() of thread i
     117  //! Return the exception condition for the ParalleTask.execute() of thread i
    119118  inline  bool    IfException(size_t i, string& msg)  { return vpext_[i]->IfException(msg); }
    120119
Note: See TracChangeset for help on using the changeset viewer.