summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/examples/FaultTolerance/FLARe/DeCoRAM/src/binary_ftrmff.cpp
blob: eedcb55a44974cc0fa8ca4154a141399459cd92d (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
// -*- C++ -*-

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

#include <fstream>
#include <sstream>
#include <iostream>
#include <ace/Get_Opt.h>
#include "FTRMFF_Binary_Search.h"

std::string filename = "test.sd"; // filename of task list input
unsigned int m = 4; // number of processors
unsigned int c = 2; // consitency level

int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if (argc > 1)
    filename = argv[1];

  if (argc > 2)
    m = atoi (argv[2]);

  if (argc > 3)
    c = atoi (argv[3]);

  TASK_LIST tasks;
  PROCESSOR_LIST procs;
  for (unsigned int i = 1; i <= m; ++i)
    {
      std::stringstream ss;
      ss << "P";
      if (i < 10)
        ss << "00";
      else if (i < 100)
        ss << "0";
      ss << i;
      procs.push_back (ss.str ());
    }

  std::ifstream ifile;
  ifile.open (filename.c_str ());

  std::transform (
    std::istream_iterator <std::string> (ifile),
    std::istream_iterator <std::string> (),
    std::inserter <TASK_LIST> (tasks,
                               tasks.begin ()),
    string_to_task ());
  
  ifile.close ();

  FTRMFF_Binary_Search ftrmff;

  FTRMFF_Input input;
  input.tasks = tasks;
  input.processors = procs;
  input.backup_count = c;
  FTRMFF_Output result = ftrmff (input);

#if 0
  for (SCHEDULING_MAP::iterator it = result.schedule.begin ();
       it != result.schedule.end ();
       ++it)
    {
      std::cout << it->first << " -> " 
                << it->second.processor 
                << " (" << it->second.priority << ")" 
                << std::endl;
    }
#endif

  if (result.unscheduled_tasks.size () > 0)
    {
      std::cout << "Could not schedule :"
                << std::endl
                << result.unscheduled_tasks
                << std::endl;

      return 1;
    }

  return 0;
}