GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
scheduler_list.cpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #include <algorithm>
25 #include <graphlab/scheduler/scheduler_list.hpp>
26 #include <graphlab/engine/iengine.hpp>
27 #include <graphlab/util/stl_util.hpp>
28 
29 
30 namespace graphlab {
31 
32  std::vector<std::string> get_scheduler_names() {
33  std::vector<std::string> ret;
34 #define __APPEND_TO_RET__(r_unused, data_unused, i, elem) \
35  ret.push_back(BOOST_PP_TUPLE_ELEM(3,0,elem));
36  BOOST_PP_SEQ_FOR_EACH_I(__APPEND_TO_RET__, _, __SCHEDULER_LIST__)
37 #undef __APPEND_TO_RET__
38  return ret;
39  }
40 
41 
42  std::string get_scheduler_names_str() {
43  std::string ret;
44  std::vector<std::string> schednames;
45  schednames = get_scheduler_names();
46  for (size_t i = 0; i < schednames.size(); ++i) {
47  if (i > 0) {
48  ret = ret + ", ";
49  }
50  ret = ret + schednames[i];
51  }
52  return ret;
53  }
54 
55  static std::string add_line_breaks(const std::string &s, size_t numcols) {
56  size_t pos = 0;
57  std::string ret;
58  while(pos < s.length() - 1) {
59  size_t oldpos = pos;
60  pos = std::min(pos + numcols, s.length());
61 
62  size_t newpos = pos;
63  // search backward for a space if we are not at the end of the
64  // string
65  if (pos < s.length()) {
66  newpos = s.rfind(" ", pos);
67  }
68  // if we get back to the old position, or we fail to find a
69  // space, force the break
70  if (newpos == std::string::npos || newpos == oldpos) {
71  newpos = pos;
72  }
73  // break
74  ret = ret + trim(s.substr(oldpos, newpos - oldpos)) + "\n";
75  pos = newpos;
76  }
77  return ret;
78  }
79 
80 
81  void print_scheduler_info(std::string s, std::ostream &out) {
82  typedef char dummy_message_type;
83  // this is annoying... I need to instantiate the graph<char, char> type to
84  // even call the scheduler
85 #define __GENERATE_SCHEDULER_HELP__(r_unused, data_unused, i, elem) \
86  BOOST_PP_EXPR_IF(i, else) if (s == BOOST_PP_TUPLE_ELEM(3,0,elem)) { \
87  out << "\n"; \
88  out << BOOST_PP_TUPLE_ELEM(3,0,elem) << " scheduler\n"; \
89  out << std::string(50, '-') << std::endl; \
90  out << add_line_breaks(BOOST_PP_TUPLE_ELEM(3,2,elem), 50) << "\n" \
91  << "Options: \n"; \
92  BOOST_PP_TUPLE_ELEM(3,1,elem)< dummy_message_type > \
93  ::print_options_help(out); \
94  }
95  /*
96  * if (scheduler == "sweep") {
97  * sweep_scheduler<graph<char,char> >::print_options_help(out);
98  * }
99  * ...
100  */
101  // generate the construction calls
102  BOOST_PP_SEQ_FOR_EACH_I(__GENERATE_SCHEDULER_HELP__, _, __SCHEDULER_LIST__)
103  else {
104  out << "Scheduler " << s << " not found" << "\n";
105  }
106 #undef __GENERATE_SCHEDULER_HELP__
107  } // end of print scheduler info
108 
109 
110 } // end of namespace graphlab
111 
112 
113