pmm  1.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
pmm_scheduler.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2010 Robert Higgins
3  Author: Robert Higgins <robert.higgins@ucd.ie>
4  Author: David Clarke <dave.p.clarke@gmail.com>
5 
6  This file is part of PMM.
7 
8  PMM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  PMM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with PMM. If not, see <http://www.gnu.org/licenses/>.
20 */
21 /*!
22  * @file pmm_scheduler.c
23  * @brief Choose next routine to benchmark
24  *
25  * Code to select next routine that should be benchmarked.
26  */
27 #if HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30 
31 #include "pmm_model.h"
32 #include "pmm_cond.h"
33 
34 /*!
35  * Function handles the chosing of the next routine to benchmark.
36  *
37  * @param scheduled pointer to pointer describing routine picked for
38  * scheduling
39  * @param r pointer to array of routines from which to pick
40  * @param n number of routines in array
41  *
42  * @return 0 if all routines are already complete (so we don't need to try
43  * to schedule them any longer), 1 if there is a schedulable routine, 2 if
44  * there are no schedulable routines at present (but some are still incomplete)
45  *
46  */
47 int
48 schedule_routine(struct pmm_routine** scheduled, struct pmm_routine** r, int n) {
49 
50  int i, status = 0;
51  *scheduled = NULL;
52 
53 
54  //iterate over r
55  for(i=0; i<n; i++) {
56 
57  check_conds(r[i]);
58 
59  //check routine is executable and model is not complete
60  if(r[i]->executable &&
61  !r[i]->model->complete) { //TODO possibly rearrange these checks
62  //if no routine is scheduled
63  if(*scheduled == NULL) {
64  *scheduled = r[i];
65  status = 1;
66  }
67 
68  //if priority is greater change scheduled
69  else if(r[i]->priority > (*scheduled)->priority) {
70  *scheduled = r[i];
71  }
72 
73  //if priorities are equal then keep the least complete (or
74  //do nothing if completion is equal.
75  else if(r[i]->priority == (*scheduled)->priority) {
76  if(r[i]->model->completion < (*scheduled)->model->completion) {
77  *scheduled = r[i];
78  }
79  }
80  }
81  //check if there is routines incomplete and not executable
82  if(!r[i]->model->complete && status == 0)
83  status = 2;
84  }
85 
86  return status;
87 }