diff --git a/example_apps/convert_to_adjacency.cpp b/example_apps/convert_to_adjacency.cpp new file mode 100644 index 00000000..93fe95ee --- /dev/null +++ b/example_apps/convert_to_adjacency.cpp @@ -0,0 +1,114 @@ + +/** + * @file + * @author Aapo Kyrola + * @version 1.0 + * + * @section LICENSE + * + * Copyright [2012] [Aapo Kyrola, Guy Blelloch, Carlos Guestrin / Carnegie Mellon University] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + + * + * @section DESCRIPTION + * + * Simple program that writes a graph into adjacency list + */ + +#include + +#include "graphchi_basic_includes.hpp" + +using namespace graphchi; + +/** + * Type definitions. Remember to create suitable graph shards using the + * Sharder-program. + */ +typedef bool VertexDataType; +typedef bool EdgeDataType; + +FILE * f; + +struct AdjConverter : public GraphChiProgram { + + + /** + * Vertex update function. + */ + void update(graphchi_vertex &vertex, graphchi_context &gcontext) { + if (vertex.id() % 10000 == 0) std::cout << vertex.id() << std::endl; + fprintf(f, "%d %d", vertex.id(), vertex.num_outedges()); + for(int i=0; ivertex_id()); + fprintf(f, "\n"); + } + + /** + * Called before an iteration starts. + */ + void before_iteration(int iteration, graphchi_context &gcontext) { + } + + /** + * Called after an iteration has finished. + */ + void after_iteration(int iteration, graphchi_context &gcontext) { + } + + /** + * Called before an execution interval is started. + */ + void before_exec_interval(vid_t window_st, vid_t window_en, graphchi_context &gcontext) { + } + + /** + * Called after an execution interval has finished. + */ + void after_exec_interval(vid_t window_st, vid_t window_en, graphchi_context &gcontext) { + } + +}; + +int main(int argc, const char ** argv) { + /* GraphChi initialization will read the command line + arguments and the configuration file. */ + graphchi_init(argc, argv); + + /* Metrics object for keeping track of performance counters + and other information. Currently required. */ + metrics m("adjconverter"); + + /* Basic arguments for application */ + std::string filename = get_option_string("file"); // Base filename + + /* Detect the number of shards or preprocess an input to create them */ + int nshards = convert_if_notexists(filename, + get_option_string("nshards", "auto")); + + std::string outfile = filename + ".adj"; + f = fopen(outfile.c_str(), "w"); + + /* Run */ + AdjConverter program; + graphchi_engine engine(filename, nshards, false, m); + engine.set_exec_threads(1); + engine.run(program, 1); + + fclose(f); + + /* Report execution metrics */ + metrics_report(m); + return 0; +}