summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/examples/FaultTolerance/FLARe/DeCoRAM/src/Scheduler.cpp
blob: 6c7459d8aa1c8fa9c7d1673ef670650cbc19e558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Scheduler.cpp
 *
 *  $Id$
 *
 *  @author  Friedhelm Wolf (fwolf@dre.vanderbilt.edu)
 */
//=============================================================================

#include "Scheduler.h"

Scheduler::Scheduler (const PROCESSOR_LIST & processors,
                      unsigned int max_failures)
  : schedule_ (create_schedule (processors)),
    max_failures_ (max_failures)
{
}

Scheduler::~Scheduler (void)
{
}

ScheduleResult
Scheduler::operator () (const Task & task)
{
  ScheduleResult result;
  result.task = task;
  result.processor = "NO PROCESSOR";
  result.wcrt = .0;

  for (SCHEDULE::iterator processor_it = schedule_.begin ();
       processor_it != schedule_.end ();
       ++processor_it)
    {
      double wcrt = this->schedule_task (task, processor_it->first);

      if (wcrt > .0)
        {
          // take result value and exit if we find a match
          result.wcrt = wcrt;
          result.processor = processor_it->first;

          // add the task to the schedule
          this->update_schedule (task, processor_it->first);

          break;
        }
    } // end for
    
  return result;  
}

void
Scheduler::update_schedule (const Task & task,
                            const Processor & processor)
{
  schedule_[processor].push_back (task);

  this->update_replica_groups (task, processor);
}

void
Scheduler::update_replica_groups (const Task & task,
                                  const Processor & processor)
{
  // create entry
  TASK_POSITION tp (processor, 
                    task);

  // add entry to respective replica group
  if (task.rank == 0)
    {
      // create a new group
      TASK_POSITIONS group;
      group.push_back (tp);
      replica_groups_[primary_name (task)] = group;
    }
  else
    {
      replica_groups_[primary_name (task)].push_back (tp);
    }

  TRACE (replica_groups_);
}

SCHEDULE
Scheduler::schedule (void) const
{
  return schedule_;
}

ProcessorNameComparison::ProcessorNameComparison (const Processor & p)
  :p_ (p)
{
}

Processor 
ProcessorPicker::operator () (const TASK_POSITIONS::value_type & entry)
{
  return entry.first;
}

bool
ProcessorNameComparison::operator () (bool equal, 
                                      const TASK_POSITIONS::value_type & pos)
{
  return (equal || (pos.first.compare (p_) == 0));
}

std::ostream & operator<< (std::ostream & ostr, 
                           const TASK_POSITION & tp)
{
  ostr << tp.second << "@" << tp.first;

  return ostr;
}

std::ostream & operator<< (std::ostream & ostr, 
                           const TASK_POSITIONS & tps)
{
  ostr << "[";
  for (TASK_POSITIONS::const_iterator it = tps.begin ();
       it != tps.end ();
       ++it)
    {
      ostr << *it << ", ";
    }
  ostr << "]";

  return ostr;
}

std::ostream & operator<< (std::ostream & ostr, 
                           const REPLICA_GROUPS & rg)
{
  ostr << "REPLICA_GROUPS:";
  for (REPLICA_GROUPS::const_iterator it = rg.begin ();
       it != rg.end ();
       ++it)
    {
      ostr << std::endl << it->first << ": " << it->second;
    }
  
  return ostr;
}