Changeset 3402
- Timestamp:
- Mar 31, 2015, 7:02:58 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/Makefile.am
r3399 r3402 5 5 # Copyright (C) 2005 Jari Häkkinen, Peter Johansson 6 6 # Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér 7 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Peter Johansson7 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Peter Johansson 8 8 # 9 9 # This file is part of the yat library, http://dev.thep.lu.se/yat … … 82 82 test/score.test \ 83 83 test/scheduler.test \ 84 test/scheduler2.test \ 84 85 test/segment.test test/smart_ptr.test \ 85 86 test/smith_waterman.test \ -
trunk/yat/utility/Scheduler.cc
r3401 r3402 26 26 #include <cassert> 27 27 28 #include <iostream> 29 28 30 namespace theplu { 29 31 namespace yat { … … 31 33 32 34 Scheduler::Scheduler(unsigned int threads) 33 : running_jobs_(0) 35 : running_jobs_(0), job_counter_(0) 34 36 { 35 37 assert(threads); … … 69 71 return; 70 72 job->status_ = Job::prepared; 73 job->id_ = job_counter_; 74 ++job_counter_; 71 75 72 76 // If we have prerequisite that need to be run first, process them … … 128 132 // Scheduler::Job 129 133 130 Scheduler::Job::Job( void)131 : status_(pristine) {}134 Scheduler::Job::Job(unsigned int prio) 135 : status_(pristine), priority_(prio), id_(0) {} 132 136 133 137 … … 136 140 137 141 142 unsigned int Scheduler::Job::priority(void) const 143 { 144 return priority_; 145 } 146 147 148 bool Scheduler::LowerPriority::operator()(const JobPtr& lhs, 149 const JobPtr& rhs) const 150 { 151 if (rhs.get() == NULL) 152 return false; 153 if (lhs.get() == NULL) 154 return true; 155 156 if (lhs->priority() != rhs->priority()) 157 return lhs->priority() < rhs->priority(); 158 159 return lhs->id_ > rhs->id_; 160 } 161 162 138 163 // Scheduler::Worker 139 164 140 Scheduler::Worker::Worker(Queue<boost::shared_ptr<Job> >& q, 141 Queue<boost::shared_ptr<Job> >& c) 165 Scheduler::Worker::Worker(JobQueue& q, Queue<JobPtr>& c) 142 166 : queue_(q), completed_(c) 143 167 { -
trunk/yat/utility/Scheduler.h
r3401 r3402 23 23 */ 24 24 25 #include "PriorityQueue.h" 25 26 #include "Queue.h" 26 27 … … 41 42 series of Jobs. The Jobs can have dependencies, such that Job X 42 43 must finish before Job Y can run, and the Scheduler takes care of 43 these dependencies. Here is a small code example in which two44 these dependencies. Here is a small code example in which two 44 45 threads are used to process the four jobs, \c MyJob. The jobs 45 46 have a dependency that job4 can not run until the three first … … 57 58 scheduler.add_dependency(job4, job3); 58 59 scheduler.submit(job4); 59 scheduler. launch();60 scheduler.wait(); 60 61 61 62 \endcode 63 64 The Scheduler sends jobs to the workers taking into account 65 dependencies, priorities and the order in which the Scheduler has 66 seen the Jobs. Of the Jobs that are ready to run, i.e., all jobs 67 it depends on have completed, the Scheduler chose the Job with 68 highest priority. If two Jobs have the same priority, the 69 Scheduler sends them in the order of appearance, i.e., if the 70 Scheduler saw Job X before Job Y, Job X is run before Job X. 71 72 \since New in yat 0.13 62 73 */ 63 74 class Scheduler … … 73 84 \brief constructor 74 85 */ 75 Job(void);86 explicit Job(unsigned int prio=0); 76 87 77 88 /** … … 79 90 */ 80 91 virtual ~Job(void); 92 93 /** 94 Jobs with greater priority are run before Jobs with less priority. 95 */ 96 unsigned int priority(void) const; 81 97 82 98 /** … … 92 108 enum status { pristine, prepared, running, completed}; 93 109 status status_; 110 unsigned priority_; 111 unsigned id_; 94 112 }; // end class Job 95 113 … … 124 142 125 143 private: 144 typedef boost::shared_ptr<Scheduler::Job> JobPtr; 145 146 struct LowerPriority 147 { 148 bool operator()(const JobPtr& lhs, const JobPtr& rhs) const; 149 }; 150 151 // some typedefs for convenience 152 typedef PriorityQueue<JobPtr, LowerPriority> JobQueue; 153 126 154 // \internal class that does the job 127 155 // … … 133 161 { 134 162 public: 135 Worker(Queue<boost::shared_ptr<Job> >& queue, 136 Queue<boost::shared_ptr<Job> >& completed); 163 Worker(JobQueue& queue, Queue<JobPtr>& completed); 137 164 void operator()(void); 138 165 private: 139 Queue<boost::shared_ptr<Job> >& queue_;140 Queue< boost::shared_ptr<Job>>& completed_;166 JobQueue& queue_; 167 Queue<JobPtr>& completed_; 141 168 }; // end class Worker 142 169 … … 155 182 void queue(boost::shared_ptr<Job> job); 156 183 157 typedef boost::shared_ptr<Scheduler::Job> JobPtr;158 184 int running_jobs_; 159 185 160 Queue<boost::shared_ptr<Job> >queue_;161 Queue< boost::shared_ptr<Job>> completed_;186 JobQueue queue_; 187 Queue<JobPtr> completed_; 162 188 boost::thread_group workers_; 163 189 unsigned long int job_counter_; 164 190 }; // end class Scheduler 165 191
Note: See TracChangeset
for help on using the changeset viewer.