GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ischeduler.hpp
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  * Also contains code that is Copyright 2011 Yahoo! Inc. All rights
25  * reserved.
26  *
27  * Contributed under the iCLA for:
28  * Joseph Gonzalez ([email protected])
29  *
30  */
31 
32 
33 #ifndef GRAPHLAB_ISCHEDULER_HPP
34 #define GRAPHLAB_ISCHEDULER_HPP
35 
36 #include <vector>
37 #include <sstream>
38 #include <ostream>
39 
40 #include <graphlab/graph/graph_basic_types.hpp>
41 
42 #include <graphlab/options/graphlab_options.hpp>
43 
44 
45 
46 namespace graphlab {
47 
48  /**
49  * This is an enumeration for the possible return values for
50  * get_next_tasks
51  */
52  struct sched_status {
53  /// \brief the possible scheduler status.
54  enum status_enum {
55  NEW_TASK, /**< The get_next_tasks function returned a new task
56  to be executed */
57  EMPTY, /**< The schedule is empty. */
58  };
59  };
60 
61 
62  /**
63  * \ingroup group_schedulers
64  *
65  * This describes the interface/concept for . The
66  * engine will be passed the scheduler type as a template argument,
67  * so the scheduler must inherit and satisfy this interface
68  * EXACTLY. Note that all functions (with the exception of the
69  * constructor and destructor and start()) must be thread-safe.
70  */
71  template<typename MessageType>
72  class ischeduler {
73  public:
74 
75  typedef MessageType message_type;
76 
77 
78  /// destructor
79  virtual ~ischeduler() {};
80 
81  /** Called by engine before starting the schedule. */
82  virtual void start() = 0;
83 
84 
85  /**
86  * Adds a message destined to the vertex vid to the schedule.
87  */
88  virtual void schedule(const lvid_type vid,
89  const message_type& message) = 0;
90 
91  /**
92  * Adds a message destined to the vertex vid to the schedule
93  */
94  virtual void schedule_from_execution_thread(const size_t cpuid,
95  const lvid_type vid,
96  const message_type& message) {
97  schedule(vid, message);
98  }
99 
100 
101  /**
102  * Schedule the message to be received by all vertices in the
103  * graph.
104  */
105  virtual void schedule_all(const message_type& message,
106  const std::string& order = "sequential") = 0;
107 
108 
109  /**
110  * This function is called by the engine to ask for the next
111  * message to process. The message and receiving vertex are
112  * returned in ret_msg and ret_vid respectively.
113  *
114  * \retval NEWTASK There is a new message to process
115  * \retval EMPTY There are no messages to process
116  */
118  get_next(const size_t cpuid, lvid_type& ret_vid,
119  message_type& ret_msg) = 0;
120 
121 
122  /**
123  * Get a message for a specific vertex.
124  */
126  get_specific(lvid_type vid, message_type& ret_msg) {
127  return sched_status::EMPTY;
128  }
129 
130 
131  /**
132  * Inserts a message for vertex vid to be maintained, but do not
133  * update the schedule.
134  *
135  */
136  virtual void place(lvid_type vid, const message_type& msg) = 0;
137 
138 
139  /**
140  * Schedules vertex vid using the stored message that was
141  * previously placed using place.
142  */
143  virtual void
144  schedule_from_execution_thread(const size_t cpuid, lvid_type vid) = 0;
145 
146  /**
147  * Schedules vertex vid using the stored message that was previously
148  * placed using place.
149  */
150  virtual void schedule(lvid_type vid) { }
151 
152 
153  /**
154  * This is called after a message has been received.
155  */
156  virtual void completed(const size_t cpuid,
157  const lvid_type vid,
158  const message_type& message) { }
159 
160 
161  /**
162  * Optional to implement. Count the number of message combination
163  * operations performed. Returns (size_t)(-1) if not available.
164  */
165  virtual size_t num_joins() const { return (size_t)(-1);}
166 
167  /**
168  * Print a help string describing the options that this scheduler
169  * accepts.
170  */
171  static void print_options_help(std::ostream& out) { };
172 
173  };
174 
175 }
176 #endif
177