FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
graph_config.h
1 #ifndef __GRAPH_CONFIG_H__
2 #define __GRAPH_CONFIG_H__
3 
4 /*
5  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of FlashGraph.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include <limits>
24 
25 #include "log.h"
26 #include "config_map.h"
27 #include "graph_exception.h"
28 
29 namespace fg
30 {
31 
36 {
37  int num_threads;
38  std::string prof_file;
39  std::string trace_file;
40  int max_processing_vertices;
41  bool enable_elevator;
42  int part_range_size_log;
43  bool _preload;
44  int index_file_weight;
45  bool _in_mem_index;
46  bool _in_mem_graph;
47  int num_vparts;
48  int min_vpart_degree;
49  bool serial_run;
50  // in pages.
51  int vertex_merge_gap;
52 public:
58  num_threads = 4;
59  max_processing_vertices = 2000;
60  enable_elevator = false;
61  part_range_size_log = 10;
62  _preload = false;
63  index_file_weight = 10;
64  _in_mem_index = false;
65  _in_mem_graph = false;
66  num_vparts = 1;
67  min_vpart_degree = std::numeric_limits<int>::max();
68  serial_run = false;
69  // When the gap is 0, it means two vertices either in the same page
70  // or two adjacent pages.
71  vertex_merge_gap = 0;
72  }
73 
77  void print_help();
81  void print();
82 
86  void init(config_map::ptr map);
87 
92  const std::string &get_prof_file() const {
93  return prof_file;
94  }
95 
100  int get_num_threads() const {
101  return num_threads;
102  }
103 
109  bool get_elevator_enabled() const {
110  return enable_elevator;
111  }
112 
118  const std::string &get_trace_file() const {
119  return trace_file;
120  }
121 
128  return max_processing_vertices;
129  }
130 
136  return part_range_size_log;
137  }
138 
143  bool preload() const {
144  return _preload;
145  }
146 
154  int get_index_file_weight() const {
155  return index_file_weight;
156  }
157 
162  bool use_in_mem_index() const {
163  return _in_mem_index;
164  }
165 
171  bool use_in_mem_graph() const {
172  return _in_mem_graph;
173  }
174 
179  bool use_serial_run() const {
180  return serial_run;
181  }
182 
187  int get_num_vparts() const {
188  return num_vparts;
189  }
190 
195  int get_min_vpart_degree() const {
196  return min_vpart_degree;
197  }
198 
206  int get_vertex_merge_gap() const {
207  return vertex_merge_gap;
208  }
209 };
210 
212 {
213  printf("Configuration parameters in graph algorithm.\n");
214  printf("\tthreads: the number of threads processing the graph\n");
215  printf("\tprof_file: the output file containing CPU profiling\n");
216  printf("\ttrace_file: log IO requests\n");
217  printf("\tmax_processing_vertices: the max number of vertices being processed\n");
218  printf("\tenable_elevator: enable the elevator algorithm for scheduling vertices\n");
219  printf("\tpart_range_size_log: the log2 of the range size in range partitioning\n");
220  printf("\tpreload: preload the graph data to the page cache\n");
221  printf("\tindex_file_weight: the weight for the graph index file\n");
222  printf("\tin_mem_index: indicate whether to use in-mem vertex index\n");
223  printf("\tin_mem_graph: indicate whether to load the entire graph to memory in advance\n");
224  printf("\tnum_vparts: the number of vertical partitions\n");
225  printf("\tmin_vpart_degree: the min degree of a vertex to perform vertical partitioning\n");
226  printf("\tserial_run: run the user code on a vertex in serial\n");
227  printf("\tvertex_merge_gap: the gap size allowed when merging two vertex requests\n");
228 }
229 
230 inline void graph_config::print()
231 {
232  BOOST_LOG_TRIVIAL(info) << "Configuration parameters in graph algorithm.";
233  BOOST_LOG_TRIVIAL(info) << "\tthreads: " << num_threads;
234  BOOST_LOG_TRIVIAL(info) << "\tprof_file: " << prof_file;
235  BOOST_LOG_TRIVIAL(info) << "\ttrace_file: " << trace_file;
236  BOOST_LOG_TRIVIAL(info) << "\tmax_processing_vertices: " << max_processing_vertices;
237  BOOST_LOG_TRIVIAL(info) << "\tenable_elevator: " << enable_elevator;
238  BOOST_LOG_TRIVIAL(info) << "\tpart_range_size_log: " << part_range_size_log;
239  BOOST_LOG_TRIVIAL(info) << "\tpreload: " << _preload;
240  BOOST_LOG_TRIVIAL(info) << "\tindex_file_weight: " << index_file_weight;
241  BOOST_LOG_TRIVIAL(info) << "\tin_mem_index: " << _in_mem_index;
242  BOOST_LOG_TRIVIAL(info) << "\tin_mem_graph: " << _in_mem_graph;
243  BOOST_LOG_TRIVIAL(info) << "\tnum_vparts: " << num_vparts;
244  BOOST_LOG_TRIVIAL(info) << "\tmin_vpart_degree: " << min_vpart_degree;
245  BOOST_LOG_TRIVIAL(info) << "\tserial_run: " << serial_run;
246  BOOST_LOG_TRIVIAL(info) << "\tvertex_merge_gap: " << vertex_merge_gap;
247 }
248 
249 inline void graph_config::init(config_map::ptr map)
250 {
251  map->read_option_int("threads", num_threads);
252  if (!power2(num_threads))
253  throw conf_exception("The number of worker threads has to be 2^n");
254  map->read_option("prof_file", prof_file);
255  map->read_option("trace_file", trace_file);
256  map->read_option_int("max_processing_vertices", max_processing_vertices);
257  map->read_option_bool("enable_elevator", enable_elevator);
258  map->read_option_int("part_range_size_log", part_range_size_log);
259  map->read_option_bool("preload", _preload);
260  map->read_option_int("index_file_weight", index_file_weight);
261  map->read_option_bool("in_mem_index", _in_mem_index);
262  map->read_option_bool("in_mem_graph", _in_mem_graph);
263  map->read_option_int("num_vparts", num_vparts);
264  map->read_option_int("min_vpart_degree", min_vpart_degree);
265  map->read_option_bool("serial_run", serial_run);
266  map->read_option_int("vertex_merge_gap", vertex_merge_gap);
267 }
268 
269 extern graph_config graph_conf;
270 
271 }
272 
273 #endif
int get_max_processing_vertices() const
Get the maximal number of vertices being processed by a worker thread.
Definition: graph_config.h:127
const std::string & get_trace_file() const
Get the I/O trace file that records all I/O requests generated by the graph engine.
Definition: graph_config.h:118
int get_min_vpart_degree() const
Get the min degree of a vertex to perform vertical partitioning.
Definition: graph_config.h:195
int get_vertex_merge_gap() const
Get the size of a gap that is allowed when merging two vertex requests. When the gap is 0...
Definition: graph_config.h:206
const std::string & get_prof_file() const
Get the output file containing CPU profiling.
Definition: graph_config.h:92
bool preload() const
Determine whether to preload the graph data to the page cache.
Definition: graph_config.h:143
bool get_elevator_enabled() const
Determine whehter to use the elevator algorithm in accessing the adjacency lists of vertices from SSD...
Definition: graph_config.h:109
void print()
Print the current values of all configurations.
Definition: graph_config.h:230
void print_help()
Print the explanations of all configurations.
Definition: graph_config.h:211
int get_num_threads() const
Get the number of worker threads used by the graph engine.
Definition: graph_config.h:100
void init(config_map::ptr map)
Set the configurations to the user-defined values.
Definition: graph_config.h:249
bool use_in_mem_index() const
Determine whether to use in-mem vertex index.
Definition: graph_config.h:162
int get_part_range_size_log() const
Get the size of a partition range at log scale.
Definition: graph_config.h:135
bool use_in_mem_graph() const
Determine whether to use in-mem graph data.
Definition: graph_config.h:171
bool use_serial_run() const
Determine whether to run the user code on a vertex in serial.
Definition: graph_config.h:179
graph_config()
The default constructor that set all configurations to their default values.
Definition: graph_config.h:57
int get_num_vparts() const
Get the number of vertical partitions.
Definition: graph_config.h:187
int get_index_file_weight() const
Get the weight for graph index file. A SAFS file has weight that is used in the page cache...
Definition: graph_config.h:154
Definition: graph_config.h:35