summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/examples/FaultTolerance/FLARe/DeCoRAM/src/Scheduler.cpp
blob: 6259c58978518898d0c977b9581912ebb351a5ab (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// -*- C++ -*-

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

#include "Scheduler.h"
#include <algorithm>

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;

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

void
Scheduler::update_schedule (const ScheduleResult & result)
{
  schedule_[result.processor].push_back (result.task);

  this->update_replica_groups (result);
}

void
Scheduler::update_replica_groups (const ScheduleResult & result)
{
  // create entry
  TASK_POSITION tp (result.processor, 
                    result.task);

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

  TRACE (replica_groups_);
}

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

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

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

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

ReplicaFinder::ReplicaFinder (const REPLICA_GROUPS & rep_groups)
  : rep_groups_ (rep_groups) 
{
}

ReplicaFinder::~ReplicaFinder (void)
{
}

PROCESSOR_SET 
ReplicaFinder::operator () (const Task & task) const
{
  PROCESSOR_SET result;

  TRACE ("TEST");
  TRACE (rep_groups_);
  
  REPLICA_GROUPS::const_iterator replicas = 
    rep_groups_.find (primary_name (task));
  
  if (replicas != rep_groups_.end ())
    {
      std::transform (replicas->second.begin (),
                      replicas->second.begin () + task.rank,
                      std::inserter (result,
                                     result.begin ()),
                      processor_picker_);
    }
  
  return result;
}

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;
}


std::ostream & operator<< (std::ostream & ostr, 
                           const PROCESSOR_SETS & ps)
{
  ostr << "{";
  for (PROCESSOR_SETS::const_iterator it = ps.begin ();
       it != ps.end ();
       ++it)
    {
      ostr << *it << "| ";
    }
  ostr << "}";

  return ostr;
}

std::ostream & operator<< (std::ostream & ostr, 
                           const TASK_SCENARIOS & ts)
{
  ostr << "{";
  for (TASK_SCENARIOS::const_iterator it = ts.begin ();
       it != ts.end ();
       ++it)
    {
      ostr << *it << "| ";
    }
  ostr << "}";

  return ostr;  
}