GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
scheduler_factory.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 #ifndef GRAPHLAB_SCHEDULER_FACTORY_HPP
25 #define GRAPHLAB_SCHEDULER_FACTORY_HPP
26 
27 #include <string>
28 
29 // Schedulers
30 #include <graphlab/options/graphlab_options.hpp>
31 #include <graphlab/scheduler/scheduler_list.hpp>
32 
33 #include <boost/preprocessor.hpp>
34 
35 
36 namespace graphlab {
37 
38 
39  /**
40  * helper for constructing graphlab engines.
41  **/
42  template<typename Message>
44  typedef Message message_type;
46 
47  /**
48  * Construct the a scheduler
49  */
50  template<typename Scheduler>
51  static ischeduler_type*
52  new_scheduler_impl(size_t num_vertices, const graphlab_options& opts) {
53  ischeduler_type* scheduler_ptr =
54  new Scheduler(num_vertices, opts);
55  ASSERT_TRUE(scheduler_ptr != NULL);
56  return scheduler_ptr;
57  } // end of new_scheduler
58 
59  /**
60  * This function returns a new scheduler for a particular engine
61  */
62  static ischeduler_type*
63  new_scheduler(size_t num_vertices, const graphlab_options& opts) {
64  std::string scheduler_str = opts.get_scheduler_type();
65 #define __GENERATE_NEW_SCHEDULER__(r_unused, data_unused, i, elem) \
66  BOOST_PP_EXPR_IF(i, else) \
67  if (scheduler_str == BOOST_PP_TUPLE_ELEM(3,0,elem)) { \
68  typedef BOOST_PP_TUPLE_ELEM(3,1,elem)<Message> \
69  scheduler_type; \
70  return new_scheduler_impl<scheduler_type> \
71  ( num_vertices, opts); \
72  }
73  // generate the construction calls
74  BOOST_PP_SEQ_FOR_EACH_I(__GENERATE_NEW_SCHEDULER__, _, __SCHEDULER_LIST__);
75 #undef __GENERATE_NEW_SCHEDULER__
76  logstream(LOG_FATAL)
77  << "Invalid scheduler type: " << scheduler_str << std::endl;
78  return NULL;
79  } // end of new_scheduler
80 
81  }; // end of class scheduler_factory
82 
83 }; // End of namespace graphlab
84 
85 
86 
87 
88 #endif
89