├── src ├── graphlab │ ├── engine │ │ ├── CMakeLists.txt │ │ ├── engine_includes.hpp │ │ └── engine_options.hpp │ ├── graph │ │ ├── CMakeLists.txt │ │ └── graph_includes.hpp │ ├── scope │ │ ├── CMakeLists.txt │ │ ├── scope_includes.hpp │ │ ├── iscope_factory.hpp │ │ ├── synchronous_scope_factory.hpp │ │ ├── general_scope.hpp │ │ └── synchronous_scope.hpp │ ├── tasks │ │ ├── CMakeLists.txt │ │ ├── task_includes.hpp │ │ └── update_task.hpp │ ├── util │ │ ├── generics │ │ │ ├── CMakeLists.txt │ │ │ ├── float_selector.hpp │ │ │ └── any.cpp │ │ ├── CMakeLists.txt │ │ ├── system_usage.hpp │ │ ├── hash_functions.hpp │ │ ├── util_includes.hpp │ │ ├── command_line_options.cpp │ │ ├── synchronized_queue.hpp │ │ ├── random.hpp │ │ ├── timer.hpp │ │ ├── judy_util.hpp │ │ ├── timer.cpp │ │ ├── binary_parser.hpp │ │ ├── task_count_termination.hpp │ │ ├── par_transform.hpp │ │ ├── synchronized_circular_queue.hpp │ │ ├── prioritized_multiqueue.hpp │ │ ├── optimal_termination.hpp │ │ ├── synchronized_multiqueue.hpp │ │ └── synchronized_unordered_map.hpp │ ├── parallel │ │ ├── CMakeLists.txt │ │ ├── parallel_includes.hpp │ │ └── atomic.hpp │ ├── serialization │ │ ├── CMakeLists.txt │ │ ├── serialize.hpp │ │ ├── serialization_includes.hpp │ │ ├── set.hpp │ │ ├── vector.hpp │ │ ├── map.hpp │ │ ├── list.hpp │ │ ├── judy_map_kdcell.hpp │ │ ├── unsupported_serialize.hpp │ │ ├── iterator.hpp │ │ ├── oarchive.cpp │ │ └── iarchive.cpp │ ├── shared_data │ │ ├── CMakeLists.txt │ │ ├── shared_data_includes.hpp │ │ ├── ishared_data.hpp │ │ └── ishared_data_manager.hpp │ ├── logger │ │ ├── CMakeLists.txt │ │ └── logger_includes.hpp │ ├── monitoring │ │ ├── CMakeLists.txt │ │ ├── monitoring_includes.hpp │ │ ├── console_monitor.hpp │ │ └── imonitor.hpp │ ├── schedulers │ │ ├── set_scheduler │ │ │ ├── CMakeLists.txt │ │ │ ├── ivertex_set.cpp │ │ │ ├── set_scheduler.cpp │ │ │ └── set_generic_typedefs.hpp │ │ ├── CMakeLists.txt │ │ ├── scheduler_includes.hpp │ │ ├── support │ │ │ ├── binary_scheduler_callback.hpp │ │ │ ├── unused_scheduler_callback.hpp │ │ │ ├── direct_callback.hpp │ │ │ └── binary_vertex_task_set.hpp │ │ └── icallback.hpp │ ├── extern │ │ ├── CMakeLists.txt │ │ ├── metis │ │ │ ├── metis.hpp │ │ │ ├── GKlib │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── omp.c │ │ │ │ ├── gk_externs.h │ │ │ │ ├── gk_defs.h │ │ │ │ ├── timers.c │ │ │ │ ├── gk_types.h │ │ │ │ ├── GKlib.h │ │ │ │ ├── gk_arch.h │ │ │ │ ├── io.c │ │ │ │ ├── tokenizer.c │ │ │ │ ├── dfkvkselect.c │ │ │ │ ├── gk_getopt.h │ │ │ │ ├── util.c │ │ │ │ ├── b64.c │ │ │ │ └── gk_memory.h │ │ │ ├── libmetis │ │ │ │ ├── stdheaders.h │ │ │ │ ├── Makefile │ │ │ │ ├── metislib.h │ │ │ │ ├── bucketsort.c │ │ │ │ ├── mrefine2.c │ │ │ │ ├── macros.h │ │ │ │ ├── myqsort.c │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── timing.c │ │ │ │ ├── coarsen.c │ │ │ │ ├── mcoarsen.c │ │ │ │ ├── mutil.c │ │ │ │ ├── mrkmetis.c │ │ │ │ ├── checkgraph.c │ │ │ │ └── util.c │ │ │ ├── LICENSE │ │ │ └── CMakeLists.txt │ │ └── bitmagic │ │ │ ├── bmundef.h │ │ │ ├── bmalgo.h │ │ │ ├── bmfwd.h │ │ │ └── bmgamma.h │ ├── distributed │ │ ├── distributed_includes.hpp │ │ ├── distributed_control_types.hpp │ │ ├── dc_internal.hpp │ │ ├── metrics │ │ │ ├── distributed_metrics.cpp │ │ │ └── distributed_metrics.hpp │ │ ├── dc_packet_headers.hpp │ │ ├── dc_internal.cpp │ │ ├── distributed_terminator.hpp │ │ └── distributed_scope.hpp │ ├── factors │ │ ├── factor_includes.hpp │ │ ├── table_factor.cpp │ │ ├── unary_factor.cpp │ │ └── binary_factor.cpp │ ├── version.hpp │ ├── macros_undef.hpp │ ├── CMakeLists.txt │ └── macros_def.hpp └── CMakeLists.txt ├── apps ├── demo │ └── CMakeLists.txt ├── svm │ ├── CMakeLists.txt │ ├── wbgradient.m │ └── subgradientsvm.m ├── shooting │ ├── CMakeLists.txt │ └── shooting.m ├── gabp │ └── CMakeLists.txt ├── image_denoise │ └── CMakeLists.txt ├── pagerank │ ├── CMakeLists.txt │ ├── pagerankmex.cpp │ └── pagerankapp.hpp ├── factor_graph_inference │ ├── CMakeLists.txt │ └── alchemy_to_bp_parser.cpp └── CMakeLists.txt ├── cleanup ├── cmake ├── Mex_stub.cpp ├── mex_link.sh └── FindMatlab.cmake ├── configure └── LICENSE.txt /src/graphlab/engine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | -------------------------------------------------------------------------------- /src/graphlab/graph/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | -------------------------------------------------------------------------------- /src/graphlab/scope/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | -------------------------------------------------------------------------------- /src/graphlab/tasks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | -------------------------------------------------------------------------------- /src/graphlab/util/generics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | -------------------------------------------------------------------------------- /src/graphlab/parallel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/graphlab/serialization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | -------------------------------------------------------------------------------- /src/graphlab/shared_data/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | subdirs(graphlab) 4 | 5 | -------------------------------------------------------------------------------- /src/graphlab/logger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/graphlab/monitoring/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/set_scheduler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | -------------------------------------------------------------------------------- /src/graphlab/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | subdirs(generics) 4 | 5 | -------------------------------------------------------------------------------- /apps/demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | add_executable(demo demo.cpp) 4 | 5 | -------------------------------------------------------------------------------- /apps/svm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | 4 | 5 | add_executable(svm svm.cpp) 6 | -------------------------------------------------------------------------------- /src/graphlab/extern/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | subdirs(metis bitmagic) 4 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | subdirs(set_scheduler) 4 | -------------------------------------------------------------------------------- /src/graphlab/tasks/task_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | -------------------------------------------------------------------------------- /src/graphlab/graph/graph_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /apps/shooting/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | 4 | 5 | add_executable(shooting shooting.cpp) 6 | -------------------------------------------------------------------------------- /src/graphlab/distributed/distributed_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | -------------------------------------------------------------------------------- /src/graphlab/logger/logger_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | -------------------------------------------------------------------------------- /src/graphlab/parallel/parallel_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | // #include 3 | // #include 4 | -------------------------------------------------------------------------------- /src/graphlab/factors/factor_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | -------------------------------------------------------------------------------- /apps/gabp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | 4 | add_executable(GABP gabp.cpp) 5 | 6 | 7 | #add_executable(BlockGABP gabp_block.cpp) 8 | 9 | #target_link_libraries(BlockGABP itpp) 10 | -------------------------------------------------------------------------------- /src/graphlab/monitoring/monitoring_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/metis.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METIS_HPP 2 | #define METIS_HPP 3 | 4 | namespace metis { 5 | 6 | // extern "C" { 7 | #include 8 | // } 9 | 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /apps/image_denoise/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | project(GraphLab) 3 | 4 | 5 | add_executable(loopybp_denoise loopybp_denoise.cpp) 6 | 7 | 8 | add_executable(gibbs_denoise gibbs_denoise.cpp) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/graphlab/serialization/serialize.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SERIALIZE_HPP 2 | #define GRAPHLAB_SERIALIZE_HPP 3 | #include 4 | #include 5 | #endif //PRL_SERIALIZE_HPP 6 | -------------------------------------------------------------------------------- /apps/pagerank/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | 4 | add_executable(pagerank pagerank.cpp) 5 | #add_executable(tsv_to_graphlab_bin tsv_to_graphlab_bin.cpp) 6 | 7 | 8 | 9 | 10 | #add_mex_library(pagerankmex pagerankapp.cpp pagerankmex.cpp) 11 | -------------------------------------------------------------------------------- /src/graphlab/util/system_usage.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SYSTEM_USAGE_HPP 2 | #define GRAPHLAB_SYSTEM_USAGE_HPP 3 | 4 | 5 | 6 | 7 | #include 8 | 9 | 10 | namespace graphlab { 11 | 12 | 13 | 14 | 15 | 16 | }; 17 | 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/graphlab/version.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_VERSION_HPP 2 | #define GRAPHLAB_VERSION_HPP 3 | 4 | #define GRAPHLAB_VERSION "1_0_0" 5 | 6 | #define GRAPHLAB_VERSION_MAJOR 1 7 | #define GRAPHLAB_VERSION_MINOR 0 8 | #define GRAPHLAB_VERSION_REVISION 0 9 | 10 | #endif -------------------------------------------------------------------------------- /src/graphlab/factors/table_factor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | std::ostream& operator<<(std::ostream& out, const graphlab::variable& var) { 5 | return out << "v_" << var.id 6 | << " in {0:" << var.arity-1 << "}"; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /apps/svm/wbgradient.m: -------------------------------------------------------------------------------- 1 | function [dw,db] = wbgradient(x,y,w,b,C) 2 | alpha = y*(x * w - b); 3 | if (alpha < 1) 4 | alpha = -1; 5 | elseif (alpha >= 1) 6 | alpha = 0; 7 | end 8 | %alpha 9 | dw = w + C*y*alpha*x'; 10 | db = - C*y*alpha; 11 | end -------------------------------------------------------------------------------- /apps/factor_graph_inference/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | 4 | add_executable(alchemy_to_bp_parser alchemy_to_bp_parser.cpp) 5 | 6 | add_executable(factor_bp factor_bp.cpp) 7 | 8 | add_executable(factor_gibbs factor_gibbs.cpp) 9 | 10 | add_executable(belief_diff belief_diff.cpp) 11 | -------------------------------------------------------------------------------- /src/graphlab/distributed/distributed_control_types.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DISTRIBUTED_CONTROL_TYPES_HPP 2 | #define DISTRIBUTED_CONTROL_TYPES_HPP 3 | namespace graphlab { 4 | class distributed_control; 5 | typedef uint16_t procid_t; 6 | typedef uint64_t handlerarg_t; 7 | typedef int sockfd_t; 8 | }; 9 | #endif -------------------------------------------------------------------------------- /src/graphlab/util/hash_functions.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_HASH_FUNCTIONS_HPP 2 | #define GRAPHLAB_HASH_FUNCTIONS_HPP 3 | 4 | namespace graphlab { 5 | class identity_hash{ 6 | public: 7 | size_t operator()(const size_t &t) const{ 8 | return t; 9 | } 10 | }; 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /src/graphlab/shared_data/shared_data_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/graphlab/engine/engine_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/graphlab/util/util_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/graphlab/serialization/serialization_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | -------------------------------------------------------------------------------- /src/graphlab/distributed/dc_internal.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DC_INTERNAL_HPP 2 | #define DC_INTERNAL_HPP 3 | 4 | #include 5 | 6 | namespace graphlab { 7 | struct dc_thread_local_struct{ 8 | char* sendbuffer; 9 | size_t sendbufferlen; 10 | }; 11 | 12 | dc_thread_local_struct& get_thread_dc_buffer(); 13 | } 14 | 15 | #endif -------------------------------------------------------------------------------- /src/graphlab/macros_undef.hpp: -------------------------------------------------------------------------------- 1 | #ifdef __GNUC__ 2 | #if (GRAPHLAB_MACROS_INC_LEVEL != __INCLUDE_LEVEL__) 3 | #error "A was not paired with a " 4 | #endif 5 | #undef GRAPHLAB_MACROS_INC_LEVEL 6 | #endif 7 | 8 | 9 | #undef GRAPHLAB_MACROS 10 | #undef DISALLOW_COPY_AND_ASSIGN 11 | #undef foreach 12 | #undef rev_foreach 13 | -------------------------------------------------------------------------------- /src/graphlab/scope/scope_includes.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /apps/svm/subgradientsvm.m: -------------------------------------------------------------------------------- 1 | function [w,b] = subgradientsvm(x,y) 2 | [nd, dim] = size(x); 3 | w=zeros(dim,1); 4 | b = 0; 5 | 6 | for j = 1:10000 7 | stepsize = 1.0/sqrt(j); 8 | for i = 1:nd 9 | [dw,db] = wbgradient(x(i,:),y(i),w,b,1.0); 10 | w = w - stepsize * dw; 11 | b = b - stepsize * db; 12 | end 13 | % pause 14 | end 15 | 16 | end -------------------------------------------------------------------------------- /cleanup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | setterm -background red; 4 | 5 | echo "This script completely erases the release, debug, and profile folders."; 6 | echo "Are you sure you want to continue? (yes or no)" 7 | 8 | read yesorno; 9 | 10 | if [ "$yesorno" == "yes" ]; then 11 | echo "Removing release debug and profile folders"; 12 | rm -rf release debug profile 13 | else 14 | echo "Doing nothing!"; 15 | fi -------------------------------------------------------------------------------- /src/graphlab/factors/unary_factor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::ostream& operator<<(std::ostream& out, 4 | const graphlab::unary_factor& fact) { 5 | out << "Unary Factor(" << fact.arity() << ")" 6 | << std::endl; 7 | for(size_t i = 0; i < fact.arity(); ++i) { 8 | out << fact.logP(i) << " "; 9 | } 10 | out << std::endl; 11 | return out; 12 | } // end of operator<< 13 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | 4 | 5 | add_library(graphlab_GKlib STATIC 6 | b64.c dlmalloc.c getopt.c memory.c pqueue.c string.c util.c 7 | blas.c error.c htable.c omp.c seq.c timers.c 8 | dfkvkselect.c fs.c io.c pdb.c sort.c tokenizer.c 9 | ) 10 | 11 | set_target_properties(graphlab_GKlib PROPERTIES COMPILE_FLAGS "${METIS_BUILD_OPTS}") 12 | 13 | INSTALL(TARGETS graphlab_GKlib DESTINATION lib) 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/graphlab/util/generics/float_selector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FLOAT_SELECTOR_HPP 2 | #define FLOAT_SELECTOR_HPP 3 | 4 | namespace graphlab { 5 | 6 | template 7 | struct float_selector { 8 | // invalid 9 | }; 10 | 11 | 12 | template <> 13 | struct float_selector<4> { 14 | typedef float float_type; 15 | }; 16 | 17 | template <> 18 | struct float_selector<8> { 19 | typedef double float_type; 20 | }; 21 | 22 | template <> 23 | struct float_selector<16> { 24 | typedef long double float_type; 25 | }; 26 | 27 | } 28 | #endif -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/stdheaders.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * stdheaders.h 5 | * 6 | * This file includes all necessary header files 7 | * 8 | * Started 8/27/94 9 | * George 10 | * 11 | * $Id: stdheaders.h,v 1.2 2003/07/25 14:31:45 karypis Exp $ 12 | */ 13 | 14 | 15 | #include 16 | #ifdef __STDC__ 17 | #include 18 | #else 19 | #include 20 | #endif 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | -------------------------------------------------------------------------------- /src/graphlab/factors/binary_factor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::ostream& operator<<(std::ostream& out, 4 | const graphlab::binary_factor& fact) { 5 | out << "Binary Factor(v_" << fact.var1() << " in {1..." 6 | << fact.arity1() << "}, " 7 | << ", v_ " << fact.var2() << " in {1..." 8 | << fact.arity2() << "})" << std::endl; 9 | for(size_t i = 0; i < fact.arity1(); ++i) { 10 | for(size_t j = 0; j < fact.arity2(); ++j) { 11 | out << fact.logP(i,j) << " "; 12 | } 13 | out << std::endl; 14 | } 15 | return out; 16 | } // end of operator<< 17 | -------------------------------------------------------------------------------- /cmake/Mex_stub.cpp: -------------------------------------------------------------------------------- 1 | // Adopted from: http://www.cmake.org/Wiki/images/7/72/Mex_stub.cpp 2 | // and tutorial: http://www.cmake.org/Wiki/CMake:MatlabMex 3 | // on June 9, 2010 (akyrola) 4 | 5 | #include "mex.h" 6 | 7 | 8 | extern void __mexFunction__(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]); 9 | extern void __at_exit__(); 10 | 11 | static void at_exit(); 12 | 13 | void mexFunction(int nlhs, mxArray *plhs[], 14 | int nrhs, const mxArray *prhs[]) 15 | { 16 | 17 | mexAtExit(&at_exit); 18 | 19 | __mexFunction__(nlhs, plhs, nrhs, prhs); 20 | 21 | } 22 | 23 | static void at_exit() 24 | { 25 | __at_exit__(); 26 | } 27 | -------------------------------------------------------------------------------- /src/graphlab/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | subdirs( 4 | engine 5 | graph 6 | logger 7 | monitoring 8 | parallel 9 | schedulers 10 | serialization 11 | scope 12 | shared_data 13 | tasks 14 | util 15 | extern) 16 | 17 | 18 | add_library(graphlab STATIC 19 | logger/logger.cpp 20 | factors/table_factor.cpp 21 | factors/binary_factor.cpp 22 | factors/unary_factor.cpp 23 | parallel/pthread_tools.cpp 24 | serialization/iarchive.cpp 25 | serialization/oarchive.cpp 26 | util/timer.cpp 27 | util/generics/any.cpp 28 | util/command_line_options.cpp) 29 | 30 | 31 | 32 | target_link_libraries(graphlab graphlab_metis) 33 | 34 | 35 | INSTALL(TARGETS graphlab ARCHIVE DESTINATION lib) 36 | 37 | 38 | -------------------------------------------------------------------------------- /apps/pagerank/pagerankmex.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "mex.h" 4 | #include "pagerankapp.hpp" 5 | 6 | 7 | void __mexFunction__( int nlhs, mxArray *plhs[], 8 | int nrhs, const mxArray*prhs[] ) { 9 | if (nlhs != 1) { 10 | mexErrMsgTxt("You need one output argument"); 11 | } 12 | 13 | if (nrhs != 2) { 14 | mexErrMsgTxt("You need two input args!!"); 15 | } 16 | 17 | std::string filename = "/mnt/bigbrofs/usr5/graphlab/testdata/pagerank/p2p-Gnutella08.txt"; 18 | pagerankapp app(filename, "", false); 19 | 20 | int argc = 0; 21 | char *argv[1]; 22 | argv[0] = "pagerankapp"; 23 | 24 | app.parse_args(argc, argv); 25 | app.start(); 26 | } 27 | 28 | void __at_exit__() { 29 | 30 | } -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | install_directory="/usr/local" 5 | 6 | reldir="./release" 7 | debugdir="./debug" 8 | profiledir="./profile" 9 | 10 | if [ ! -d $reldir ]; then 11 | mkdir $reldir 12 | fi 13 | 14 | if [ ! -d $debugdir ]; then 15 | mkdir $debugdir 16 | fi 17 | 18 | if [ ! -d $profiledir ]; then 19 | mkdir $profiledir 20 | fi 21 | 22 | cd $reldir 23 | cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=$install_directory ../. 24 | cd .. 25 | 26 | cd $debugdir 27 | cmake -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX=$install_directory ../. 28 | cd .. 29 | 30 | cd $profiledir 31 | cmake -D CMAKE_BUILD_TYPE=Release -D COMPILE_PROFILING=1 -D CMAKE_INSTALL_PREFIX=$install_directory ../. 32 | cd .. 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/omp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * omp.c 5 | * 6 | * This file contains "fake" implementations of OpenMP's runtime libraries 7 | * 8 | */ 9 | 10 | #include 11 | 12 | #if !defined(__OPENMP__) 13 | void omp_set_num_threads(int num_threads) { return; } 14 | int omp_get_num_threads(void) { return 1; } 15 | int omp_get_max_threads(void) { return 1; } 16 | int omp_get_thread_num(void) { return 1; } 17 | int omp_get_num_procs(void) { return 1; } 18 | int omp_in_parallel(void) { return 0; } 19 | void omp_set_dynamic(int num_threads) { return; } 20 | int omp_get_dynamic(void) { return 0; } 21 | void omp_set_nested(int nested) { return; } 22 | int omp_get_nested(void) { return 0; } 23 | #endif 24 | 25 | 26 | -------------------------------------------------------------------------------- /cmake/mex_link.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | OUTPUT=$1 4 | STATIC_LIB_NAME=$OUTPUT 5 | MOVE_LOCATION=$2 6 | BASEDIR=$3 7 | LINKFILES=$4 8 | LINKER_FLAGS= -shared -Wl,--version-script,/afs/cs.cmu.edu/misc/matlab/amd64_f7/7.9/lib/matlab7/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined 9 | 10 | echo $OUTPUT 11 | echo $STATIC_LIB_NAME 12 | 13 | 14 | 15 | echo 'Running godawful mex linking hack...' 16 | # mex_stub.o compiled with: 17 | g++ -g -Wall -fPIC -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -DMATLAB_MEX_FILE -lmx -lmex -lmat -lm -I/afs/cs.cmu.edu/local/matlab/amd64_f7/7.9/lib/matlab7/extern/include -c ${BASEDIR}/cmake/Mex_stub.cpp -o mex_stub.o 18 | mex -g -cxx CC='gcc' CXX='g++' LD='g++' -L./ -lglib-2.0 -l$STATIC_LIB_NAME $LINKER_FLAGS -output $OUTPUT mex_stub.o $LINKFILES 19 | #mv $OUTPUT.mexa64 $MOVE_LOCATION 20 | 21 | #-lpthread -lgthread-2.0 -lrt -DMX_COMPAT_32 -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/gk_externs.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_externs.h 3 | \brief This file contains definitions of external variables created by GKlib 4 | 5 | \date Started 3/27/2007 6 | \author George 7 | \version\verbatim $Id: gk_externs.h 1277 2007-03-27 21:17:33Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_EXTERNS_H_ 11 | #define _GK_EXTERNS_H_ 12 | 13 | #include 14 | 15 | /************************************************************************* 16 | * Extern variable definition. Hopefully, the __thread makes them thread-safe. 17 | **************************************************************************/ 18 | #ifndef _GK_ERROR_C_ 19 | 20 | #ifdef __linux__ 21 | extern __thread jmp_buf gk_return_to_entry; /* declared in error.c */ 22 | #else 23 | extern jmp_buf gk_return_to_entry; /* declared in error.c */ 24 | #endif 25 | 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/graphlab/util/command_line_options.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace boost { 4 | template<> 5 | std::string lexical_cast(const std::vector& vec) { 6 | return graphlab_vec_to_string(vec); 7 | } 8 | 9 | template<> 10 | std::string lexical_cast< std::string>(const std::vector& vec) { 11 | return graphlab_vec_to_string(vec); 12 | } 13 | 14 | template<> 15 | std::string lexical_cast< std::string >(const std::vector& vec) { 16 | return graphlab_vec_to_string(vec); 17 | } 18 | 19 | template<> 20 | std::string lexical_cast< std::string>(const std::vector& vec) { 21 | return graphlab_vec_to_string(vec); 22 | } 23 | 24 | template<> 25 | std::string lexical_cast< std::string>(const std::vector& vec) { 26 | return graphlab_vec_to_string(vec); 27 | } 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | #subdirs( 4 | # image_denoise 5 | # factor_graph_inference 6 | # gabp 7 | # pagerank 8 | # svm 9 | # shooting 10 | # demo 11 | #) 12 | 13 | link_libraries(${GraphLab_LIBRARIES}) 14 | 15 | macro(add_all_subdirectories retval curdir) 16 | file(GLOB sub-dir RELATIVE ${curdir} *) 17 | set(list_of_dirs "") 18 | foreach(dir ${sub-dir}) 19 | if(IS_DIRECTORY ${curdir}/${dir}) 20 | STRING(SUBSTRING ${dir} 0 1 firstchar) 21 | if(${firstchar} STREQUAL ".") 22 | else(${firstchar} STREQUAL ".") 23 | set(list_of_dirs ${list_of_dirs} ${dir}) 24 | message(STATUS "Detected apps: " ${dir}) 25 | add_subdirectory(${dir}) 26 | endif() 27 | endif() 28 | endforeach() 29 | set(${retval} ${list_of_dirs}) 30 | endmacro() 31 | 32 | add_all_subdirectories(retval, ${CMAKE_CURRENT_SOURCE_DIR}) 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/graphlab/distributed/metrics/distributed_metrics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace graphlab { 5 | 6 | mutex singletonlock; 7 | 8 | distributed_metrics * distributed_metrics_receive_target = NULL; 9 | 10 | distributed_metrics * distributed_metrics::instance(distributed_control * dc) { 11 | singletonlock.lock(); 12 | if (distributed_metrics_receive_target == NULL) { 13 | distributed_metrics_receive_target = new distributed_metrics(dc); 14 | } 15 | singletonlock.unlock(); 16 | return distributed_metrics_receive_target; 17 | } 18 | 19 | // Remote call 20 | void distributed_metrics::remote_set_value(distributed_control& _dc, size_t source, void *ptr, size_t len, 21 | std::string key, double value) { 22 | instance(&_dc)->set_value(source, key, value); 23 | } 24 | 25 | 26 | } -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.in 2 | 3 | CURBUILDDIR = $(LIBBUILDDIR) 4 | 5 | OBJS = $(patsubst %.c, $(CURBUILDDIR)/%$(OBJEXT), $(wildcard *.c)) 6 | HEADERS = $(wildcard *.h) $(TOPDIR)/include/metis.h $(wildcard $(GKLIBINCDIR)/*.h) 7 | 8 | GKLIBOBJS = $(wildcard $(GKLIBBUILDDIR)/*$(OBJEXT)) 9 | 10 | $(BUILDDIR)/libmetis$(LIBEXT): $(OBJS) $(GKLIBOBJS) 11 | $(AR) $(OBJS) $(GKLIBOBJS) 12 | $(RANLIB) 13 | 14 | clean: 15 | rm -f $(OBJS) 16 | 17 | realclean: 18 | rm -f $(OBJS) ; rm -f $(BUILDDIR)/libmetis$(LIBEXT) 19 | 20 | dist: 21 | mkdir $(TOPDIR)/../$(PKGNAME) ;\ 22 | cp -r $(TOPDIR)/* $(TOPDIR)/../$(PKGNAME) ;\ 23 | tar -C $(TOPDIR)/../ --exclude=.svn -czf $(TOPDIR)/$(PKGNAME).tar.gz $(PKGNAME);\ 24 | rm -rf $(TOPDIR)/../$(PKGNAME) 25 | 26 | $(OBJS) : $(HEADERS) ../Makefile.in Makefile 27 | 28 | 29 | $(CURBUILDDIR)/%$(OBJEXT) : %.c 30 | $(CC) $(CFLAGS) $(SOURCEFILE) $(OUTPUTFILE) 31 | -------------------------------------------------------------------------------- /src/graphlab/serialization/set.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SERIALIZE_SET_HPP 2 | #define GRAPHLAB_SERIALIZE_SET_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace graphlab { 11 | 12 | /** 13 | Serializes a set 14 | Returns true on success, false on failure */ 15 | template 16 | oarchive& operator<<(oarchive& a, const std::set& vec){ 17 | serialize_iterator(a,vec.begin(),vec.end(), vec.size()); 18 | return a; 19 | } 20 | 21 | /** 22 | deserializes a set 23 | Returns true on success, false on failure */ 24 | template 25 | iarchive& operator>>(iarchive& a, std::set& vec){ 26 | vec.clear(); 27 | deserialize_iterator(a, std::inserter(vec,vec.end())); 28 | return a; 29 | } 30 | 31 | } // namespace prl 32 | 33 | #endif //PRL_SERIALIZE_SET_HPP 34 | -------------------------------------------------------------------------------- /src/graphlab/serialization/vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SERIALIZE_VECTOR_HPP 2 | #define GRAPHLAB_SERIALIZE_VECTOR_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | namespace graphlab { 10 | /** 11 | Serializes a vector 12 | Returns true on success, false on failure */ 13 | template 14 | oarchive& operator<<(oarchive& a, const std::vector& vec){ 15 | serialize_iterator(a,vec.begin(), vec.end()); 16 | return a; 17 | } 18 | 19 | /** 20 | deserializes a vector 21 | Returns true on success, false on failure */ 22 | template 23 | iarchive& operator>>(iarchive& a, std::vector& vec){ 24 | vec.clear(); 25 | deserialize_iterator(a, std::inserter(vec, vec.end())); 26 | return a; 27 | } 28 | } // namespace prl 29 | 30 | #endif //PRL_SERIALIZE_VECTOR_HPP 31 | -------------------------------------------------------------------------------- /src/graphlab/util/generics/any.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace graphlab { 4 | 5 | 6 | __any_registration_map_type& __get_registration_map() { 7 | static __any_registration_map_type __any_registration_map; 8 | return __any_registration_map; 9 | } 10 | 11 | __any_placeholder* __any_placeholder::base_load(iarchive &arc) { 12 | uint64_t idload; 13 | arc >> idload; 14 | __any_registration_map_type::iterator i = __get_registration_map().find(idload); 15 | assert(i != __get_registration_map().end()); 16 | return __get_registration_map()[idload](arc); 17 | } 18 | 19 | void __any_placeholder::base_save(oarchive &arc) const { 20 | arc << get_deserializer_id(); 21 | save(arc); 22 | } 23 | 24 | 25 | } // end of namespace graphlab 26 | 27 | 28 | // std::ostream& operator<<(std::ostream& out, const graphlab::any& any) { 29 | // return any.print(out); 30 | // } // end of operator << for any 31 | 32 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/gk_defs.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_defs.h 3 | \brief This file contains various constants definitions 4 | 5 | \date Started 3/27/2007 6 | \author George 7 | \version\verbatim $Id: gk_defs.h 1277 2007-03-27 21:17:33Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_DEFS_H_ 11 | #define _GK_DEFS_H_ 12 | 13 | 14 | #define LTERM (void **) 0 /* List terminator for GKfree() */ 15 | 16 | #define HTABLE_EMPTY -1 17 | #define HTABLE_DELETED -2 18 | #define HTABLE_FIRST 1 19 | #define HTABLE_NEXT 2 20 | 21 | /* pdb corruption bit switches */ 22 | #define CRP_ALTLOCS 1 23 | #define CRP_MISSINGCA 2 24 | #define CRP_MISSINGBB 4 25 | #define CRP_MULTICHAIN 8 26 | #define CRP_MULTICA 16 27 | #define CRP_MULTIBB 32 28 | 29 | #define MAXLINELEN 300000 30 | 31 | /* custom signals */ 32 | #define SIGMEM SIGABRT 33 | #define SIGERR SIGABRT 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/graphlab/serialization/map.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SERIALIZE_MAP_HPP 2 | #define GRAPHLAB_SERIALIZE_MAP_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace graphlab { 11 | 12 | /** Serializes a map 13 | Returns true on success, false on failure */ 14 | template 15 | oarchive& operator<<(oarchive& a, const std::map& vec){ 16 | serialize_iterator(a,vec.begin(),vec.end(), vec.size()); 17 | return a; 18 | } 19 | 20 | /** deserializes a map 21 | Returns true on success, false on failure */ 22 | template 23 | iarchive& operator>>(iarchive& a, std::map& vec){ 24 | vec.clear(); 25 | deserialize_iterator >(a, std::inserter(vec,vec.end())); 26 | return a; 27 | } 28 | } // namespace prl 29 | 30 | #endif //PRL_SERIALIZE_MAP_HPP 31 | -------------------------------------------------------------------------------- /src/graphlab/distributed/dc_packet_headers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DISTRIBUTED_CONTROL_PACKET_HEADERS_HPP 2 | #define DISTRIBUTED_CONTROL_PACKET_HEADERS_HPP 3 | 4 | #include 5 | namespace graphlab { 6 | 7 | enum packet_ids{ 8 | REMOTECALL_ID, REMOTECALLX_ID, REMOTECALLXS_ID, REMOTECALL_CONTROL_ID 9 | }; 10 | 11 | struct remotecall_packdata{ 12 | uint16_t packtype; 13 | procid_t srcnodeid; 14 | void* fnptr; 15 | uint32_t len; 16 | uint32_t numargs; 17 | handlerarg_t args[0]; 18 | }; 19 | 20 | struct remotecallx_packdata{ 21 | uint16_t packtype; 22 | procid_t srcnodeid; 23 | void* fnptr; 24 | uint32_t len; 25 | uint32_t stacklen; 26 | }; 27 | 28 | struct remotecallxs_packdata{ 29 | uint16_t packtype; 30 | procid_t srcnodeid; 31 | void* fnptr; 32 | uint32_t len; 33 | uint32_t stacklen; 34 | }; 35 | 36 | struct fence_packdata{ 37 | uint16_t packtype; 38 | }; 39 | 40 | typedef uint32_t pheaderlen_t; 41 | } 42 | 43 | 44 | #endif -------------------------------------------------------------------------------- /src/graphlab/serialization/list.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SERIALIZE_LIST_HPP 2 | #define GRAPHLAB_SERIALIZE_LIST_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | //TODO: Remove from the graphlab namespace 11 | 12 | namespace graphlab { 13 | 14 | /** Serializes a list 15 | Returns true on success, false on failure */ 16 | template 17 | oarchive& operator<<(oarchive& a, const std::list& vec){ 18 | serialize_iterator(a,vec.begin(), vec.end()); 19 | return a; 20 | } 21 | 22 | /** deserializes a list 23 | Returns true on success, false on failure */ 24 | template 25 | iarchive& operator>>(iarchive& a, std::list& vec){ 26 | vec.clear(); 27 | deserialize_iterator(a, std::inserter(vec, vec.end())); 28 | return a; 29 | } 30 | } // namespace prl 31 | #endif //PRL_SERIALIZE_LIST_HPP 32 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Notice 2 | ---------------- 3 | 4 | The METIS package is copyrighted by the Regents of the University of 5 | Minnesota. It can be freely used for educational and research purposes 6 | by non-profit institutions and US government agencies only. Other 7 | organizations are allowed to use METIS only for evaluation purposes, 8 | and any further uses will require prior approval. The software 9 | may not be sold or redistributed without prior approval. One may 10 | make copies of the software for their use provided that the copies, 11 | are not sold or distributed, are used under the same terms and 12 | conditions. 13 | 14 | As unestablished research software, this code is provided on an 15 | ``as is'' basis without warranty of any kind, either expressed or 16 | implied. The downloading, or executing any part of this software 17 | constitutes an implicit agreement to these terms. These terms and 18 | conditions are subject to change at any time without prior notice. 19 | 20 | 21 | -------------------------------------------------------------------------------- /apps/shooting/shooting.m: -------------------------------------------------------------------------------- 1 | function [w,b] = shooting(x,y, reallambda) 2 | [nd, dim] = size(x); 3 | w=zeros(dim,1); 4 | b = 0; 5 | residuals = y; 6 | lambda = 0.001; 7 | for j = 1:1000 8 | a=randperm(dim); 9 | for i = a 10 | % solve the local squared loss minimization step 11 | % first, my contribution to the 'y's are 12 | localcontribution = w(i) * x(:,i); 13 | % take away my contributions 14 | residuals = residuals + localcontribution; 15 | % solve a local least squares 16 | ix = 1.0 / (x(:,i)' * x(:,i)); % this should be a scaler! 17 | w(i) = ix * x(:,i)' * residuals; 18 | if (w(i) > lambda) 19 | w(i) = w(i) - lambda; 20 | elseif (w(i) < -lambda) 21 | w(i) = w(i) + lambda; 22 | else 23 | w(i) = 0; 24 | end 25 | % compute my new contributions and subtract from the residuals 26 | localcontribution = w(i) * x(:,i); 27 | residuals = residuals - localcontribution; 28 | end 29 | end 30 | 31 | end -------------------------------------------------------------------------------- /apps/factor_graph_inference/alchemy_to_bp_parser.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | 6 | 7 | #include "factor_graph.hpp" 8 | #include "factor_bp.hpp" 9 | 10 | using namespace std; 11 | 12 | int main(int argc, char** argv) { 13 | if(argc != 2) { 14 | cout << "" << endl; 15 | return EXIT_FAILURE; 16 | } 17 | 18 | cout << "Making bp factor graph from alchemy graph." << endl; 19 | gl_types::graph graph; 20 | { // scoping to save some memory 21 | cout << "\t (1/5) Loading file: " << argv[1] << ". " << endl; 22 | factor_graph model; 23 | model.load_alchemy(argv[1]); 24 | cout << "\t (2/5) Rendering BP graphlab graph: " << endl ; 25 | make_bp_graph(model, graph); 26 | } 27 | cout << "\t (3/5) Finalizing graph." << endl; 28 | graph.finalize(); 29 | cout << "\t (4/5) Saving Adjacency file." << endl; 30 | graph.save_adjacency(std::string("adjacency.csv")); 31 | cout << "\t (5/5) Saving graph." << endl; 32 | graph.save("graphlab_bp.bin"); 33 | return EXIT_SUCCESS; 34 | } 35 | -------------------------------------------------------------------------------- /src/graphlab/serialization/judy_map_kdcell.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SERIALIZE_JUDYMAP_KDCELL_HPP 2 | #define GRAPHLAB_SERIALIZE_JUDYMAP_KDCELL_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace graphlab { 11 | 12 | /** Serializes a map 13 | Returns true on success, false on failure */ 14 | template 15 | oarchive& operator<<(oarchive& a, const judy_map_kdcell& vec){ 16 | serialize_iterator(a,vec.begin(),vec.end(), vec.size()); 17 | return a; 18 | } 19 | 20 | /** deserializes a map 21 | Returns true on success, false on failure */ 22 | template 23 | iarchive& operator>>(iarchive& a, judy_map_kdcell& vec){ 24 | vec.clear(); 25 | deserialize_iterator >(a, std::inserter(vec,vec.end())); 26 | return a; 27 | } 28 | } // namespace prl 29 | 30 | #endif //PRL_SERIALIZE_MAP_HPP 31 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/metislib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * metis.h 5 | * 6 | * This file includes all necessary header files 7 | * 8 | * Started 8/27/94 9 | * George 10 | * 11 | * $Id: metislib.h,v 1.1 2002/08/10 06:29:31 karypis Exp $ 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #if defined(ENABLE_OPENMP) 29 | #include 30 | #endif 31 | 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | #if defined(COMPILER_MSC) 43 | #define rint(x) ((idxtype)((x)+0.5)) /* MSC does not have rint() function */ 44 | #endif 45 | 46 | 47 | #if defined(COMPILER_GCC) 48 | //extern char* strdup (const char *); 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /src/graphlab/serialization/unsupported_serialize.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_UNSUPPORTED_SERIALIZE_HPP 2 | #define GRAPHLAB_UNSUPPORTED_SERIALIZE_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace graphlab { 9 | 10 | struct unsupported_serialize { 11 | void save(oarchive& archive) const { 12 | ASSERT_MSG(false, "trying to serialize an unserializable object"); 13 | } 14 | void load(iarchive& archive) { 15 | ASSERT_MSG(false, "trying to deserialize an unserializable object"); 16 | } 17 | }; // end of struct 18 | }; 19 | 20 | #define GRAPHLAB_UNSERIALIZABLE(TNAME) \ 21 | graphlab::oarchive& operator<<(graphlab::oarchive&, \ 22 | const TNAME &mat) {ASSERT_MSG(false,"trying to serialize an unserializable object");} \ 23 | graphlab::iarchive& operator>>(graphlab::iarchive&, \ 24 | TNAME &vec) {ASSERT_MSG(false,"trying to deserialize an unserializable object");} 25 | 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/graphlab/macros_def.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // if GNUC is available, this checks if the file which included 5 | // macros_def.hpp is the same file which included macros_undef.hpp 6 | #ifdef __GNUC__ 7 | #define GRAPHLAB_MACROS_INC_LEVEL __INCLUDE_LEVEL__ 8 | #endif 9 | 10 | 11 | // prevent this file from being included before other graphlab headers 12 | #ifdef GRAPHLAB_MACROS 13 | #error "Repeated include of . This probably means that macros_def.hpp was not the last include, or some header file failed to include " 14 | #endif 15 | 16 | #define GRAPHLAB_MACROS 17 | 18 | /** A macro to disallow the copy constructor and operator= functions 19 | This should be used in the private: declarations for a class */ 20 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 21 | TypeName(const TypeName&); \ 22 | void operator=(const TypeName&); 23 | 24 | 25 | 26 | // Shortcut macro definitions 27 | //! see http://www.boost.org/doc/html/foreach.html 28 | #define foreach BOOST_FOREACH 29 | 30 | #define rev_foreach BOOST_REVERSE_FOREACH 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/graphlab/util/synchronized_queue.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SYNCHRONIZED_QUEUE_HPP 2 | #define GRAPHLAB_SYNCHRONIZED_QUEUE_HPP 3 | 4 | 5 | #include 6 | 7 | #include 8 | namespace graphlab { 9 | 10 | template 11 | class synchronized_queue { 12 | 13 | public: 14 | synchronized_queue() { }; 15 | ~synchronized_queue() { }; 16 | 17 | void push(const T &item) { 18 | _queuelock.lock(); 19 | _queue.push(item); 20 | _queuelock.unlock(); 21 | } 22 | 23 | bool safepop(T * ret) { 24 | _queuelock.lock(); 25 | if (_queue.size() == 0) { 26 | _queuelock.unlock(); 27 | 28 | return false; 29 | } 30 | *ret = _queue.front(); 31 | _queue.pop(); 32 | _queuelock.unlock(); 33 | return true; 34 | } 35 | 36 | T pop() { 37 | _queuelock.lock(); 38 | T t = _queue.front(); 39 | _queue.pop(); 40 | _queuelock.unlock(); 41 | return t; 42 | } 43 | 44 | size_t size() const{ 45 | return _queue.size(); 46 | } 47 | private: 48 | std::queue _queue; 49 | spinlock _queuelock; 50 | }; 51 | 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/bucketsort.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * bucketsort.c 5 | * 6 | * This file contains code that implement a variety of counting sorting 7 | * algorithms 8 | * 9 | * Started 7/25/97 10 | * George 11 | * 12 | */ 13 | 14 | #include 15 | 16 | 17 | 18 | /************************************************************************* 19 | * This function uses simple counting sort to return a permutation array 20 | * corresponding to the sorted order. The keys are agk_fsumed to start from 21 | * 0 and they are positive. This sorting is used during matching. 22 | **************************************************************************/ 23 | void BucketSortKeysInc(idxtype n, idxtype max, idxtype *keys, idxtype *tperm, idxtype *perm) 24 | { 25 | idxtype i, ii; 26 | idxtype *counts; 27 | 28 | counts = idxsmalloc(max+2, 0, "BucketSortKeysInc: counts"); 29 | 30 | for (i=0; i 13 | 14 | 15 | 16 | 17 | /************************************************************************* 18 | * This function returns the CPU seconds 19 | **************************************************************************/ 20 | gk_wclock_t gk_WClockSeconds(void) 21 | { 22 | return time(NULL); 23 | } 24 | 25 | 26 | /************************************************************************* 27 | * This function returns the CPU seconds 28 | **************************************************************************/ 29 | double gk_CPUSeconds(void) 30 | { 31 | #ifdef __OPENMP__ 32 | return omp_get_wtime(); 33 | #else 34 | #ifdef WIN32 35 | return((double) clock()/CLOCKS_PER_SEC); 36 | #else 37 | struct rusage r; 38 | 39 | getrusage(RUSAGE_SELF, &r); 40 | return ((r.ru_utime.tv_sec + r.ru_stime.tv_sec) + 1.0e-6*(r.ru_utime.tv_usec + r.ru_stime.tv_usec)); 41 | #endif 42 | #endif 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/graphlab/util/random.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_RANDOM_HPP 2 | #define GRAPHLAB_RANDOM_HPP 3 | 4 | #include 5 | 6 | namespace graphlab { 7 | 8 | /** 9 | * A collection of thread safe random number routines. Each thread 10 | * is assigned its own generator. 11 | */ 12 | struct random { 13 | 14 | /** 15 | * Generate a thread specific random number between 0 and 1 16 | */ 17 | static double rand01() { 18 | return thread::get_thread_specific_data().rand01(); 19 | } 20 | 21 | /** 22 | * Generate a thread specific random integer between 0 and max inclusive 23 | */ 24 | static size_t rand_int(size_t max) { 25 | return thread::get_thread_specific_data().rand_int(max); 26 | } 27 | 28 | /** 29 | * Seed the random number generator. Note that the engine 30 | * automatically seeds the number generators. 31 | */ 32 | static void seed(size_t value) { 33 | thread::get_thread_specific_data().seed(value); 34 | } 35 | 36 | /** Seed the random number generator with the default seed */ 37 | static void seed() { 38 | thread::get_thread_specific_data().seed(); 39 | } 40 | }; // end of random 41 | } // end of graphlab 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/scheduler_includes.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/set_scheduler/ivertex_set.cpp: -------------------------------------------------------------------------------- 1 | 2 | // #include 3 | // #include 4 | 5 | // namespace graphlab { 6 | 7 | // void ivertex_set::add_event_target(ivertex_set *ev) { 8 | // if (ev != NULL) { 9 | // all_children.push_back(ev); 10 | // } 11 | // } 12 | 13 | 14 | // size_t ivertex_set::all_dependent_events() { 15 | // unsigned char dependentevs = supported_events(); 16 | // for (size_t i = 0; i < all_children.size(); ++i) { 17 | // dependentevs |= all_children[i]->all_dependent_events(); 18 | // } 19 | // return dependentevs; 20 | // } 21 | 22 | // void ivertex_set::resolve_event_handlers() { 23 | // for (size_t i = 0; i < all_children.size(); ++i) { 24 | // ivertex_set *ev = all_children[i]; 25 | // size_t supportevs = ev->all_dependent_events(); 26 | // if (supportevs & INSERT_EVENT) insert_events.push_back(ev); 27 | // if (supportevs & ERASE_EVENT) erase_events.push_back(ev); 28 | // if (supportevs & MODIFY_VERTEX_EVENT) modify_vertex_events.push_back(ev); 29 | // if (supportevs & MODIFY_EDGE_EVENT) modify_edge_events.push_back(ev); 30 | // ev->resolve_event_handlers(); 31 | // } 32 | // } 33 | 34 | // } 35 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GraphLab) 2 | 3 | # if(CMAKE_COMPILER_IS_GNUCXX) 4 | # # metis is so full of warnings 5 | # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -w -DLINUX -std=c99 -D_FILE_OFFSET_BITS=64") 6 | # set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -w -DLINUX -std=c99 -D_FILE_OFFSET_BITS=64") 7 | # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -w -DLINUX -std=c99 -D_FILE_OFFSET_BITS=64") 8 | # set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -w -DLINUX -std=c99 -D_FILE_OFFSET_BITS=64") 9 | # endif(CMAKE_COMPILER_IS_GNUCXX) 10 | # 11 | # IF(APPLE) 12 | # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDARWIN ") 13 | # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDARWIN") 14 | # set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DDARWIN") 15 | # ENDIF(APPLE) 16 | # 17 | 18 | if (CMAKE_BUILD_TYPE MATCHES "Release") 19 | set(METIS_BUILD_OPTS "${CMAKE_C_FLAGS_RELEASE} -w -DLINUX -std=c99 -D_FILE_OFFSET_BITS=64") 20 | elseif(CMAKE_BUILD_TYPE MATCHES "Debug") 21 | set(METIS_BUILD_OPTS "${CMAKE_C_FLAGS_DEBUG} -w -DLINUX -std=c99 -D_FILE_OFFSET_BITS=64") 22 | endif() 23 | 24 | 25 | IF(APPLE) 26 | set(METIS_BUILD_OPTS "${METIS_BUILD_OPTS} -DDARWIN") 27 | ENDIF(APPLE) 28 | 29 | 30 | include_directories( 31 | . 32 | GKlib 33 | libmetis 34 | ) 35 | 36 | 37 | subdirs(GKlib libmetis) 38 | 39 | -------------------------------------------------------------------------------- /src/graphlab/scope/iscope_factory.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | \author Yucheng Low (ylow), Joseph Gonzalez 3 | Interface for Scope Factories 4 | */ 5 | #ifndef GRAPHLAB_ISCOPE_FACTORY_HPP 6 | #define GRAPHLAB_ISCOPE_FACTORY_HPP 7 | 8 | #include 9 | #include 10 | 11 | namespace graphlab { 12 | 13 | 14 | 15 | template 16 | class iscope_factory { 17 | public: 18 | 19 | 20 | 21 | typedef Graph graph_type; 22 | typedef iscope iscope_type; 23 | 24 | /** \note This constructor here does not actually do anything. It just exists 25 | to force the derived class constructors to look like this */ 26 | iscope_factory(Graph& graph, size_t ncpus) {} 27 | 28 | virtual ~iscope_factory() {} 29 | 30 | //! Returns a scope around a particular vertex 31 | virtual iscope_type* get_scope(size_t cpuid, 32 | vertex_id_t vertex, 33 | scope_range::scope_range_enum s = scope_range::USE_DEFAULT) = 0; 34 | 35 | //! Set the default scope type 36 | virtual void set_default_scope(scope_range::scope_range_enum default_scope_range) = 0; 37 | 38 | //! Destroys a scope 39 | virtual void release_scope(iscope* scope) = 0; 40 | 41 | //! Get the number of vertices 42 | virtual size_t num_vertices() const = 0; 43 | 44 | }; 45 | 46 | } 47 | 48 | #include 49 | #endif 50 | -------------------------------------------------------------------------------- /src/graphlab/extern/bitmagic/bmundef.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com) 2 | // 3 | // BM library internal header 4 | // 5 | // Cleaning the BM related preprocessor defines to eliminate the risks of collision 6 | // with other programs. Please let me know if something is missing. 7 | // 8 | 9 | #undef BMCOUNT_INC 10 | #undef BMCOUNT_DEC 11 | #undef BMCOUNT_VALID 12 | #undef BMCOUNT_SET 13 | #undef BMCOUNT_ADJ 14 | #undef BMCOUNT_INC 15 | #undef BMCOUNT_DEC 16 | #undef BMCOUNT_VALID 17 | #undef BMCOUNT_SET 18 | #undef BMCOUNT_ADJ 19 | #undef BMRESTRICT 20 | #undef BMFORCEINLINE 21 | #undef BMGAP_PTR 22 | #undef BMSET_PTRGAP 23 | #undef BM_IS_GAP 24 | #undef BMPTR_SETBIT0 25 | #undef BMPTR_CLEARBIT0 26 | #undef BMPTR_TESTBIT0 27 | #undef BM_SET_MMX_GUARD 28 | #undef SER_NEXT_GRP 29 | #undef BM_SET_ONE_BLOCKS 30 | #undef DECLARE_TEMP_BLOCK 31 | #undef BM_MM_EMPTY 32 | #undef BM_ASSERT 33 | #undef FULL_BLOCK_ADDR 34 | #undef IS_VALID_ADDR 35 | #undef IS_FULL_BLOCK 36 | #undef IS_EMPTY_BLOCK 37 | #undef BM_INCWORD_BITCOUNT 38 | #undef BM_MINISET_GAPLEN 39 | #undef BM_MINISET_ARRSIZE 40 | 41 | #undef BMVECTOPT 42 | #undef VECT_XOR_ARR_2_MASK 43 | #undef VECT_ANDNOT_ARR_2_MASK 44 | #undef VECT_INVERT_ARR 45 | #undef VECT_AND_ARR 46 | #undef VECT_OR_ARR 47 | #undef VECT_SUB_ARR 48 | #undef VECT_XOR_ARR 49 | 50 | #undef VECT_COPY_BLOCK 51 | #undef VECT_SET_BLOCK 52 | 53 | #undef BM_UNALIGNED_ACCESS_OK 54 | #undef BM_ALIGN16 55 | #undef BM_ALIGN16ATTR 56 | #undef BM_x86 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/graphlab/extern/bitmagic/bmalgo.h: -------------------------------------------------------------------------------- 1 | #ifndef BMALGO__H__INCLUDED__ 2 | #define BMALGO__H__INCLUDED__ 3 | /* 4 | Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com) 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the "Software"), to deal in the Software without restriction, 9 | including without limitation the rights to use, copy, modify, merge, 10 | publish, distribute, sublicense, and/or sell copies of the Software, 11 | and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | For more information please visit: http://bmagic.sourceforge.net 26 | 27 | */ 28 | 29 | #include "bm.h" 30 | #include "bmfunc.h" 31 | #include "bmdef.h" 32 | 33 | #include "bmalgo_impl.h" 34 | 35 | #include "bmundef.h" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/gk_types.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_types.h 3 | \brief This file contains basic scalar datatype used in GKlib 4 | 5 | \date Started 3/27/2007 6 | \author George 7 | \version\verbatim $Id: gk_types.h 1413 2007-04-05 02:43:48Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_TYPES_H_ 11 | #define _GK_TYPES_H_ 12 | 13 | /************************************************************************* 14 | * Basic data type definitions. These definitions allow GKlib to separate 15 | * the following elemental types: 16 | * - loop iterator variables, which are set to size_t 17 | * - signed and unsigned int variables that can be set to any # of bits 18 | * - signed and unsigned long variables that can be set to any # of bits 19 | * - real variables, which can be set to single or double precision. 20 | **************************************************************************/ 21 | typedef ptrdiff_t gk_loop_t; /* loop index variable */ 22 | typedef ptrdiff_t gk_idx_t; /* index variable */ 23 | typedef int32_t gk_int_t; /* integer values */ 24 | typedef uint32_t gk_uint_t; /* unsigned integer values */ 25 | typedef int64_t gk_long_t; /* long integer values */ 26 | typedef uint64_t gk_ulong_t; /* unsigned long integer values */ 27 | typedef float gk_real_t; /* real type */ 28 | typedef double gk_dreal_t; /* double precission real type */ 29 | typedef time_t gk_wclock_t; /* wall-clock time */ 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/GKlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GKlib.h 3 | * 4 | * George's library of most frequently used routines 5 | * 6 | * $Id: GKlib.h 1430 2007-04-07 17:53:07Z karypis $ 7 | * 8 | */ 9 | 10 | #ifndef _GKLIB_H_ 11 | #define _GKLIB_H_ 1 12 | 13 | #define GKMSPACE 14 | 15 | #if defined(_MSC_VER) 16 | #define __MSC__ 17 | #endif 18 | #if defined(__ICC) 19 | #define __ICC__ 20 | #endif 21 | #include 22 | 23 | #include /*!< This should be here, prior to the includes */ 24 | 25 | 26 | /************************************************************************* 27 | * Header file inclusion section 28 | **************************************************************************/ 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #if defined(__WITHPCRE__) 46 | #include 47 | #else 48 | #include 49 | #endif 50 | 51 | 52 | #if defined(__OPENMP__) 53 | #include 54 | #endif 55 | 56 | 57 | 58 | 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | 67 | #include 68 | #include 69 | #include 70 | 71 | #include 72 | 73 | #endif /* GKlib.h */ 74 | 75 | 76 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Select Lab, Carnegie Mellon University 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. Redistributions 10 | in binary form must reproduce the above copyright notice, this list of 11 | conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. Neither the name of 13 | the Carnegie Mellon University nor the names of its contributors may be 14 | used to endorse or promote products derived from this software without 15 | specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/support/binary_scheduler_callback.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BINARY_SCHEDULER_CALLBACK_HPP 2 | #define BINARY_SCHEDULER_CALLBACK_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace graphlab { 9 | /** 10 | This is a special callback which only records whether or not 11 | add_tasks was called 12 | */ 13 | template 14 | class binary_scheduler_callback : 15 | public icallback { 16 | 17 | typedef Graph graph_type; 18 | typedef icallback base; 19 | typedef ischeduler scheduler_type; 20 | 21 | typedef typename base::update_task_type update_task_type; 22 | typedef typename base::update_function_type update_function_type; 23 | 24 | public: 25 | binary_scheduler_callback() {add_task_called= false; } 26 | virtual ~binary_scheduler_callback() {} 27 | 28 | void add_task(update_task_type task, double priority) { 29 | add_task_called = true; 30 | } 31 | /** Creates a collection of tasks on all the vertices in 32 | 'vertices', and all with the same update function and 33 | priority */ 34 | void add_tasks(const std::vector& vertices, 35 | update_function_type func, double priority) { 36 | add_task_called = true; 37 | } 38 | 39 | 40 | void reset() { 41 | add_task_called = false; 42 | } 43 | 44 | void force_abort() { 45 | assert(false); // Unsupported 46 | } 47 | 48 | /// Commits the tasks added 49 | void commit() { }; 50 | bool add_task_called; 51 | }; 52 | 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /src/graphlab/distributed/dc_internal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | namespace graphlab { 4 | 5 | void destroy_dc_thread_local_struct(void* ptr) ; 6 | 7 | struct dc_thread_keys { 8 | pthread_key_t GRAPHLAB_DC_BUFFER_ID; 9 | dc_thread_keys() : GRAPHLAB_DC_BUFFER_ID(1){ 10 | pthread_key_create(&GRAPHLAB_DC_BUFFER_ID, 11 | destroy_dc_thread_local_struct); 12 | } 13 | }; 14 | 15 | static const dc_thread_keys dckeys; 16 | 17 | 18 | 19 | dc_thread_local_struct* create_thread_dc_buffer(size_t thread_id = 0) { 20 | // Require that the data not yet exist 21 | assert(pthread_getspecific(dckeys.GRAPHLAB_DC_BUFFER_ID) == NULL); 22 | // Create the data 23 | dc_thread_local_struct* data = new dc_thread_local_struct; 24 | ASSERT_NE(data, NULL); 25 | memset(data, 0, sizeof(dc_thread_local_struct)); 26 | // Set the data 27 | pthread_setspecific(dckeys.GRAPHLAB_DC_BUFFER_ID, data); 28 | // Return the associated tsd 29 | return data; 30 | } 31 | 32 | 33 | dc_thread_local_struct& get_thread_dc_buffer() { 34 | // get the tsd 35 | dc_thread_local_struct* tsd = 36 | reinterpret_cast 37 | (pthread_getspecific(dckeys.GRAPHLAB_DC_BUFFER_ID)); 38 | // If no tsd be has been associated, create one 39 | if(tsd == NULL) tsd = create_thread_dc_buffer(); 40 | assert(tsd != NULL); 41 | return *tsd; 42 | } 43 | 44 | 45 | void destroy_dc_thread_local_struct(void* ptr) { 46 | dc_thread_local_struct* tsd = 47 | reinterpret_cast 48 | (pthread_getspecific(dckeys.GRAPHLAB_DC_BUFFER_ID)); 49 | 50 | if (tsd != NULL && tsd->sendbuffer != NULL) free(tsd->sendbuffer); 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/mrefine2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * mrefine2.c 5 | * 6 | * This file contains the driving routines for multilevel refinement 7 | * 8 | * Started 7/24/97 9 | * George 10 | * 11 | * $Id: mrefine2.c,v 1.2 2002/08/10 06:29:33 karypis Exp $ 12 | */ 13 | 14 | #include 15 | 16 | 17 | /************************************************************************* 18 | * This function is the entry point of refinement 19 | **************************************************************************/ 20 | void MocRefine2Way2(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float *tpwgts, 21 | float *ubvec) 22 | { 23 | 24 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->UncoarsenTmr)); 25 | 26 | /* Compute the parameters of the coarsest graph */ 27 | MocCompute2WayPartitionParams(ctrl, graph); 28 | 29 | for (;;) { 30 | ASSERT(CheckBnd(graph)); 31 | 32 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->RefTmr)); 33 | switch (ctrl->RType) { 34 | case RTYPE_FM: 35 | MocBalance2Way2(ctrl, graph, tpwgts, ubvec); 36 | MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, ubvec, 8); 37 | break; 38 | default: 39 | errexit("Unknown refinement type: %d\n", ctrl->RType); 40 | } 41 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->RefTmr)); 42 | 43 | if (graph == orggraph) 44 | break; 45 | 46 | graph = graph->finer; 47 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->ProjectTmr)); 48 | MocProject2WayPartition(ctrl, graph); 49 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->ProjectTmr)); 50 | } 51 | 52 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->UncoarsenTmr)); 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/graphlab/util/timer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_TIMER_HPP 2 | #define GRAPHLAB_TIMER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace graphlab { 10 | /** 11 | * \class timer A simple class that can be used for 12 | * benchmarking/timing up to microsecond resolution. 13 | */ 14 | class timer { 15 | private: 16 | timeval start_time_; 17 | public: 18 | timer() { } 19 | 20 | //! Starts the timer. 21 | void start() { gettimeofday(&start_time_, NULL); } 22 | 23 | /** 24 | * Returns the number of seconds since start() was called Behavior 25 | * is undefined if start() was not called before calling 26 | * current_time() 27 | */ 28 | double current_time() const { 29 | timeval current_time; 30 | gettimeofday(¤t_time, NULL); 31 | double answer = 32 | // (current_time.tv_sec + ((double)current_time.tv_usec)/1.0E6) - 33 | // (start_time_.tv_sec + ((double)start_time_.tv_usec)/1.0E6); 34 | current_time.tv_sec-start_time_.tv_sec+ ((double)(current_time.tv_usec-start_time_.tv_usec))/1.0E6; 35 | return answer; 36 | } 37 | 38 | double current_time_millis() const { 39 | return current_time() * 1000; 40 | } 41 | 42 | }; // end of Timer 43 | 44 | float lowres_time_seconds(); 45 | size_t lowres_time_millis(); 46 | 47 | } // end of graphlab namespace 48 | 49 | /** 50 | * Convenience function. Allows you to call "cout << ti" where ti is 51 | * a timer object and it will print the number of seconds elapsed 52 | * since ti.start() was called. 53 | */ 54 | std::ostream& operator<<(std::ostream& out, const graphlab::timer& t); 55 | 56 | /** Returns the current time accurate to 100ms*/ 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/graphlab/monitoring/console_monitor.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef GRAPHLAB_CONSOLE_MONITOR_HPP 3 | #define GRAPHLAB_CONSOLE_MONITOR_HPP 4 | 5 | #include 6 | #include 7 | 8 | namespace graphlab { 9 | 10 | template 11 | class console_monitor : 12 | public imonitor { 13 | 14 | public: 15 | 16 | typedef typename imonitor::update_task_type update_task_type; 17 | typedef typename imonitor::iengine_type iengine_type; 18 | 19 | public: 20 | unsigned long output_priority_freq_tasks; 21 | unsigned long task_counter; 22 | double current_max_priority; 23 | 24 | console_monitor(unsigned long output_priority_freq_tasks = 1000) : 25 | output_priority_freq_tasks(output_priority_freq_tasks), 26 | task_counter(0), 27 | current_max_priority(0) { } 28 | 29 | virtual void init(iengine_type* engine) { 30 | std::cout << "====== CONSOLE LISTENER STARTED =====" << std::endl; 31 | } 32 | 33 | 34 | void scheduler_task_added(update_task_type task, double priority) { 35 | current_max_priority = std::max(current_max_priority, priority); 36 | // Not thread safe!!! 37 | if (++task_counter % output_priority_freq_tasks == 0) { 38 | std::cout << "Approx. task count " 39 | << task_counter 40 | << " with max priority " 41 | << current_max_priority 42 | << " adding task " << size_t(task.function()) 43 | << std::endl; 44 | current_max_priority = 0; 45 | } 46 | } 47 | 48 | 49 | 50 | 51 | 52 | void set_status_str(char * str) { 53 | printf("Status %s\n", str); 54 | } 55 | }; 56 | 57 | 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/graphlab/util/judy_util.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_JUDY_UTIL_HPP 2 | #define GRAPHLAB_JUDY_UTIL_HPP 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | namespace graphlab { 10 | /** 11 | * Get the set of keys in a map as a vector 12 | */ 13 | template 14 | std::vector keys_as_vector(const judy_map_m& map) { 15 | std::vector output(map.size()); 16 | typedef std::pair pair_type; 17 | size_t i = 0; 18 | foreach(const pair_type& pair, map) { 19 | output[i++] = pair.first; 20 | } 21 | return output; 22 | } 23 | 24 | 25 | template 26 | const T& safe_get(const judy_map_m& map, Key k) { 27 | typedef judy_map_m map_type; 28 | typename map_type::const_iterator i = map.find(k); 29 | assert(i != map.end()); 30 | return i->second; 31 | } 32 | 33 | 34 | 35 | template 36 | std::vector keys_as_vector(const judy_map_kdcell& map) { 37 | std::vector output(map.size()); 38 | typedef std::pair pair_type; 39 | size_t i = 0; 40 | foreach(const pair_type& pair, map) { 41 | output[i++] = pair.first; 42 | } 43 | return output; 44 | } 45 | 46 | 47 | template 48 | const T safe_get(const judy_map_kdcell& map, Key k) { 49 | typedef judy_map_kdcell map_type; 50 | typename map_type::const_iterator i = map.find(k); 51 | assert(i != map.end()); 52 | return (*i).second; 53 | } 54 | } 55 | #include 56 | #endif 57 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * macros.h 5 | * 6 | * This file contains macros used in multilevel 7 | * 8 | * Started 9/25/94 9 | * George 10 | * 11 | * $Id: macros.h,v 1.6 2003/04/30 12:42:05 karypis Exp $ 12 | * 13 | */ 14 | 15 | 16 | /************************************************************************* 17 | * The following macro returns a random number in the specified range 18 | **************************************************************************/ 19 | #define AND(a, b) ((a) < 0 ? ((-(a))&(b)) : ((a)&(b))) 20 | #define OR(a, b) ((a) < 0 ? -((-(a))|(b)) : ((a)|(b))) 21 | #define XOR(a, b) ((a) < 0 ? -((-(a))^(b)) : ((a)^(b))) 22 | 23 | #define idxcopy(n, a, b) (idxtype *)memcpy((void *)(b), (void *)(a), sizeof(idxtype)*(n)) 24 | 25 | #define HASHFCT(key, size) ((key)%(size)) 26 | 27 | 28 | /************************************************************************* 29 | * Datatype related macros 30 | **************************************************************************/ 31 | #define idxtype_abs(x) ((x) > 0 ? (x) : -(x)) 32 | 33 | 34 | 35 | 36 | 37 | /************************************************************************* 38 | * These macros insert and remove nodes from the boundary list 39 | **************************************************************************/ 40 | #define BNDInsert(nbnd, bndind, bndptr, vtx) \ 41 | do { \ 42 | ASSERT(bndptr[vtx] == -1); \ 43 | bndind[nbnd] = vtx; \ 44 | bndptr[vtx] = nbnd++;\ 45 | } while(0) 46 | 47 | #define BNDDelete(nbnd, bndind, bndptr, vtx) \ 48 | do { \ 49 | ASSERT(bndptr[vtx] != -1); \ 50 | bndind[bndptr[vtx]] = bndind[--nbnd]; \ 51 | bndptr[bndind[nbnd]] = bndptr[vtx]; \ 52 | bndptr[vtx] = -1; \ 53 | } while(0) 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/graphlab/util/timer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | std::ostream& operator<<(std::ostream& out, const graphlab::timer& t) { 8 | return out << t.current_time(); 9 | } 10 | 11 | namespace graphlab { 12 | void alarm_wakeup(int i); 13 | 14 | 15 | class hundredms_timer { 16 | public: 17 | hundredms_timer() { 18 | stop = false; 19 | tout_val.it_interval.tv_sec = 0; 20 | tout_val.it_interval.tv_usec = 0; 21 | tout_val.it_value.tv_sec = 0; 22 | tout_val.it_value.tv_usec = 100000; 23 | setitimer(ITIMER_REAL, &tout_val,0); 24 | signal(SIGALRM,alarm_wakeup); /* set the Alarm signal capture */ 25 | ti.start(); 26 | } 27 | size_t ctr; 28 | timer ti; 29 | struct itimerval tout_val; 30 | bool stop; 31 | 32 | ~hundredms_timer() { 33 | stop = true; 34 | signal(SIGALRM, SIG_IGN); 35 | } 36 | }; 37 | 38 | hundredms_timer hmstimer; 39 | 40 | 41 | void alarm_wakeup(int i) { 42 | if (hmstimer.stop) return; 43 | signal(SIGALRM,alarm_wakeup); 44 | // compute the desired time till the next 100ms tick by using a real timer call 45 | double realtime = hmstimer.ti.current_time() ; 46 | // round down 47 | hmstimer.ctr = (size_t)(realtime * 10); 48 | hmstimer.tout_val.it_value.tv_usec = (hmstimer.ctr + 1) * 100000 - realtime * 1000000; 49 | setitimer(ITIMER_REAL, &(hmstimer.tout_val), 0); 50 | } 51 | 52 | /** 53 | * Precision of deciseconds 54 | */ 55 | float lowres_time_seconds() { 56 | return float(hmstimer.ctr) / 10; 57 | } 58 | 59 | 60 | /** 61 | * Precision of deciseconds 62 | */ 63 | size_t lowres_time_millis() { 64 | return hmstimer.ctr * 100; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/graphlab/util/binary_parser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_BINARY_PARSER_HPP 2 | #define GRAPHLAB_BINARY_PARSER_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace graphlab { 8 | 9 | /** 10 | * A thin wrapper around ifstream to provide simplicity of reading 11 | * of binary data. 12 | * \see binary_output_stream 13 | */ 14 | class binary_input_stream : public std::ifstream { 15 | typedef std::ifstream base_type; 16 | using base_type::bad; 17 | public: 18 | binary_input_stream(const char* fname) : 19 | base_type(fname, std::ios::binary | std::ios::in) { 20 | assert(bad() == false); 21 | } 22 | 23 | /** 24 | * Read an arbitrary type. 25 | */ 26 | template T read() { 27 | T t; 28 | base_type::read(reinterpret_cast(&t), sizeof(T)); 29 | if(bad()) { 30 | std::cout << "Error reading file!" << std::endl; 31 | assert(false); 32 | } 33 | return t; 34 | } 35 | }; 36 | 37 | 38 | 39 | /** 40 | * A thin wrapper around ifstream to provide simplicity of writing 41 | * of binary data. 42 | * \see binary_input_stream 43 | */ 44 | class binary_output_stream : public std::ofstream { 45 | typedef std::ofstream base_type; 46 | using std::ofstream::bad; 47 | public: 48 | binary_output_stream(const char* fname) : 49 | std::ofstream(fname, std::ios::binary | std::ios::out) { 50 | assert(bad() == false); 51 | } 52 | 53 | //! Write the arbitrary data type to file 54 | template void write(T t) { 55 | base_type::write(reinterpret_cast(&t), sizeof(T)); 56 | if(bad()) { 57 | std::cout << "Error writing file!" << std::endl; 58 | assert(false); 59 | } 60 | } 61 | }; // end of binary_output_stream 62 | 63 | 64 | 65 | } 66 | 67 | 68 | 69 | 70 | #endif 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/gk_arch.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_arch.h 3 | \brief This file contains various architecture-specific declerations 4 | 5 | \date Started 3/27/2007 6 | \author George 7 | \version\verbatim $Id: gk_arch.h 1430 2007-04-07 17:53:07Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_ARCH_H_ 11 | #define _GK_ARCH_H_ 12 | 13 | /************************************************************************* 14 | * Architecture-specific differences in header files 15 | **************************************************************************/ 16 | #ifdef LINUX 17 | #if !defined(__USE_XOPEN) 18 | #define __USE_XOPEN 19 | #endif 20 | #if !defined(_XOPEN_SOURCE) 21 | #define _XOPEN_SOURCE 600 22 | #endif 23 | #if !defined(__USE_XOPEN2K) 24 | #define __USE_XOPEN2K 25 | #endif 26 | #include 27 | #endif 28 | 29 | 30 | #ifdef __MSC__ 31 | #include 32 | #else 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #endif 39 | 40 | 41 | 42 | /************************************************************************* 43 | * Architecture-specific modifications 44 | **************************************************************************/ 45 | #ifdef WIN32 46 | #define __thread __declspec( thread ) 47 | 48 | typedef __int32 int32_t; 49 | typedef __int64 int64_t; 50 | typedef unsigned __int32 uint32_t; 51 | typedef unsigned __int64 uint64_t; 52 | #endif 53 | 54 | 55 | #ifdef SUNOS 56 | #define __thread 57 | #endif 58 | 59 | 60 | #ifdef DARWIN 61 | #define __thread 62 | #endif 63 | 64 | 65 | #ifdef __MSC__ 66 | #define rint(x) ((int)((x)+0.5)) /* MSC does not have rint() function */ 67 | #endif 68 | 69 | 70 | #ifdef __GNUC__ 71 | #if !defined(strdup) 72 | extern char* strdup (const char *); 73 | #endif 74 | #endif 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/graphlab/util/task_count_termination.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_TASK_COUNT_TERMINATION_HPP 2 | #define GRAPHLAB_TASK_COUNT_TERMINATION_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace graphlab { 11 | /** 12 | * Shared termination checker based on task counting. When a 13 | * processor decides to go to sleep, it should call finish(). If 14 | * finish() return true, it can end. Otherwise it must proceed. 15 | * Whenever a new job is created, it must call new_job() after 16 | * inserting into task queue. When the job is fully completed 17 | * (i.e. all new jobs created, it must call completed_job(). 18 | */ 19 | class task_count_termination { 20 | atomic newtaskcount; 21 | atomic finishedtaskcount; 22 | bool force_termination; //signal computation is aborted 23 | 24 | public: 25 | task_count_termination() : newtaskcount(0), 26 | finishedtaskcount(0), 27 | force_termination(false) { } 28 | 29 | ~task_count_termination(){ } 30 | 31 | bool finish() { 32 | return newtaskcount.value == finishedtaskcount.value 33 | || force_termination; 34 | } 35 | 36 | void abort(){ 37 | force_termination = true; 38 | } 39 | 40 | bool is_aborted(){ return force_termination; } 41 | 42 | void restart(){ 43 | force_termination = false; 44 | } 45 | 46 | void new_job() { 47 | newtaskcount.inc(); 48 | } 49 | void completed_job() { 50 | finishedtaskcount.inc(); 51 | assert(finishedtaskcount.value <= newtaskcount.value); 52 | } 53 | 54 | void print() { 55 | std::cout << finishedtaskcount.value << " of " 56 | << newtaskcount.value << std::endl; 57 | } 58 | }; 59 | 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /src/graphlab/extern/bitmagic/bmfwd.h: -------------------------------------------------------------------------------- 1 | #ifndef BMFWD__H__INCLUDED__ 2 | #define BMFWD__H__INCLUDED__ 3 | /* 4 | Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com) 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the "Software"), to deal in the Software without restriction, 9 | including without limitation the rights to use, copy, modify, merge, 10 | publish, distribute, sublicense, and/or sell copies of the Software, 11 | and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | For more information please visit: http://bmagic.sourceforge.net 26 | 27 | */ 28 | 29 | #include "bmconst.h" 30 | 31 | namespace bm 32 | { 33 | 34 | class block_allocator; 35 | class ptr_allocator; 36 | 37 | template class mem_alloc; 38 | 39 | template class miniset; 40 | template class bvmini; 41 | 42 | typedef bm::bvmini standard_miniset; 43 | typedef mem_alloc standard_allocator; 44 | 45 | template 47 | class bvector; 48 | 49 | 50 | } // namespace 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/graphlab/parallel/atomic.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_ATOMIC_HPP 2 | #define GRAPHLAB_ATOMIC_HPP 3 | 4 | namespace graphlab { 5 | /** 6 | * \brief atomic object toolkit 7 | * 8 | * A templated class for creating atomic numbers. 9 | */ 10 | 11 | template 12 | class atomic{ 13 | public: 14 | volatile T value; 15 | atomic(const T& value = 0) : value(value) { } 16 | T inc() { return __sync_add_and_fetch(&value, 1); } 17 | T dec() { return __sync_sub_and_fetch(&value, 1); } 18 | T inc(T val) { return __sync_add_and_fetch(&value, val); } 19 | T dec(T val) { return __sync_sub_and_fetch(&value, val); } 20 | }; 21 | 22 | 23 | /** 24 | atomic instruction that is equivalent to the following:: 25 | 26 | if a==oldval, then { \ 27 | a = newval; \ 28 | return true; \ 29 | } 30 | return false; 31 | */ 32 | template 33 | bool atomic_compare_and_swap(T& a, const T &oldval, const T &newval) { 34 | return __sync_bool_compare_and_swap(&a, oldval, newval); 35 | }; 36 | 37 | 38 | template <> 39 | inline bool atomic_compare_and_swap(double& a, const double &oldval, const double &newval) { 40 | return __sync_bool_compare_and_swap(reinterpret_cast(&a), 41 | *reinterpret_cast(&oldval), 42 | *reinterpret_cast(&newval)); 43 | }; 44 | 45 | template <> 46 | inline bool atomic_compare_and_swap(float& a, const float &oldval, const float &newval) { 47 | return __sync_bool_compare_and_swap(reinterpret_cast(&a), 48 | *reinterpret_cast(&oldval), 49 | *reinterpret_cast(&newval)); 50 | }; 51 | 52 | template 53 | void atomic_exchange(T& a, T& b) { 54 | b =__sync_lock_test_and_set(&a, b); 55 | }; 56 | 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/myqsort.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * myqsort.c 5 | * 6 | * This file contains a fast idxtype increasing qsort algorithm. 7 | * Addopted from TeX 8 | * 9 | * Started 10/18/96 10 | * George 11 | * 12 | * $Id: myqsort.c,v 1.2 2002/08/10 06:29:33 karypis Exp $ 13 | */ 14 | 15 | #include /* only for type declarations */ 16 | 17 | 18 | 19 | 20 | /************************************************************************* 21 | * Entry point of idxtype increasing sort 22 | **************************************************************************/ 23 | void iidxsort(size_t n, idxtype *base) 24 | { 25 | #define idxtype_lt(a, b) ((*a) < (*b)) 26 | GKQSORT(idxtype, base, n, idxtype_lt); 27 | } 28 | 29 | 30 | /************************************************************************* 31 | * Entry point of KeyVal increasing sort, ONLY key part 32 | **************************************************************************/ 33 | void ikeysort(size_t n, KeyValueType *base) 34 | { 35 | #define keyvalue_lt(a, b) ((a)->key < (b)->key) 36 | GKQSORT(KeyValueType, base, n, keyvalue_lt); 37 | } 38 | 39 | 40 | 41 | /************************************************************************* 42 | * Entry point of KeyVal increasing sort, BOTH key and val part 43 | **************************************************************************/ 44 | void ikeyvalsort(size_t n, KeyValueType *base) 45 | { 46 | #define keyvalueboth_lt(a, b) ((a)->key < (b)->key || ((a)->key == (b)->key && (a)->val < (b)->val)) 47 | GKQSORT(KeyValueType, base, n, keyvalueboth_lt); 48 | } 49 | 50 | 51 | /************************************************************************* 52 | * Entry point of DKeyValueType increasing sort based on keys 53 | **************************************************************************/ 54 | void idkeysort(size_t n, DKeyValueType *base) 55 | { 56 | #define dkeyvalue_lt(a, b) ((a)->key < (b)->key) 57 | GKQSORT(DKeyValueType, base, n, dkeyvalue_lt); 58 | } 59 | -------------------------------------------------------------------------------- /apps/pagerank/pagerankapp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * pagerankapp.hpp 3 | * GraphLab_saved 4 | * 5 | * Created by Aapo Kyrola on 1/21/10. 6 | * Copyright 2010 Carnegie Mellon University. All rights reserved. 7 | * 8 | */ 9 | 10 | #ifndef EIGENVECTORAPP_HPP 11 | #define EIGENVECTORAPP_HPP 12 | 13 | #include 14 | 15 | using namespace graphlab; 16 | 17 | struct edge_data { 18 | float weight; 19 | float lastusedval; 20 | float srcvalue; 21 | float residual; 22 | edge_data() {} 23 | edge_data(float _w) { 24 | weight = _w; 25 | lastusedval = 0; 26 | srcvalue = 0; 27 | residual = 0; 28 | } 29 | void save(graphlab::oarchive &oarc) const{ 30 | serialize(oarc, this, sizeof(edge_data)); 31 | } 32 | void load(graphlab::iarchive &iarc) { 33 | deserialize(iarc, this, sizeof(edge_data)); 34 | } 35 | }; 36 | 37 | struct vertex_data { 38 | float value; 39 | float selfweight; 40 | vertex_data() {} 41 | vertex_data(float v) { 42 | value = v; 43 | } 44 | void save(graphlab::oarchive &oarc) const{ 45 | serialize(oarc, this, sizeof(vertex_data)); 46 | } 47 | void load(graphlab::iarchive &iarc) { 48 | deserialize(iarc, this, sizeof(vertex_data)); 49 | } 50 | }; 51 | 52 | 53 | typedef graph pagerank_graph; 54 | typedef types gl_types; 55 | 56 | 57 | 58 | using namespace graphlab; 59 | 60 | class pagerankapp : public iapp { 61 | 62 | public: 63 | pagerankapp(std::string inputfile, std::string binoutfile, bool optimize); 64 | ~pagerankapp(); 65 | 66 | void start(); 67 | 68 | /* Used with analyzer_listener */ 69 | virtual global_dumper dump_function(); 70 | virtual std::vector dump_headers(); 71 | virtual int dump_frequency(); 72 | 73 | 74 | pagerank_graph g; 75 | 76 | 77 | 78 | private: 79 | gl_types::iengine * graphlab; 80 | std::string inputfile; 81 | std::string binoutfile; 82 | bool graphoptimize; 83 | void loadGraph(std::string filename); 84 | }; 85 | 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/support/unused_scheduler_callback.hpp: -------------------------------------------------------------------------------- 1 | #ifndef UNUSED_SCHEDULER_CALLBACK_HPP 2 | #define UNUSED_SCHEDULER_CALLBACK_HPP 3 | #include 4 | #include 5 | #include 6 | 7 | namespace graphlab { 8 | 9 | template 10 | class unused_scheduler_callback : 11 | public icallback { 12 | public: 13 | typedef Graph graph_type; 14 | typedef icallback base; 15 | typedef ischeduler scheduler_type; 16 | 17 | typedef typename base::iengine_type iengine_type; 18 | typedef typename base::update_task_type update_task_type; 19 | typedef typename base::update_function_type update_function_type; 20 | 21 | 22 | 23 | public: 24 | unused_scheduler_callback(iengine_type* engine = NULL) : 25 | engine(engine), logoutput(false) { } 26 | 27 | virtual ~unused_scheduler_callback() {} 28 | 29 | 30 | void add_task(update_task_type task, double priority) { 31 | if (logoutput == false) { 32 | logger(LOG_WARNING, "This scheduler does not permit add task operations." 33 | "This warning will only be displayed once"); 34 | logoutput = true; 35 | } 36 | } 37 | 38 | /** Creates a collection of tasks on all the vertices in 39 | 'vertices', and all with the same update function and 40 | priority */ 41 | void add_tasks(const std::vector& vertices, 42 | update_function_type func, double priority) { 43 | if (logoutput == false) { 44 | logger(LOG_WARNING, "This scheduler does not permit add task operations." 45 | "This warning will only be displayed once"); 46 | logoutput = true; 47 | } 48 | } 49 | 50 | /** 51 | * Force the engine to abort. 52 | */ 53 | void force_abort() { 54 | assert(engine != NULL); 55 | engine->stop(); 56 | } 57 | 58 | 59 | void disable_buffering() {} 60 | 61 | 62 | /// Commits the tasks added 63 | void commit() { }; 64 | private: 65 | iengine_type* engine; 66 | bool logoutput; 67 | }; 68 | 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | project(GraphLab) 3 | 4 | add_library(graphlab_metis STATIC 5 | balance.c graph.c mcoarsen.c mmatch.c refine.c 6 | bucketsort.c initpart.c memory.c mmd.c rkmetis.c 7 | ccgraph.c kfmetis.c mesh.c mpmetis.c separator.c 8 | checkgraph.c kmetis.c meshpart.c mrefine2.c sfm.c 9 | cmetis.c kvmetis.c mfm2.c mrefine.c srefine.c 10 | coarsen.c kwayfm.c mfm.c mrkmetis.c stat.c 11 | compress.c kwayrefine.c mincover.c mutil.c streamio.c 12 | debug.c kwayvolfm.c minitpart2.c myqsort.c subdomains.c 13 | estmem.c kwayvolrefine.c minitpart.c ometis.c timing.c 14 | fm.c match.c mkmetis.c parmetis.c util.c 15 | fortran.c mbalance2.c mkwayfmh.c pmetis.c 16 | frename.c mbalance.c mkwayrefine.c pqueue.c 17 | ) 18 | 19 | # add_library(metis2_shared SHARED 20 | # balance.c graph.c mcoarsen.c mmatch.c refine.c 21 | # bucketsort.c initpart.c memory.c mmd.c rkmetis.c 22 | # ccgraph.c kfmetis.c mesh.c mpmetis.c separator.c 23 | # checkgraph.c kmetis.c meshpart.c mrefine2.c sfm.c 24 | # cmetis.c kvmetis.c mfm2.c mrefine.c srefine.c 25 | # coarsen.c kwayfm.c mfm.c mrkmetis.c stat.c 26 | # compress.c kwayrefine.c mincover.c mutil.c streamio.c 27 | # debug.c kwayvolfm.c minitpart2.c myqsort.c subdomains.c 28 | # estmem.c kwayvolrefine.c minitpart.c ometis.c timing.c 29 | # fm.c match.c mkmetis.c parmetis.c util.c 30 | # fortran.c mbalance2.c mkwayfmh.c pmetis.c 31 | # frename.c mbalance.c mkwayrefine.c pqueue.c 32 | # ) 33 | 34 | 35 | 36 | 37 | # SET_TARGET_PROPERTIES(metis2_shared 38 | # PROPERTIES 39 | # OUTPUT_NAME metis2 40 | # ) 41 | 42 | set_target_properties(graphlab_metis PROPERTIES COMPILE_FLAGS "${METIS_BUILD_OPTS}") 43 | target_link_libraries(graphlab_metis graphlab_GKlib) 44 | 45 | 46 | INSTALL(TARGETS graphlab_metis DESTINATION lib) 47 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/io.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file io.c 3 | \brief Various file I/O functions. 4 | 5 | This file contains various functions that perform I/O. 6 | 7 | \date Started 4/10/95 8 | \author George 9 | \version\verbatim $Id: io.c 1430 2007-04-07 17:53:07Z karypis $ \endverbatim 10 | */ 11 | 12 | 13 | #include 14 | 15 | /************************************************************************* 16 | * This function opens a file 17 | **************************************************************************/ 18 | FILE *gk_fopen(char *fname, char *mode, const char *msg) 19 | { 20 | FILE *fp; 21 | char errmsg[8192]; 22 | 23 | fp = fopen(fname, mode); 24 | if (fp != NULL) 25 | return fp; 26 | 27 | sprintf(errmsg,"file: %s, mode: %s, [%s]", fname, mode, msg); 28 | perror(errmsg); 29 | errexit("Failed on gk_fopen()\n"); 30 | 31 | return NULL; 32 | } 33 | 34 | 35 | /************************************************************************* 36 | * This function closes a file 37 | **************************************************************************/ 38 | void gk_fclose(FILE *fp) 39 | { 40 | fclose(fp); 41 | } 42 | 43 | 44 | 45 | /************************************************************************* 46 | * This function is the GKlib implementation of glibc's getline() 47 | * function. 48 | **************************************************************************/ 49 | gk_loop_t gk_getline(char **lineptr, size_t *n, FILE *stream) 50 | { 51 | size_t i; 52 | int ch; 53 | 54 | if (feof(stream)) 55 | return -1; 56 | 57 | /* Initial memory allocation if *lineptr is NULL */ 58 | if (*lineptr == NULL || *n == 0) { 59 | *n = 1024; 60 | *lineptr = gk_malloc((*n)*sizeof(char), "gk_getline: lineptr"); 61 | } 62 | 63 | /* get into the main loop */ 64 | for (i = 0; (ch = getc(stream)) != EOF; i++) { 65 | (*lineptr)[i] = (char)ch; 66 | 67 | /* reallocate memory if reached at the end of the buffer. The +2 is for '\0' */ 68 | if (i+2 == *n) { 69 | *n = 2* (*n); 70 | *lineptr = gk_realloc(*lineptr, (*n)*sizeof(char), "gk_getline: lineptr"); 71 | } 72 | 73 | if (ch == '\n') 74 | break; 75 | } 76 | (*lineptr)[i+1] = '\0'; 77 | 78 | return i; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /src/graphlab/monitoring/imonitor.hpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | // 5 | // Generic listener interface for monitoring, debugging and profiling. 6 | // 7 | 8 | #ifndef GRAPHLAB_IMONITOR_HPP 9 | #define GRAPHLAB_IMONITOR_HPP 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace graphlab { 17 | 18 | // Predecleration 19 | template class iengine; 20 | 21 | template 22 | class imonitor { 23 | public: 24 | 25 | typedef Graph graph_type; 26 | typedef update_task update_task_type; 27 | typedef iscope iscope_type; 28 | typedef iengine iengine_type; 29 | 30 | /* Initialization, called by the engine */ 31 | virtual void init(iengine_type* engine) { } 32 | 33 | /* Engine calls */ 34 | virtual void engine_task_execute_start(update_task_type task, 35 | iscope_type* scope, 36 | size_t cpuid) { } 37 | 38 | virtual void engine_task_execute_finished(update_task_type task, 39 | iscope_type* scope, 40 | size_t cpuid) { } 41 | 42 | virtual void engine_worker_starts(size_t cpuid) { } 43 | 44 | virtual void engine_worker_dies(size_t cpuid, int taskcount) { } 45 | 46 | 47 | 48 | /* Scheduler calls */ 49 | virtual void scheduler_task_added(update_task_type task, double priority) { } 50 | 51 | virtual void scheduler_task_promoted(update_task_type task, 52 | double diffpriority, 53 | double totalpriority) { } 54 | 55 | virtual void scheduler_task_scheduled(update_task_type task, 56 | double current_max_priority) { } 57 | 58 | virtual void scheduler_task_pruned(update_task_type task) { } 59 | 60 | /* Application calls */ 61 | virtual void app_set_vertex_value(vertex_id_t vid, double value) { } 62 | 63 | /* Called by application to help visualizers to scale values properly */ 64 | virtual void app_set_vertex_value_scale(double min, double max) { } 65 | 66 | }; 67 | } 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/tokenizer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tokenizer.c 3 | * 4 | * This file contains various routines for splitting an input string into 5 | * tokens and returning them in form of a list. The goal is to mimic 6 | * perl's split function 7 | * 8 | * Started 11/23/04 9 | * George 10 | * 11 | * $Id: tokenizer.c 1414 2007-04-05 02:52:46Z karypis $ 12 | * 13 | */ 14 | 15 | #include 16 | 17 | 18 | /************************************************************************ 19 | * This function tokenizes a string based on the user-supplied delimiters 20 | * list. The resulting tokens are returned into an array of strings. 21 | *************************************************************************/ 22 | void gk_strtokenize(char *str, char *delim, gk_Tokens_t *tokens) 23 | { 24 | int i, ntoks, slen; 25 | 26 | tokens->strbuf = gk_strdup(str); 27 | 28 | slen = strlen(str); 29 | str = tokens->strbuf; 30 | 31 | /* Scan once to determine the number of tokens */ 32 | for (ntoks=0, i=0; intoks = ntoks; 49 | tokens->list = (char **)gk_malloc(ntoks*sizeof(char *), "strtokenize: tokens->list"); 50 | 51 | 52 | /* Scan a second time to mark and link the tokens */ 53 | for (ntoks=0, i=0; ilist[ntoks++] = str+i; 62 | 63 | /* Consume all the consecutive characters from the token */ 64 | while (ilist, &tokens->strbuf, LTERM); 76 | } 77 | 78 | -------------------------------------------------------------------------------- /src/graphlab/distributed/distributed_terminator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DISTRIBUTED_TERMINATOR_HPP 2 | #define DISTRIBUTED_TERMINATOR_HPP 3 | #include 4 | #include 5 | #include 6 | 7 | namespace graphlab { 8 | 9 | class distributed_control; 10 | struct distributed_termination_token { 11 | size_t totaltransmitted; 12 | size_t totalreceived; 13 | bool terminatenow; 14 | }; 15 | 16 | class distributed_terminator{ 17 | private: 18 | distributed_control &dc; 19 | distributed_termination_token curtoken; 20 | 21 | // the total I have contributed to the token thus far 22 | // this is protected by the mutex 23 | mutex my_total_lock; 24 | size_t my_total_transmitted; 25 | size_t my_total_received; 26 | 27 | // increments to add to the token next time I send it 28 | // protected by atomics 29 | atomic delta_transmitted; 30 | atomic delta_received; 31 | 32 | bool hastoken; 33 | bool quit; 34 | 35 | bool use_control_packets; 36 | 37 | size_t termid; 38 | static std::vector distributed_term_target; 39 | 40 | public: 41 | distributed_terminator(distributed_control &dc); 42 | 43 | inline bool terminatenow() { 44 | return quit; 45 | } 46 | 47 | inline void reset() { 48 | quit = false; 49 | curtoken.terminatenow = false; 50 | } 51 | 52 | void set_use_control_packets(bool ctrl) { 53 | use_control_packets = ctrl; 54 | } 55 | // if done returns true, distributed termination is complete 56 | // even when locally done, this function still needs to be called 57 | // ocassionally. (possibly with sched_yields outside) 58 | bool done(size_t transmitted, size_t received); 59 | 60 | // message handler 61 | static void distributed_terminator_handler(distributed_control &dc, 62 | procid_t source, 63 | void * ptr, //unused 64 | size_t len, // unused 65 | size_t id, 66 | distributed_termination_token token); 67 | 68 | private: 69 | // send the token. Caller must be sure that I have the token 70 | void send_token(); 71 | 72 | }; 73 | 74 | } 75 | #endif 76 | -------------------------------------------------------------------------------- /src/graphlab/scope/synchronous_scope_factory.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SYNCHRONOUS_SCOPE_FACTORY 2 | #define SYNCHRONOUS_SCOPE_FACTORY 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace graphlab { 10 | /** 11 | * This defines a scope type which is meant for "synchronous" type of 12 | * algorithms. This type of scope should only be used by synchronous_engine 13 | */ 14 | template 15 | class synchronous_scope_factory : 16 | public iscope_factory { 17 | public: 18 | typedef iscope_factory base; 19 | typedef typename base::iscope_type iscope_type; 20 | typedef synchronous_scope synchronous_scope_type; 21 | 22 | synchronous_scope_factory(Graph& srcgraph, 23 | Graph& destgraph, size_t ncpus) : 24 | base(srcgraph, ncpus), 25 | _srcgraph(&srcgraph), 26 | _destgraph(&destgraph), 27 | scopes(ncpus) { 28 | // vertexd data graph does not change 29 | _vertexdatagraph = _destgraph; 30 | } 31 | 32 | ~synchronous_scope_factory() { } 33 | 34 | void set_default_scope(scope_range::scope_range_enum default_scope_range) { }; 35 | 36 | iscope_type* get_scope(size_t cpuid, 37 | vertex_id_t v, 38 | scope_range::scope_range_enum scope_range = scope_range::USE_DEFAULT) { 39 | assert(cpuid < scopes.size()); 40 | synchronous_scope_type& scope = scopes[cpuid]; 41 | scope.init(_srcgraph,_destgraph, _vertexdatagraph, v); 42 | return &(scope); 43 | } 44 | 45 | void swap_graphs() { 46 | Graph* tmp = _srcgraph; 47 | _srcgraph = _destgraph; 48 | _destgraph = tmp; 49 | } 50 | 51 | Graph* get_src_graph() { return _srcgraph; } 52 | Graph* get_dest_graph() { return _destgraph; } 53 | Graph* get_vertex_data_graph() { return _vertexdatagraph; } 54 | 55 | void release_scope(iscope_type* scope) { } 56 | 57 | size_t num_vertices() const { 58 | return _vertexdatagraph->num_vertices(); 59 | } 60 | 61 | private: 62 | Graph* _srcgraph; 63 | Graph* _destgraph; 64 | Graph* _vertexdatagraph; 65 | std::vector scopes; 66 | }; 67 | 68 | } 69 | #endif 70 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/dfkvkselect.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file dfkvkselect.c 3 | \brief Sorts only the largest k values 4 | 5 | \date Started 7/14/00 6 | \author George 7 | \version\verbatim $Id: dfkvkselect.c 1421 2007-04-06 14:37:41Z karypis $\endverbatim 8 | */ 9 | 10 | 11 | #include 12 | 13 | /* Byte-wise swap two items of size SIZE. */ 14 | #define QSSWAP(a, b, stmp) do { stmp = (a); (a) = (b); (b) = stmp; } while (0) 15 | 16 | 17 | /****************************************************************************** 18 | * This function puts the 'topk' largest values in the beginning of the array 19 | *******************************************************************************/ 20 | int gk_dfkvkselect(int n, int topk, gk_fkv_t *cand) 21 | { 22 | int i, j, lo, hi, mid; 23 | gk_fkv_t pivot, stmp; 24 | 25 | if (n <= topk) 26 | return n; /* return if the array has fewer elements than we want */ 27 | 28 | for (lo=0, hi=n-1; hi-lo > 2;) { 29 | mid = lo + ((hi-lo) >> 1); 30 | 31 | /* select the pivot */ 32 | if (cand[mid].key > cand[lo].key) 33 | QSSWAP(cand[mid], cand[lo], stmp); 34 | if (cand[hi].key > cand[mid].key) 35 | QSSWAP(cand[mid], cand[hi], stmp); 36 | else 37 | goto jump_over; 38 | if (cand[mid].key > cand[lo].key) 39 | QSSWAP(cand[mid], cand[lo], stmp); 40 | 41 | jump_over:; 42 | pivot = cand[mid]; 43 | 44 | /* Here's the famous ``collapse the walls'' section of quicksort. */ 45 | for (i=lo+1, j=hi-1; i<=j;) { 46 | for (; cand[i].key > pivot.key; i++); 47 | for (; pivot.key > cand[j].key; j--); 48 | 49 | if (i < j) { 50 | QSSWAP (cand[i], cand[j], stmp); 51 | i++; 52 | j--; 53 | } 54 | else if (i == j) { 55 | i++; 56 | j--; 57 | } 58 | } 59 | 60 | if (i > topk) 61 | hi = i; 62 | else if (i < topk) 63 | lo = i; 64 | else 65 | break; 66 | } 67 | 68 | if (hi-lo == 2) { 69 | if (cand[lo].key < cand[lo+1].key) 70 | QSSWAP(cand[lo], cand[lo+1], stmp); 71 | } 72 | 73 | /* 74 | if (cand[lo].key < cand[hi].key) 75 | printf("Hmm Error: %d %d %d %f %f\n", i, lo, hi, cand[lo].key, cand[hi].key); 76 | 77 | 78 | for (i=topk; i cand[j].key) 81 | printf("Hmm Error: %d %d %f %f %d %d\n", i, j, cand[i].key, cand[j].key, lo, hi); 82 | } 83 | */ 84 | 85 | return topk; 86 | } 87 | -------------------------------------------------------------------------------- /src/graphlab/tasks/update_task.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_UPDATE_TASK_HPP 2 | #define GRAPHLAB_UPDATE_TASK_HPP 3 | 4 | #include 5 | #include 6 | 7 | 8 | #include 9 | namespace graphlab { 10 | // Predecleration 11 | template class icallback; 12 | template class ishared_data; 13 | 14 | 15 | template 16 | class update_task { 17 | public: 18 | 19 | typedef Graph graph_type; 20 | typedef iscope iscope_type; 21 | typedef icallback callback_type; 22 | typedef ishared_data ishared_data_type; 23 | 24 | /// This is the standard vertex update function 25 | typedef void(*update_function_type)(iscope_type& scope, 26 | callback_type& scheduler, 27 | ishared_data_type* sdm); 28 | 29 | 30 | struct hash_functor { 31 | size_t operator()(const update_task& t) const { return t.hash(); } 32 | }; 33 | 34 | private: 35 | vertex_id_t vertexid; 36 | update_function_type func; 37 | 38 | public: 39 | update_task(vertex_id_t vertexid = -1, 40 | update_function_type func = NULL) : 41 | vertexid(vertexid), func(func) { } 42 | 43 | ~update_task() {} 44 | 45 | // Move into engine to simplify typing of this object 46 | // void execute(scope_type& scope, 47 | // ischeduler_callback &scheduler, 48 | // const shared_data_manager* data_manager) { 49 | // assert(func != NULL); 50 | // func(scope, scheduler, data_manager); 51 | // } 52 | 53 | vertex_id_t vertex() const { 54 | return vertexid; 55 | } 56 | 57 | update_function_type function() const { 58 | return func; 59 | } 60 | 61 | /// Returns true if tasks are identical 62 | bool operator==(const update_task &i) const{ 63 | return vertexid == i.vertexid && func == i.func ; 64 | } 65 | 66 | /// comparator 67 | bool operator<(const update_task &i) const{ 68 | return (vertexid < i.vertexid) || 69 | (vertexid == i.vertexid && func < i.func); 70 | } 71 | 72 | size_t hash() const { 73 | // TODO: this was arbitrarily decided. need something better here 74 | return vertexid ^ (size_t)(void*)(func) ^ 66253282; 75 | } 76 | 77 | }; 78 | 79 | 80 | } 81 | #include 82 | #endif 83 | -------------------------------------------------------------------------------- /src/graphlab/extern/bitmagic/bmgamma.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright(c) 2002-2009 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com) 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 19 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | For more information please visit: http://bmagic.sourceforge.net 24 | 25 | */ 26 | 27 | #ifndef BMGAMMAENC__H__INCLUDED__ 28 | #define BMGAMMAENC__H__INCLUDED__ 29 | 30 | 31 | namespace bm 32 | { 33 | 34 | 35 | /** 36 | Elias Gamma decoder 37 | */ 38 | template 39 | class gamma_decoder 40 | { 41 | public: 42 | gamma_decoder(TBitIO& bin) : bin_(bin) 43 | {} 44 | 45 | /** 46 | Start encoding sequence 47 | */ 48 | void start() 49 | {} 50 | 51 | /** 52 | Stop decoding sequence 53 | */ 54 | void stop() 55 | {} 56 | 57 | /** 58 | Decode word 59 | */ 60 | T operator()(void) 61 | { 62 | unsigned l = bin_.eat_zero_bits(); 63 | bin_.get_bit(); // get border bit 64 | T current = 0; 65 | for (unsigned i = 0; i < l; ++i) 66 | { 67 | if (bin_.get_bit()) 68 | { 69 | current += 1 << i; 70 | } 71 | } 72 | current |= (1 << l); 73 | return current; 74 | } 75 | private: 76 | gamma_decoder(const gamma_decoder&); 77 | gamma_decoder& operator=(const gamma_decoder&); 78 | private: 79 | TBitIO& bin_; 80 | }; 81 | 82 | 83 | 84 | } // bm 85 | 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /src/graphlab/util/par_transform.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_PAR_TRANSFORM_HPP 2 | #define GRAPHLAB_PAR_TRANSFORM_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace graphlab { 8 | 9 | namespace partransform_impl { 10 | 11 | template 12 | void transform_update_function(typename CoreType::types::iscope& scope, 13 | typename CoreType::types::icallback& scheduler, 14 | typename CoreType::types::ishared_data* data_manager) { 15 | // get the function 16 | 17 | any a = data_manager->get_constant(0); 18 | TransformF* transformfunction = (TransformF*)(a.as()); 19 | (*transformfunction)(*(scope.vertex_data())); 20 | } 21 | 22 | } 23 | 24 | template 25 | void par_transform(Iterator start, Iterator end, const TransformF& f, size_t ncpus = 0){ 26 | 27 | 28 | typedef typename Iterator::value_type value_type; 29 | typedef core core_type; 30 | 31 | core_type glcore; 32 | // create alot of vertices 33 | glcore.set_scope_type("null"); 34 | glcore.set_engine_type("async"); 35 | glcore.set_scheduler_type("sweep"); 36 | if (ncpus > 0) glcore.set_ncpus(ncpus); 37 | 38 | Iterator i = start; 39 | while (i!=end) { 40 | glcore.graph().add_vertex(&(*i)); 41 | ++i; 42 | } 43 | 44 | glcore.shared_data().set_constant(0, (void*)(&f)); 45 | glcore.add_task_to_all(partransform_impl:: 46 | transform_update_function, 1.0); 47 | glcore.start(); 48 | } 49 | 50 | 51 | 52 | template 53 | void par_transform(Iterator start, Iterator end, const TransformF& f, 54 | const engine_options& eopts){ 55 | 56 | 57 | typedef typename Iterator::value_type value_type; 58 | typedef core core_type; 59 | 60 | core_type glcore; 61 | // create alot of vertices 62 | glcore.set_engine_options(eopts); 63 | 64 | 65 | Iterator i = start; 66 | while (i!=end) { 67 | glcore.graph().add_vertex(&(*i)); 68 | ++i; 69 | } 70 | 71 | glcore.shared_data().set_constant(0, (void*)(&f)); 72 | glcore.add_task_to_all(partransform_impl:: 73 | transform_update_function, 1.0); 74 | glcore.start(); 75 | } 76 | 77 | 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/icallback.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_ICALLBACK_HPP 2 | #define GRAPHLAB_ICALLBACK_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | namespace graphlab { 14 | 15 | /** 16 | * This is the class that is passed to the update functions. This 17 | * class allows the update functions to create and add new tasks to 18 | * be scheduled. The commit() function should be called by the task 19 | * executor at the end of the update function call. This allows the 20 | * scheduler to either "buffer" the tasks and apply them only on a 21 | * commit, or to do some intelligent pre-pruning of tasks, or to 22 | * even insert the task directly into the scheduler. 23 | */ 24 | template 25 | class icallback { 26 | public: 27 | typedef Graph graph_type; 28 | typedef update_task update_task_type; 29 | typedef iengine iengine_type; 30 | typedef typename update_task_type::update_function_type 31 | update_function_type; 32 | 33 | 34 | icallback() {} 35 | virtual ~icallback() {} 36 | 37 | /** 38 | * Adds a task to execute the update function on the vertex with 39 | * the given priority. 40 | */ 41 | void add_task(vertex_id_t vertex, 42 | update_function_type update_fun, 43 | double priority) { 44 | update_task_type task(vertex, update_fun); 45 | add_task(task, priority); 46 | } 47 | 48 | /** 49 | * Adds an update task with a particular priority. The exact 50 | * behavior of this function depends on the type of scheduler 51 | */ 52 | virtual void add_task(update_task_type task, double priority) = 0; 53 | 54 | /** 55 | * Creates a collection of tasks on all the vertices in 56 | * 'vertices', and all with the same update function and priority 57 | */ 58 | virtual void add_tasks(const std::vector& vertices, 59 | update_function_type func, double priority) = 0; 60 | 61 | 62 | /** 63 | * Calling this function will force the engine to abort 64 | * immediately 65 | */ 66 | virtual void force_abort() = 0; 67 | 68 | 69 | 70 | // TODO : FIX 71 | virtual void enable_buffering() {} 72 | virtual void commit() {} 73 | virtual int num_of_buffered_tasks() { return 0; } 74 | }; 75 | 76 | }; //end graphlab namespace 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/timing.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * timing.c 5 | * 6 | * This file contains routines that deal with timing Metis 7 | * 8 | * Started 7/24/97 9 | * George 10 | * 11 | * $Id: timing.c,v 1.2 2002/08/10 06:29:34 karypis Exp $ 12 | * 13 | */ 14 | 15 | #include 16 | 17 | 18 | /************************************************************************* 19 | * This function clears the timers 20 | **************************************************************************/ 21 | void InitTimers(CtrlType *ctrl) 22 | { 23 | gk_clearcputimer(ctrl->TotalTmr); 24 | gk_clearcputimer(ctrl->InitPartTmr); 25 | gk_clearcputimer(ctrl->MatchTmr); 26 | gk_clearcputimer(ctrl->ContractTmr); 27 | gk_clearcputimer(ctrl->CoarsenTmr); 28 | gk_clearcputimer(ctrl->UncoarsenTmr); 29 | gk_clearcputimer(ctrl->RefTmr); 30 | gk_clearcputimer(ctrl->ProjectTmr); 31 | gk_clearcputimer(ctrl->SplitTmr); 32 | gk_clearcputimer(ctrl->SepTmr); 33 | gk_clearcputimer(ctrl->AuxTmr1); 34 | gk_clearcputimer(ctrl->AuxTmr2); 35 | gk_clearcputimer(ctrl->AuxTmr3); 36 | gk_clearcputimer(ctrl->AuxTmr4); 37 | gk_clearcputimer(ctrl->AuxTmr5); 38 | gk_clearcputimer(ctrl->AuxTmr6); 39 | } 40 | 41 | 42 | 43 | /************************************************************************* 44 | * This function prints the various timers 45 | **************************************************************************/ 46 | void PrintTimers(CtrlType *ctrl) 47 | { 48 | mprintf("\nTiming Information -------------------------------------------------"); 49 | mprintf("\n Multilevel: \t\t %7.3f", gk_getcputimer(ctrl->TotalTmr)); 50 | mprintf("\n Coarsening: \t\t %7.3f", gk_getcputimer(ctrl->CoarsenTmr)); 51 | mprintf("\n Matching: \t\t\t %7.3f", gk_getcputimer(ctrl->MatchTmr)); 52 | mprintf("\n Contract: \t\t\t %7.3f", gk_getcputimer(ctrl->ContractTmr)); 53 | mprintf("\n Initial Partition: \t %7.3f", gk_getcputimer(ctrl->InitPartTmr)); 54 | mprintf("\n Construct Separator: \t %7.3f", gk_getcputimer(ctrl->SepTmr)); 55 | mprintf("\n Uncoarsening: \t\t %7.3f", gk_getcputimer(ctrl->UncoarsenTmr)); 56 | mprintf("\n Refinement: \t\t\t %7.3f", gk_getcputimer(ctrl->RefTmr)); 57 | mprintf("\n Projection: \t\t\t %7.3f", gk_getcputimer(ctrl->ProjectTmr)); 58 | mprintf("\n Splitting: \t\t %7.3f", gk_getcputimer(ctrl->SplitTmr)); 59 | mprintf("\n AUX1: \t\t %7.3f", gk_getcputimer(ctrl->AuxTmr1)); 60 | mprintf("\n AUX2: \t\t %7.3f", gk_getcputimer(ctrl->AuxTmr2)); 61 | mprintf("\n AUX3: \t\t %7.3f", gk_getcputimer(ctrl->AuxTmr3)); 62 | mprintf("\n********************************************************************\n"); 63 | } 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/coarsen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coarsen.c 3 | * 4 | * This file contains the driving routines for the coarsening process 5 | * 6 | * Started 7/23/97 7 | * George 8 | * 9 | */ 10 | 11 | #include 12 | 13 | 14 | /************************************************************************* 15 | * This function takes a graph and creates a sequence of coarser graphs 16 | **************************************************************************/ 17 | GraphType *Coarsen2Way(CtrlType *ctrl, GraphType *graph) 18 | { 19 | idxtype clevel; 20 | GraphType *cgraph; 21 | 22 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->CoarsenTmr)); 23 | 24 | cgraph = graph; 25 | 26 | /* The following is ahack to allow the multiple bisections to go through with correct 27 | coarsening */ 28 | if (ctrl->CType > 20) { 29 | clevel = 1; 30 | ctrl->CType -= 20; 31 | } 32 | else 33 | clevel = 0; 34 | 35 | do { 36 | IFSET(ctrl->dbglvl, DBG_COARSEN, mprintf("%6D %7D %7D [%D] [%D %D]\n", 37 | cgraph->nvtxs, cgraph->nedges/2, idxsum(cgraph->nvtxs, cgraph->adjwgtsum, 1)/2, 38 | ctrl->CoarsenTo, ctrl->maxvwgt, 39 | (cgraph->vwgt ? idxsum(cgraph->nvtxs, cgraph->vwgt, 1) : cgraph->nvtxs))); 40 | 41 | if (cgraph->adjwgt) { 42 | switch (ctrl->CType) { 43 | case MTYPE_RM: 44 | Match_RM(ctrl, cgraph); 45 | break; 46 | case MTYPE_HEM: 47 | if (clevel < 1 || cgraph->nedges == 0) 48 | Match_RM(ctrl, cgraph); 49 | else 50 | Match_HEM(ctrl, cgraph); 51 | break; 52 | case MTYPE_SHEM: 53 | if (clevel < 1 || cgraph->nedges == 0) 54 | Match_RM(ctrl, cgraph); 55 | else 56 | Match_SHEM(ctrl, cgraph); 57 | break; 58 | case MTYPE_SHEMKWAY: 59 | if (cgraph->nedges == 0) 60 | Match_RM(ctrl, cgraph); 61 | else 62 | Match_SHEM(ctrl, cgraph); 63 | break; 64 | default: 65 | errexit("Unknown CType: %d\n", ctrl->CType); 66 | } 67 | } 68 | else { 69 | Match_RM_NVW(ctrl, cgraph); 70 | } 71 | 72 | cgraph = cgraph->coarser; 73 | clevel++; 74 | 75 | } while (cgraph->nvtxs > ctrl->CoarsenTo && cgraph->nvtxs < COARSEN_FRACTION2*cgraph->finer->nvtxs && cgraph->nedges > cgraph->nvtxs/2); 76 | 77 | IFSET(ctrl->dbglvl, DBG_COARSEN, mprintf("%6D %7D %7D [%D] [%D %D]\n", 78 | cgraph->nvtxs, cgraph->nedges/2, idxsum(cgraph->nvtxs, cgraph->adjwgtsum, 1)/2, 79 | ctrl->CoarsenTo, ctrl->maxvwgt, 80 | (cgraph->vwgt ? idxsum(cgraph->nvtxs, cgraph->vwgt, 1) : cgraph->nvtxs))); 81 | 82 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->CoarsenTmr)); 83 | 84 | return cgraph; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /src/graphlab/serialization/iterator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SERIALIZE_ITERATOR_HPP 2 | #define GRAPHLAB_SERIALIZE_ITERATOR_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace graphlab { 11 | /** 12 | Serializes the contents between the iterators begin and end. 13 | This version prefers the availability of RandomAccessIterator since it needs 14 | a distance between the begin and end iterator. 15 | This function as implemented will work for other input iterators 16 | but is extremely inefficient. 17 | Returns true on success, false on failure */ 18 | template 19 | void serialize_iterator(oarchive& a, RandomAccessIterator begin, 20 | RandomAccessIterator end){ 21 | size_t vsize = std::distance(begin, end); 22 | a << vsize; 23 | //store each element 24 | for(; begin != end; ++begin) { 25 | a << *begin; 26 | } 27 | } 28 | 29 | 30 | /** 31 | Serializes the contents between the iterators begin and end. 32 | This version takes all InputIterator types, but takes a "count" for 33 | efficiency. This count is checked and will return failure if the number 34 | of elements serialized does not match the count 35 | Returns true on success, false on failure */ 36 | template 37 | void serialize_iterator(oarchive& a, InputIterator begin, 38 | InputIterator end, size_t vsize){ 39 | a << vsize; 40 | //store each element 41 | size_t count = 0; 42 | for(; begin != end; ++begin) { 43 | ++count; 44 | a << *begin; 45 | } 46 | // fail if count does not match 47 | assert(count == vsize); 48 | } 49 | 50 | /** 51 | The accompanying function to serialize_iterator() 52 | Reads elements from the stream and send it to the output iterator. 53 | Note that this requires an additional template parameter T which is the 54 | "type of object to deserialize" 55 | This is necessary for instance for the map type. The map::value_type 56 | is pair which is not useful since I cannot assign to it. 57 | In this case, T=pair 58 | 59 | Returns true on success, false on failure */ 60 | template 61 | void deserialize_iterator(iarchive& a, OutputIterator result) { 62 | // get the number of elements to deserialize 63 | size_t length = 0; 64 | a >> length; 65 | 66 | // iterate through and send to the output iterator 67 | for (size_t x = 0; x < length ; ++x){ 68 | T v; 69 | a >> v; 70 | (*result) = v; 71 | result++; 72 | } 73 | } 74 | } // namespace prl 75 | #endif //PRL_SERIALIZE_ITERATOR_HPP 76 | -------------------------------------------------------------------------------- /src/graphlab/util/synchronized_circular_queue.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SYNCHRONIZED_CIRCULAR_QUEUE_HPP 2 | #define GRAPHLAB_SYNCHRONIZED_CIRCULAR_QUEUE_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #include 10 | 11 | 12 | namespace graphlab { 13 | 14 | 15 | /** 16 | Implementation of a self-resizing circular queue 17 | */ 18 | template 19 | class synchronized_circular_queue { 20 | 21 | public: 22 | synchronized_circular_queue(size_t sizehint = 128) { 23 | queue = (T*)malloc(sizeof(T) * sizehint); 24 | head = 0; 25 | tail = 0; 26 | length = 0; 27 | queuesize = sizehint; 28 | } 29 | 30 | ~synchronized_circular_queue() { 31 | free(queue); 32 | } 33 | 34 | 35 | void push(const T &item) { 36 | queuelock.lock(); 37 | if (length == queuesize) { 38 | unsync_doublesize(); 39 | } 40 | queue[tail] = item; 41 | ++tail; 42 | tail = (tail < queuesize)?tail:0; 43 | ++length; 44 | queuelock.unlock(); 45 | } 46 | 47 | bool safepop(T * ret) { 48 | queuelock.lock(); 49 | if (length == 0) { 50 | queuelock.unlock(); 51 | return false; 52 | } 53 | (*ret) = queue[head]; 54 | ++head; 55 | head = (head < queuesize)?head:0; 56 | --length; 57 | queuelock.unlock(); 58 | return true; 59 | } 60 | 61 | T pop() { 62 | queuelock.lock(); 63 | assert(length > 0); 64 | T t = queue[head]; 65 | ++head; 66 | head = (head < queuesize)?head:0; 67 | --length; 68 | queuelock.unlock(); 69 | return t; 70 | } 71 | 72 | size_t size() const{ 73 | return length; 74 | } 75 | private: 76 | T* queue; 77 | spinlock queuelock; 78 | size_t head; /// points to the first element in the queue 79 | size_t tail; /// points to one past the last element in the queue 80 | size_t length; /// number of elements in the queue 81 | size_t queuesize; /// the size of the queue array 82 | 83 | void unsync_doublesize() { 84 | queue = (T*)realloc(queue, sizeof(T) * (queuesize*2)); 85 | //queue.resize(queue.size() * 2); 86 | // now I need to move elements around 87 | // if head < tail, that means that the array 88 | // is in the right position. I do not need to do anything 89 | // otherwise.I need to move (0...tail-1) to (size:size+tail) 90 | if (head >= tail && length > 0) { 91 | memcpy(queue+queuesize, queue, sizeof(T) * tail); 92 | tail = queuesize + tail; 93 | } 94 | queuesize *= 2; 95 | } 96 | }; 97 | 98 | } 99 | #endif 100 | -------------------------------------------------------------------------------- /src/graphlab/util/prioritized_multiqueue.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_PRIORITIZED_MULTIQUEUE_HPP 2 | #define GRAPHLAB_PRIORITIZED_MULTIQUEUE_HPP 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace graphlab { 9 | 10 | template 11 | class prioritized_multiqueue { 12 | 13 | public: 14 | prioritized_multiqueue(size_t numqueues_ = 8) { 15 | numqueues = numqueues_; 16 | queue.resize(numqueues); 17 | locks.resize(numqueues); 18 | num_queues_full.value = 0; 19 | }; 20 | ~prioritized_multiqueue() { }; 21 | 22 | inline void push(const T &item, size_t queuehint) { 23 | locks[queuehint].lock(); 24 | if (queue[queuehint].empty()) num_queues_full.inc(); 25 | queue[queuehint].push(item); 26 | locks[queuehint].unlock(); 27 | } 28 | 29 | inline bool safepop(T* ret, size_t queuehint) { 30 | locks[queuehint].lock(); 31 | // if the queue has stuff in it 32 | if (queue[queuehint].size() == 0) { 33 | locks[queuehint].unlock(); 34 | return false; 35 | } 36 | *ret = queue[queuehint].front(); 37 | queue[queuehint].pop(); 38 | if (queue[queuehint].empty()) num_queues_full.dec(); 39 | locks[queuehint].unlock(); 40 | return true; 41 | } 42 | 43 | /** Pushes an element into the queue without a hint. If you use this, you 44 | really should lock. */ 45 | void push(const T &item) { 46 | // M.D. Mitzenmacher The Power of Two Choices in Randomized Load Balancing (1991) 47 | // http://www.eecs.harvard.edu/~michaelm/postscripts/mythesis.pdf 48 | 49 | // pushing without a hint. push into the smaller of 2 selections 50 | if (numqueues == 1) { 51 | push(item, 0); 52 | return; 53 | } 54 | size_t r1 = rand_int(numqueues); 55 | size_t r2 = rand_int(numqueues-1); 56 | if (r2 >= r1) ++r2; 57 | size_t queuehint = (queue[r1].size() < queue[r2].size()) ? r1 : r2; 58 | push(item, queuehint); 59 | } 60 | 61 | size_t size() const{ 62 | size_t count = 0; 63 | for (size_t i = 0; i < queue.size(); ++i) { 64 | count += queue[i].size(); 65 | } 66 | return count; 67 | } 68 | 69 | bool empty() const { 70 | return (num_queues_full.value == 0); 71 | } 72 | private: 73 | 74 | static inline size_t rand_int(size_t q) { 75 | double v = thread::rand01(); 76 | size_t r = *reinterpret_cast(&v); 77 | return (r >> 8) % q; 78 | } 79 | 80 | typedef mutable_queue vertex_queue_type; 81 | 82 | std::vector > queue; 83 | std::vector locks; 84 | size_t numqueues; 85 | atomic num_queues_full; 86 | }; 87 | 88 | } 89 | #endif 90 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/gk_getopt.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_getopt.h 3 | \brief This file contains GNU's externs/structs/prototypes 4 | 5 | \date Started 3/27/2007 6 | \author George 7 | \version\verbatim $Id: gk_getopt.h 1277 2007-03-27 21:17:33Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_GETOPT_H_ 11 | #define _GK_GETOPT_H_ 12 | 13 | 14 | /* Externals from getopt.c */ 15 | extern char *gk_optarg; 16 | extern int gk_optind; 17 | extern int gk_opterr; 18 | extern int gk_optopt; 19 | 20 | 21 | /*! \brief The structure that stores the information about the command-line options 22 | 23 | This structure describes a single long option name for the sake of 24 | gk_getopt_long(). The argument long_options must be an array 25 | of these structures, one for each long option. Terminate the array with 26 | an element containing all zeros. 27 | */ 28 | struct gk_option { 29 | const char *name; /*!< This field is the name of the option. */ 30 | int has_arg; /*!< This field says whether the option takes an argument. 31 | It is an integer, and there are three legitimate values: 32 | no_argument, required_argument and optional_argument. 33 | 34 | \todo Need to better define/use the constants for this member 35 | variable. 36 | */ 37 | int *flag; /*!< See the discussion on ::gk_option#val */ 38 | int val; /*!< These fields control how to report or act on the option 39 | when it occurs. 40 | 41 | If flag is a null pointer, then the val is a value which 42 | identifies this option. Often these values are chosen 43 | to uniquely identify particular long options. 44 | 45 | If flag is not a null pointer, it should be the address 46 | of an int variable which is the flag for this option. 47 | The value in val is the value to store in the flag to 48 | indicate that the option was seen. */ 49 | }; 50 | 51 | /* Names for the values of the `has_arg' field of `struct gk_option'. */ 52 | #define no_argument 0 53 | #define required_argument 1 54 | #define optional_argument 2 55 | 56 | 57 | /* Function prototypes */ 58 | extern int gk_getopt(int __argc, char **__argv, const char *__shortopts); 59 | extern int gk_getopt_long(int __argc, char *const *__argv, const char *__shortopts, 60 | const struct gk_option *__longopts, int *__longind); 61 | extern int gk_getopt_long_only (int __argc, char *const *__argv, 62 | const char *__shortopts, const struct gk_option *__longopts, int *__longind); 63 | 64 | 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * util.c 5 | * 6 | * This file contains utility functions 7 | * 8 | * $Id: util.c 1421 2007-04-06 14:37:41Z karypis $ 9 | * 10 | */ 11 | 12 | #include 13 | 14 | 15 | 16 | /************************************************************************* 17 | * This file randomly permutes the contents of an array. 18 | * flag == 0, don't initialize perm 19 | * flag == 1, set p[i] = i 20 | **************************************************************************/ 21 | void gk_RandomPermute(size_t n, int *p, int flag) 22 | { 23 | gk_idx_t i, u, v; 24 | int tmp; 25 | 26 | if (flag == 1) { 27 | for (i=0; i 1; i++, a = a>>1); 75 | return i-1; 76 | } 77 | 78 | 79 | /************************************************************************* 80 | * This function checks if the argument is a power of 2 81 | **************************************************************************/ 82 | int gk_ispow2(int a) 83 | { 84 | return (a == (1< 7 | #include 8 | 9 | namespace graphlab { 10 | /** 11 | Algorithm based on: 12 | Ho Fung Leung, Hing Fung Ting. 13 | Optimal Global termination Detection in Shared Memory Asynchronous 14 | Multiprocessor Systems 15 | */ 16 | class optimal_termination { 17 | public: 18 | optimal_termination(size_t _ncpus):worker(this),t(&worker) { 19 | ncpus = _ncpus; 20 | alpha = (volatile size_t*)malloc(sizeof(size_t) * ncpus); 21 | beta = (volatile size_t*)malloc(sizeof(size_t) * ncpus); 22 | for (size_t i = 0;i < ncpus; ++i) { 23 | alpha[i] = 1; 24 | beta[i] = 1; 25 | } 26 | gamma = 0; 27 | dead = false; 28 | // start the thread 29 | lastwakeup = 0; 30 | t.start(); 31 | } 32 | 33 | 34 | 35 | ~optimal_termination(){ 36 | free((void*)(alpha)); 37 | free((void*)(beta)); 38 | } 39 | 40 | void termination_stage1(size_t cpuid) { 41 | alpha[cpuid] = 0; 42 | } 43 | 44 | void cancel_stage1(size_t cpuid) { 45 | alpha[cpuid] = 1; 46 | } 47 | 48 | void termination_stage2(size_t cpuid) { 49 | beta[cpuid] = 0; 50 | } 51 | bool poll_termination(size_t cpuid) { 52 | return dead; 53 | } 54 | 55 | void cancel_stage2(size_t cpuid) { 56 | beta[cpuid] = 1; 57 | alpha[cpuid] = 1; 58 | } 59 | 60 | void new_job() { 61 | size_t a = lastwakeup++; 62 | lastwakeup = lastwakeup % ncpus; 63 | a = a % ncpus; 64 | new_job(a); 65 | } 66 | 67 | void new_job(size_t cpuhint) { 68 | while(alpha[cpuhint] == 0); 69 | gamma = 1; 70 | } 71 | 72 | 73 | class optimal_termination_worker: public runnable { 74 | optimal_termination* st; 75 | public: 76 | optimal_termination_worker(optimal_termination* _st) : st(_st) { } 77 | void run() { 78 | volatile size_t r = 1; 79 | size_t ncpus = st->ncpus; 80 | while (r == 1) { 81 | r = 0; 82 | for (size_t i = 0;i < ncpus; ++i) { 83 | r = r || st->beta[i]; 84 | } 85 | r = r || st->gamma; 86 | st->gamma = 0; 87 | usleep(10000); 88 | } 89 | st->dead = true; 90 | return; 91 | } 92 | }; 93 | 94 | private: 95 | volatile size_t* alpha; 96 | volatile size_t* beta; 97 | volatile size_t gamma; 98 | size_t ncpus; 99 | size_t lastwakeup; 100 | bool dead; 101 | optimal_termination_worker worker; 102 | thread t; 103 | }; 104 | 105 | } 106 | #endif 107 | -------------------------------------------------------------------------------- /src/graphlab/util/synchronized_multiqueue.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SYNCHRONIZED_MULTIQUEUE_HPP 2 | #define GRAPHLAB_SYNCHRONIZED_MULTIQUEUE_HPP 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | namespace graphlab { 11 | 12 | template 13 | class synchronized_multiqueue { 14 | 15 | public: 16 | synchronized_multiqueue(size_t numqueues_ = 8) { 17 | numqueues = numqueues_; 18 | queue.resize(numqueues); 19 | locks.resize(numqueues); 20 | num_queues_full.value = 0; 21 | }; 22 | ~synchronized_multiqueue() { }; 23 | 24 | inline void push(const T &item, size_t queuehint) { 25 | locks[queuehint].lock(); 26 | if (queue[queuehint].empty()) num_queues_full.inc(); 27 | queue[queuehint].push(item); 28 | locks[queuehint].unlock(); 29 | } 30 | 31 | inline bool safepop(T* ret, size_t queuehint) { 32 | locks[queuehint].lock(); 33 | // if the queue has stuff in it 34 | if (queue[queuehint].size() == 0) { 35 | locks[queuehint].unlock(); 36 | return false; 37 | } 38 | *ret = queue[queuehint].front(); 39 | queue[queuehint].pop(); 40 | if (queue[queuehint].empty()) num_queues_full.dec(); 41 | locks[queuehint].unlock(); 42 | return true; 43 | } 44 | 45 | /** Pushes an element into the queue without a hint. If you use this, you 46 | really should lock. */ 47 | void push(const T &item) { 48 | // M.D. Mitzenmacher The Power of Two Choices in Randomized 49 | // Load Balancing (1991) 50 | // http://www.eecs.harvard.edu/~michaelm/postscripts/mythesis.pdf 51 | 52 | // pushing without a hint. push into the smaller of 2 selections 53 | if (numqueues == 1) { 54 | push(item, 0); 55 | return; 56 | } 57 | size_t r1 = random::rand_int(numqueues-1); 58 | size_t r2 = random::rand_int(numqueues-2); 59 | if (r2 >= r1) ++r2; 60 | size_t queuehint = (queue[r1].size() < queue[r2].size()) ? r1 : r2; 61 | push(item, queuehint); 62 | } 63 | 64 | size_t size() const{ 65 | size_t count = 0; 66 | for (size_t i = 0; i < queue.size(); ++i) { 67 | count += queue[i].size(); 68 | } 69 | return count; 70 | } 71 | 72 | bool empty() const { 73 | return (num_queues_full.value == 0); 74 | } 75 | private: 76 | 77 | 78 | // static inline size_t rand_int(size_t q) { 79 | // // double v = thread::rand01(); 80 | // // size_t r = *reinterpret_cast(&v); 81 | // // return (r >> 8) % q; 82 | // return size_t(std::floor(thread::rand01() * q)); 83 | // } 84 | 85 | std::vector > queue; 86 | std::vector locks; 87 | size_t numqueues; 88 | atomic num_queues_full; 89 | }; 90 | 91 | } 92 | #endif 93 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/mcoarsen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mcoarsen.c 3 | * 4 | * This file contains the driving routines for the coarsening process 5 | * 6 | * Started 7/23/97 7 | * George 8 | * 9 | * $Id: mcoarsen.c,v 1.3 2003/07/31 15:52:47 karypis Exp $ 10 | * 11 | */ 12 | 13 | #include 14 | 15 | 16 | /************************************************************************* 17 | * This function takes a graph and creates a sequence of coarser graphs 18 | **************************************************************************/ 19 | GraphType *MCCoarsen2Way(CtrlType *ctrl, GraphType *graph) 20 | { 21 | idxtype i, clevel; 22 | GraphType *cgraph; 23 | 24 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->CoarsenTmr)); 25 | 26 | cgraph = graph; 27 | 28 | clevel = 0; 29 | do { 30 | if (ctrl->dbglvl&DBG_COARSEN) { 31 | mprintf("%6D %7D %10D [%D] [%6.4f", cgraph->nvtxs, cgraph->nedges, 32 | idxsum(cgraph->nvtxs, cgraph->adjwgtsum, 1), ctrl->CoarsenTo, ctrl->nmaxvwgt); 33 | for (i=0; incon; i++) 34 | mprintf(" %5.3f", gk_fsum(cgraph->nvtxs, cgraph->nvwgt+i, cgraph->ncon)); 35 | mprintf("]\n"); 36 | } 37 | 38 | if (cgraph->nedges == 0) { 39 | MCMatch_RM(ctrl, cgraph); 40 | } 41 | else { 42 | switch (ctrl->CType) { 43 | case MTYPE_RM: 44 | MCMatch_RM(ctrl, cgraph); 45 | break; 46 | case MTYPE_HEM: 47 | if (clevel < 1) 48 | MCMatch_RM(ctrl, cgraph); 49 | else 50 | MCMatch_HEM(ctrl, cgraph); 51 | break; 52 | case MTYPE_SHEM: 53 | if (clevel < 1) 54 | MCMatch_RM(ctrl, cgraph); 55 | else 56 | MCMatch_SHEM(ctrl, cgraph); 57 | break; 58 | case MTYPE_SHEMKWAY: 59 | MCMatch_SHEM(ctrl, cgraph); 60 | break; 61 | case MTYPE_SHEBM_ONENORM: 62 | MCMatch_SHEBM(ctrl, cgraph, 1); 63 | break; 64 | case MTYPE_SHEBM_INFNORM: 65 | MCMatch_SHEBM(ctrl, cgraph, -1); 66 | break; 67 | case MTYPE_SBHEM_ONENORM: 68 | MCMatch_SBHEM(ctrl, cgraph, 1); 69 | break; 70 | case MTYPE_SBHEM_INFNORM: 71 | MCMatch_SBHEM(ctrl, cgraph, -1); 72 | break; 73 | default: 74 | errexit("Unknown CType: %d\n", ctrl->CType); 75 | } 76 | } 77 | 78 | cgraph = cgraph->coarser; 79 | clevel++; 80 | 81 | } while (cgraph->nvtxs > ctrl->CoarsenTo && cgraph->nvtxs < COARSEN_FRACTION2*cgraph->finer->nvtxs && cgraph->nedges > cgraph->nvtxs/2); 82 | 83 | if (ctrl->dbglvl&DBG_COARSEN) { 84 | mprintf("%6D %7D %10D [%D] [%6.4f", cgraph->nvtxs, cgraph->nedges, 85 | idxsum(cgraph->nvtxs, cgraph->adjwgtsum, 1), ctrl->CoarsenTo, ctrl->nmaxvwgt); 86 | for (i=0; incon; i++) 87 | mprintf(" %5.3f", gk_fsum(cgraph->nvtxs, cgraph->nvwgt+i, cgraph->ncon)); 88 | mprintf("]\n"); 89 | } 90 | 91 | 92 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->CoarsenTmr)); 93 | 94 | return cgraph; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/support/direct_callback.hpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef DIRECT_CALLBACK_HPP 4 | #define DIRECT_CALLBACK_HPP 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace graphlab { 15 | 16 | /** 17 | This is a callback class that is passed to the update functions, and allow the 18 | update functions to add tasks back into the scheduler 19 | \see ischeduler_callback */ 20 | template 21 | class direct_callback : 22 | public icallback { 23 | public: 24 | typedef Graph graph_type; 25 | typedef icallback base; 26 | typedef ischeduler scheduler_type; 27 | 28 | typedef typename base::iengine_type iengine_type; 29 | typedef typename base::update_task_type update_task_type; 30 | typedef typename base::update_function_type update_function_type; 31 | 32 | protected: 33 | 34 | 35 | typedef std::pair task_priority_pair; 36 | 37 | scheduler_type* scheduler; /// a pointer to the owning scheduler 38 | iengine_type* engine; 39 | bool buffering_enabled; 40 | std::vector< task_priority_pair > tasks; /// The collection of tasks inserted 41 | public: 42 | 43 | direct_callback(scheduler_type* scheduler = NULL, 44 | iengine_type* engine = NULL) : 45 | scheduler(scheduler), engine(engine), 46 | buffering_enabled(false) { } 47 | 48 | ~direct_callback() { } 49 | 50 | 51 | void set_engine(iengine_type* eng) { 52 | engine = eng; 53 | } 54 | 55 | void enable_buffering() { 56 | buffering_enabled = true; 57 | } 58 | 59 | 60 | void add_task(update_task_type task, double priority) { 61 | assert(task.function() != NULL); 62 | if (!buffering_enabled) { 63 | scheduler->add_task(task, priority); 64 | } else { 65 | tasks.push_back(task_priority_pair(task, priority)); 66 | } 67 | } 68 | 69 | void add_tasks(const std::vector &vertices, 70 | update_function_type func, 71 | double priority) { 72 | foreach(vertex_id_t vertex, vertices) { 73 | add_task(update_task_type(vertex, func), priority); 74 | } 75 | } 76 | 77 | 78 | int num_of_buffered_tasks() { 79 | return tasks.size(); 80 | } 81 | 82 | 83 | 84 | void commit() { 85 | if(buffering_enabled) { 86 | foreach(task_priority_pair tp, tasks) { 87 | scheduler->add_task(tp.first, tp.second); 88 | } 89 | tasks.clear(); 90 | } 91 | } 92 | 93 | void force_abort() { 94 | assert(engine != NULL); 95 | engine->stop(); 96 | } 97 | 98 | 99 | }; 100 | } 101 | 102 | #include 103 | 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /src/graphlab/serialization/oarchive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | /*************************************************************************** 7 | * Basic Serializers * 8 | ***************************************************************************/ 9 | // generate the operator<< call for a whole bunch of integer types 10 | #define GENCASTSERIALIZE(typesrc,typedest) \ 11 | oarchive& operator<<(oarchive& a, const typesrc i) { \ 12 | operator<<(a, static_cast(i)); \ 13 | return a; \ 14 | } 15 | 16 | #define GENINTSERIALIZE(typesrc) \ 17 | oarchive& operator<<(oarchive& a, const typesrc i) { \ 18 | serialize_64bit_integer(a, static_cast(i)); \ 19 | return a; \ 20 | } 21 | namespace graphlab { 22 | 23 | oarchive& operator<<(oarchive& a, const char i) { 24 | a.o->put(i); 25 | assert(!a.o->fail()); 26 | return a; 27 | } 28 | 29 | oarchive& serialize_64bit_integer(oarchive& a, const int64_t i) { 30 | a.o->write(reinterpret_cast(&i), sizeof(int64_t)); 31 | assert(!a.o->fail()); 32 | return a; 33 | } 34 | 35 | oarchive& operator<<(oarchive& a,const float i) { 36 | a.o->write(reinterpret_cast(&i), sizeof(float)); 37 | assert(!a.o->fail()); 38 | return a; 39 | } 40 | 41 | oarchive& operator<<(oarchive& a,const double i) { 42 | a.o->write(reinterpret_cast(&i), sizeof(double)); 43 | assert(!a.o->fail()); 44 | return a; 45 | } 46 | 47 | GENCASTSERIALIZE(bool, char); 48 | GENCASTSERIALIZE(unsigned char, char); 49 | GENINTSERIALIZE(short); 50 | GENINTSERIALIZE(unsigned short); 51 | GENINTSERIALIZE(int); 52 | GENINTSERIALIZE(long); 53 | GENINTSERIALIZE(long long); 54 | GENINTSERIALIZE(unsigned long); 55 | GENINTSERIALIZE(unsigned int); 56 | GENINTSERIALIZE(unsigned long long); 57 | //GENCASTSERIALIZE(size_t, int64_t); 58 | 59 | oarchive& serialize(oarchive& a, const void* i,const size_t length) { 60 | // save the length 61 | operator<<(a,length); 62 | a.o->write(reinterpret_cast(i), length); 63 | assert(!a.o->fail()); 64 | return a; 65 | } 66 | 67 | oarchive& operator<<(oarchive& a, const char* s) { 68 | // save the length 69 | size_t length = strlen(s); 70 | operator<<(a,length); 71 | a.o->write(reinterpret_cast(s), length); 72 | assert(!a.o->fail()); 73 | return a; 74 | } 75 | 76 | oarchive& operator<<(oarchive& a, const std::string& s){ 77 | // if we can't serialize the length, return immediately 78 | size_t length = s.length(); 79 | a << length; 80 | a.o->write(reinterpret_cast(s.c_str()), length); 81 | assert(!a.o->fail()); 82 | return a; 83 | } 84 | 85 | oarchive& operator<<(oarchive& a, void* const t) { 86 | std::cerr << "serializing void*" << std::endl; 87 | a << (size_t)(t); 88 | return a; 89 | } 90 | } // namespace prl 91 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/set_scheduler/set_scheduler.cpp: -------------------------------------------------------------------------------- 1 | 2 | // #include 3 | // #include 4 | // #include 5 | 6 | // #include 7 | // #include 8 | // #include 9 | // #include 10 | // #include 11 | // #include 12 | // #include 13 | // #include 14 | // #include 15 | // #include 16 | // #include 17 | // #include 18 | // #include 19 | // #include 20 | 21 | 22 | // namespace graphlab { 23 | // bool set_scheduler::get_task_from_active_set(size_t cpuid, update_task &ret_task) { 24 | // if (activeset == -1) return false; 25 | 26 | // int localactiveset = activeset; 27 | 28 | // if (localactiveset == -1) { 29 | // return false; 30 | // } 31 | // if (vertexsets[localactiveset]->next(nextschedpos[cpuid], cpuid) == false) { 32 | // return false; 33 | // } 34 | // size_t tmp = nextschedpos[cpuid]; 35 | // ret_task = update_task(tmp, schedupdate); 36 | // return true; 37 | // } 38 | 39 | // void set_scheduler::init() { 40 | // ss_set_type allvertices; 41 | // for (size_t i = 0; i < g.num_vertices(); ++i) { 42 | // ss_insert(allvertices, i); 43 | // } 44 | // static ss_set_type unused; 45 | // rootset.rebuild(NULL, allvertices); 46 | // rootset.resolve_event_handlers(); 47 | // rootset.set_as_root_set(); 48 | // rootsetevents = rootset.all_dependent_events(); 49 | // logger(LOG_INFO, "Set Scheduler Initialization Complete"); 50 | // logger(LOG_INFO, "Set Scheduler Active Event Set: %d", rootsetevents); 51 | // startschedule->wait(); 52 | // } 53 | 54 | 55 | // void set_scheduler::wait() { 56 | 57 | // schedposlock.lock(); 58 | // while(1) { 59 | // if ((activeset == -1 || vertexsets[activeset]->size() == 0) && 60 | // pendingtaskctr.value == 0 && 61 | // executedtaskctr.value == finishedtaskctr.value && 62 | // (cureplan == NULL || cureplan->done())) { 63 | // break; 64 | // } 65 | // schedposcond.wait(schedposlock); 66 | // } 67 | // schedposlock.unlock(); 68 | 69 | // } 70 | 71 | // void set_scheduler::begin_schedule(schedule_function s) { 72 | // executing = false; 73 | // complete = false; 74 | // size_t nschedulethreads = 1; 75 | // // startbarrier = new graphlab::barrier(nschedulethreads); 76 | // worker.resize(nschedulethreads); 77 | // for (size_t i = 0; i < nschedulethreads; ++i) { 78 | // worker[i].func = s; 79 | // worker[i].parent = this; 80 | // scheduling_thread.launch(&worker[i]); 81 | // } 82 | // startschedule->wait(); 83 | // } 84 | 85 | 86 | // }; //end of namespace 87 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/mutil.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutil.c 3 | * 4 | * This file contains various utility functions for the MOC portion of the 5 | * code 6 | * 7 | * Started 2/15/98 8 | * George 9 | * 10 | * $Id: mutil.c,v 1.2 2002/08/10 06:29:33 karypis Exp $ 11 | * 12 | */ 13 | 14 | #include 15 | 16 | 17 | /************************************************************************* 18 | * This function checks if the vertex weights of two vertices are below 19 | * a given set of values 20 | **************************************************************************/ 21 | idxtype AreAllVwgtsBelow(idxtype ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit) 22 | { 23 | idxtype i; 24 | 25 | for (i=0; i limit) 27 | return 0; 28 | 29 | return 1; 30 | } 31 | 32 | 33 | /************************************************************************* 34 | * This function checks if the vertex weights of two vertices are below 35 | * a given set of values 36 | **************************************************************************/ 37 | idxtype AreAnyVwgtsBelow(idxtype ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit) 38 | { 39 | idxtype i; 40 | 41 | for (i=0; i max) 79 | max = npwgts[j*ncon+i]; 80 | } 81 | if (max*nparts > lb) 82 | lb = max*nparts; 83 | } 84 | 85 | return lb; 86 | } 87 | 88 | /************************************************************************* 89 | * This function checks if the vertex weights of two vertices are below 90 | * a given set of values 91 | **************************************************************************/ 92 | idxtype AreAllBelow(idxtype ncon, float *v1, float *v2) 93 | { 94 | idxtype i; 95 | 96 | for (i=0; i v2[i]) 98 | return 0; 99 | 100 | return 1; 101 | } 102 | -------------------------------------------------------------------------------- /src/graphlab/scope/general_scope.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_GENERAL_SCOPE_HPP 2 | #define GRAPHLAB_GENERAL_SCOPE_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | 11 | namespace graphlab { 12 | template class general_scope_factory; 13 | 14 | /** 15 | * This defines a general scope type 16 | */ 17 | template 18 | class general_scope : 19 | public iscope { 20 | public: 21 | typedef iscope base; 22 | typedef typename Graph::vertex_data_type vertex_data_type; 23 | typedef typename Graph::edge_data_type edge_data_type; 24 | 25 | using base::_vertex; 26 | using base::_graph_ptr; 27 | 28 | scope_range::scope_range_enum stype; 29 | iscope_factory* factory; 30 | public: 31 | general_scope() : 32 | base(NULL,NULL) { } 33 | 34 | general_scope(Graph* graph_ptr, vertex_id_t vertex, 35 | iscope_factory* factory, 36 | scope_range::scope_range_enum s = scope_range::USE_DEFAULT) : 37 | base(graph_ptr, vertex), stype(s), factory(factory) { 38 | } 39 | 40 | scope_range::scope_range_enum scope_type() const { 41 | return stype; 42 | } 43 | 44 | ~general_scope() { } 45 | 46 | void commit() {} 47 | 48 | 49 | void init(Graph* graph, vertex_id_t vertex) { 50 | base::_graph_ptr = graph; 51 | base::_vertex = vertex; 52 | } 53 | 54 | vertex_data_type& vertex_data() { 55 | return (_graph_ptr->vertex_data(_vertex)); 56 | } 57 | 58 | 59 | const vertex_data_type& vertex_data() const { 60 | return const_vertex_data(); 61 | } 62 | 63 | const vertex_data_type& const_vertex_data() const { 64 | return (_graph_ptr->vertex_data(_vertex)); 65 | } 66 | 67 | /// Direct calls to access edge data 68 | const edge_data_type& edge_data(edge_id_t eid) const { 69 | return const_edge_data(eid); 70 | } 71 | 72 | const edge_data_type& const_edge_data(edge_id_t eid) const { 73 | return (_graph_ptr->edge_data(eid)); 74 | } 75 | 76 | edge_data_type& edge_data(edge_id_t eid) { 77 | return (_graph_ptr->edge_data(eid)); 78 | } 79 | 80 | 81 | const vertex_data_type& neighbor_vertex_data(vertex_id_t vertex) const { 82 | return const_neighbor_vertex_data(vertex); 83 | } 84 | 85 | 86 | const vertex_data_type& const_neighbor_vertex_data(vertex_id_t vertex) const { 87 | return _graph_ptr->vertex_data(vertex); 88 | } 89 | 90 | // warning. Guarantee free! 91 | vertex_data_type& neighbor_vertex_data(vertex_id_t vertex) { 92 | return _graph_ptr->vertex_data(vertex); 93 | } 94 | 95 | bool experimental_scope_upgrade(scope_range::scope_range_enum newrange) { 96 | assert(factory != NULL); 97 | factory->release_scope(this); 98 | ASSERT_TRUE(factory->get_scope(thread::thread_id(),base::_vertex,newrange) == this); 99 | stype = newrange; 100 | return true; 101 | } 102 | 103 | friend class general_scope_factory; 104 | }; // end of ext_locked_scope 105 | 106 | } // end of graphlab namespace 107 | 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/GKlib/b64.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file b64.c 3 | \brief This file contains some simple 8bit-to-6bit encoding/deconding routines 4 | 5 | Most of these routines are outdated and should be converted using glibc's equivalent 6 | routines. 7 | 8 | \date Started 2/22/05 9 | \author George 10 | \version\verbatim $Id: b64.c 1421 2007-04-06 14:37:41Z karypis $ \endverbatim 11 | */ 12 | 13 | 14 | #include 15 | 16 | #define B64OFFSET 48 /* This is the '0' number */ 17 | 18 | 19 | 20 | /****************************************************************************** 21 | * Encode 3 '8-bit' binary bytes as 4 '6-bit' characters 22 | *******************************************************************************/ 23 | void encodeblock(unsigned char *in, unsigned char *out) 24 | { 25 | out[0] = (in[0] >> 2); 26 | out[1] = (((in[0] & 0x03) << 4) | (in[1] >> 4)); 27 | out[2] = (((in[1] & 0x0f) << 2) | (in[2] >> 6)); 28 | out[3] = (in[2] & 0x3f); 29 | 30 | out[0] += B64OFFSET; 31 | out[1] += B64OFFSET; 32 | out[2] += B64OFFSET; 33 | out[3] += B64OFFSET; 34 | 35 | // printf("%c %c %c %c %2x %2x %2x %2x %2x %2x %2x\n", out[0], out[1], out[2], out[3], out[0], out[1], out[2], out[3], in[0], in[1], in[2]); 36 | } 37 | 38 | /****************************************************************************** 39 | * Decode 4 '6-bit' characters into 3 '8-bit' binary bytes 40 | *******************************************************************************/ 41 | void decodeblock(unsigned char *in, unsigned char *out) 42 | { 43 | in[0] -= B64OFFSET; 44 | in[1] -= B64OFFSET; 45 | in[2] -= B64OFFSET; 46 | in[3] -= B64OFFSET; 47 | 48 | out[0] = (in[0] << 2 | in[1] >> 4); 49 | out[1] = (in[1] << 4 | in[2] >> 2); 50 | out[2] = (in[2] << 6 | in[3]); 51 | } 52 | 53 | 54 | /****************************************************************************** 55 | * This function encodes an input array of bytes into a base64 encoding. Memory 56 | * for the output array is assumed to have been allocated by the calling program 57 | * and be sufficiently large. The output string is NULL terminated. 58 | *******************************************************************************/ 59 | void GKEncodeBase64(int nbytes, unsigned char *inbuffer, unsigned char *outbuffer) 60 | { 61 | int i, j; 62 | 63 | if (nbytes%3 != 0) 64 | gk_errexit(SIGERR, "GKEncodeBase64: Input buffer size should be a multiple of 3! (%d)\n", nbytes); 65 | 66 | for (j=0, i=0; i 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | namespace graphlab { 20 | 21 | 22 | 23 | /** 24 | * \brief The shared data interface 25 | * 26 | * Often in a graphlab program there is data (constant and mutable) 27 | * that cannot be directly expressed in the graph. Typical forms of 28 | * shared data may be counters or global statistics that evolve over 29 | * time. The ishared_data class describes the interface given to 30 | * each update function that can be used to read and modify the 31 | * global shared data. 32 | * 33 | */ 34 | template 35 | class ishared_data { 36 | public: 37 | typedef Graph graph_type; 38 | typedef typename Graph::vertex_data_type vertex_data_type; 39 | typedef iscope iscope_type; 40 | typedef iscope_factory iscope_factory_type; 41 | 42 | typedef void(*sync_function_type)(size_t index, 43 | const ishared_data& shared_data, 44 | iscope_type& scope, 45 | any& accumulator); 46 | 47 | typedef void(*apply_function_type)(size_t index, 48 | const ishared_data& shared_data, 49 | any& current_data, 50 | const any& new_data); 51 | 52 | typedef void(*merge_function_type)(size_t index, 53 | const ishared_data& shared_data, 54 | any& merge_dest, 55 | const any& merge_src); 56 | 57 | 58 | public: 59 | 60 | // Virtual Functions 61 | // ======================================================> 62 | 63 | /** This is used to manage constants */ 64 | virtual const any& get_constant(size_t index) const = 0; 65 | 66 | /** Return the shared data at the specific location. 67 | In the distributed setting. This value could be slightly outdated*/ 68 | virtual any get(size_t index) const = 0; 69 | 70 | 71 | /** Return the shared data at the specific location */ 72 | virtual any atomic_get(size_t index) const = 0; 73 | 74 | /** Atomically sets the shared data at the specific location */ 75 | virtual void atomic_set(size_t index, const any& data) = 0; 76 | 77 | /** Atomically sets the shared data at the specific location */ 78 | virtual any atomic_exchange(size_t index, const any& data) = 0; 79 | 80 | 81 | /** Atomically applies the function to the shared data with the 82 | provided closure. The application is done eventually */ 83 | virtual void atomic_apply(size_t index, 84 | apply_function_type fun, 85 | const any& closure) = 0; 86 | 87 | virtual void trigger_sync(size_t index) = 0; 88 | virtual void trigger_sync_all() = 0; 89 | }; 90 | 91 | 92 | 93 | }; // end of namespace graphlab 94 | 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/mrkmetis.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * mrkmetis.c 5 | * 6 | * This file contains the top level routines for the multilevel k-way partitioning 7 | * algorithm KMETIS. 8 | * 9 | * Started 7/28/97 10 | * George 11 | * 12 | * $Id: mrkmetis.c,v 1.2 2003/04/04 23:25:10 karypis Exp $ 13 | * 14 | */ 15 | 16 | #include 17 | 18 | 19 | 20 | /************************************************************************* 21 | * This function is the entry point for KWMETIS 22 | **************************************************************************/ 23 | void METIS_mCRefineGraphKway(idxtype *nvtxs, idxtype *ncon, idxtype *xadj, idxtype *adjncy, 24 | idxtype *vwgt, idxtype *adjwgt, idxtype *wgtflag, idxtype *numflag, 25 | idxtype *nparts, float *rubvec, idxtype *options, idxtype *edgecut, 26 | idxtype *part) 27 | { 28 | idxtype i, j; 29 | GraphType graph; 30 | CtrlType ctrl; 31 | 32 | if (*numflag == 1) 33 | Change2CNumbering(*nvtxs, xadj, adjncy); 34 | 35 | SetUpGraph(&graph, OP_KMETIS, *nvtxs, *ncon, xadj, adjncy, vwgt, adjwgt, *wgtflag); 36 | 37 | if (options[0] == 0) { /* Use the default parameters */ 38 | ctrl.CType = McKMETIS_CTYPE; 39 | ctrl.IType = McKMETIS_ITYPE; 40 | ctrl.RType = McKMETIS_RTYPE; 41 | ctrl.dbglvl = McKMETIS_DBGLVL; 42 | } 43 | else { 44 | ctrl.CType = options[OPTION_CTYPE]; 45 | ctrl.IType = options[OPTION_ITYPE]; 46 | ctrl.RType = options[OPTION_RTYPE]; 47 | ctrl.dbglvl = options[OPTION_DBGLVL]; 48 | } 49 | ctrl.optype = OP_KMETIS; 50 | ctrl.CoarsenTo = amax((*nvtxs)/(20*gk_log2(*nparts)), 30*(*nparts)); 51 | ctrl.nmaxvwgt = 0.0; /* GK-MOD: Ensure that no coarsening will take place */ 52 | 53 | InitRandom(-1); 54 | 55 | AllocateWorkSpace(&ctrl, &graph, *nparts); 56 | 57 | IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); 58 | IFSET(ctrl.dbglvl, DBG_TIME, gk_startcputimer(ctrl.TotalTmr)); 59 | 60 | *edgecut = MCMlevelKWayRefinement(&ctrl, &graph, *nparts, part, rubvec); 61 | 62 | IFSET(ctrl.dbglvl, DBG_TIME, gk_stopcputimer(ctrl.TotalTmr)); 63 | IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); 64 | 65 | FreeWorkSpace(&ctrl, &graph); 66 | 67 | if (*numflag == 1) 68 | Change2FNumbering(*nvtxs, xadj, adjncy, part); 69 | } 70 | 71 | 72 | /************************************************************************* 73 | * This function takes a graph and produces a bisection of it 74 | **************************************************************************/ 75 | idxtype MCMlevelKWayRefinement(CtrlType *ctrl, GraphType *graph, idxtype nparts, idxtype *part, 76 | float *rubvec) 77 | { 78 | idxtype i, j, nvtxs; 79 | GraphType *cgraph; 80 | idxtype options[10], edgecut; 81 | 82 | cgraph = MCCoarsen2Way(ctrl, graph); 83 | 84 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->InitPartTmr)); 85 | MocAllocateKWayPartitionMemory(ctrl, cgraph, nparts); 86 | 87 | if (cgraph->nvtxs != graph->nvtxs) 88 | errexit("GK-MOD Failed: %d %d\n", cgraph->nvtxs, graph->nvtxs); 89 | 90 | for (i=0; invtxs; i++) 91 | cgraph->where[graph->cmap[i]] = part[i]; 92 | 93 | MocRefineKWayHorizontal(ctrl, graph, cgraph, nparts, rubvec); 94 | 95 | idxcopy(graph->nvtxs, graph->where, part); 96 | 97 | FreeGraph(graph, 0); 98 | 99 | return graph->mincut; 100 | 101 | } 102 | 103 | -------------------------------------------------------------------------------- /src/graphlab/distributed/distributed_scope.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DISTRIBUTED_SCOPE_HPP 2 | #define DISTRIBUTED_SCOPE_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | 11 | #include 12 | namespace graphlab { 13 | 14 | 15 | 16 | template 17 | class distributed_scope: public iscope { 18 | public: 19 | typedef iscope base; 20 | typedef typename Graph::vertex_data_type vertex_data_type; 21 | typedef typename Graph::edge_data_type edge_data_type; 22 | 23 | using base::_vertex; 24 | using base::_graph_ptr; 25 | DLockManager &lock_manager; 26 | scope_range::scope_range_enum stype; 27 | size_t deferred_lock_id; 28 | public: 29 | distributed_scope(DLockManager &lock_manager) : 30 | base(NULL,-1), 31 | lock_manager(lock_manager), 32 | stype(scope_range::USE_DEFAULT), 33 | deferred_lock_id(-1) { } 34 | 35 | ~distributed_scope() { } 36 | 37 | void commit() { 38 | if (deferred_lock_id != size_t(-1)) { 39 | lock_manager.release(deferred_lock_id); 40 | } 41 | deferred_lock_id = -1; 42 | } 43 | /** 44 | Called only when the deferred lock has been acquired 45 | */ 46 | void init(Graph* graph, vertex_id_t vertex, size_t deferred_lock = -1) { 47 | base::_graph_ptr = graph; 48 | base::_vertex = vertex; 49 | deferred_lock_id = deferred_lock; 50 | } 51 | 52 | vertex_data_type& vertex_data() { 53 | return lock_manager.get_vertex(base::_vertex); 54 | } 55 | 56 | 57 | const vertex_data_type& vertex_data() const { 58 | return lock_manager.get_const_vertex(base::_vertex); 59 | } 60 | 61 | const vertex_data_type& const_vertex_data() const { 62 | return lock_manager.get_const_vertex(base::_vertex); 63 | } 64 | 65 | /// Direct calls to access edge data 66 | const edge_data_type& edge_data(edge_id_t eid) const { 67 | // TODO: remove this... relies on graph partitioning assumptions. 68 | // if (base::_graph_ptr->has_constant_edges()) return base::_graph_ptr->edge_data(eid); 69 | return lock_manager.get_const_edge(eid); 70 | } 71 | 72 | /// Direct calls to access edge data 73 | const edge_data_type& const_edge_data(edge_id_t eid) const { 74 | // TODO: remove this... relies on graph partitioning assumptions. 75 | //if (base::_graph_ptr->has_constant_edges()) return base::_graph_ptr->edge_data(eid); 76 | return lock_manager.get_const_edge(eid); 77 | } 78 | 79 | edge_data_type& edge_data(edge_id_t eid) { 80 | // TODO: remove this... relies on graph partitioning assumptions. 81 | //if (base::_graph_ptr->has_constant_edges()) return base::_graph_ptr->edge_data(eid); 82 | return lock_manager.get_edge(eid); 83 | } 84 | 85 | 86 | const vertex_data_type& neighbor_vertex_data(vertex_id_t vertex) const { 87 | return lock_manager.get_const_vertex(vertex); 88 | } 89 | 90 | const vertex_data_type& const_neighbor_vertex_data(vertex_id_t vertex) const { 91 | return lock_manager.get_const_vertex(vertex); 92 | } 93 | 94 | // warning. Guarantee free! 95 | vertex_data_type& neighbor_vertex_data(vertex_id_t vertex) { 96 | return lock_manager.get_vertex(vertex); 97 | } 98 | }; // end of distributed_scope 99 | 100 | } // end of namespace 101 | #include 102 | 103 | 104 | #endif -------------------------------------------------------------------------------- /src/graphlab/serialization/iarchive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace graphlab { 5 | 6 | /*************************************************************************** 7 | * Basic Deserializers * 8 | ***************************************************************************/ 9 | 10 | // generate the serialize call for a whole bunch of integer types 11 | #define GENCASTDESERIALIZE(typesrc, typedest) \ 12 | iarchive& operator>>(iarchive &a, typesrc &i) { \ 13 | typedest c; \ 14 | operator>>(a, c); \ 15 | i = static_cast(c); \ 16 | return a; \ 17 | } 18 | 19 | #define GENINTDESERIALIZE(typesrc) \ 20 | iarchive& operator>>(iarchive &a, typesrc &i) { \ 21 | int64_t c; \ 22 | deserialize_64bit_integer(a, c); \ 23 | i = static_cast(c); \ 24 | return a; \ 25 | } 26 | 27 | iarchive& operator>>(iarchive& a, char& i) { 28 | a.i->get(i); 29 | assert(!a.i->fail()); 30 | return a; 31 | } 32 | 33 | iarchive& deserialize_64bit_integer(iarchive& a, int64_t& i) { 34 | a.i->read(reinterpret_cast(&i), sizeof(int64_t)); 35 | assert(!a.i->fail()); 36 | return a; 37 | } 38 | 39 | 40 | GENCASTDESERIALIZE(bool, char); 41 | GENCASTDESERIALIZE(unsigned char, char); 42 | // serializes a bunch of integer types 43 | GENINTDESERIALIZE(short); 44 | GENINTDESERIALIZE(unsigned short); 45 | GENINTDESERIALIZE(int); 46 | GENINTDESERIALIZE(long); 47 | GENINTDESERIALIZE(long long); 48 | GENINTDESERIALIZE(unsigned long); 49 | GENINTDESERIALIZE(unsigned int); 50 | GENINTDESERIALIZE(unsigned long long); 51 | 52 | 53 | iarchive& operator>>(iarchive& a, float& i) { 54 | a.i->read(reinterpret_cast(&i), sizeof(float)); 55 | assert(!a.i->fail()); 56 | return a; 57 | } 58 | 59 | iarchive& operator>>(iarchive& a, double& i) { 60 | a.i->read(reinterpret_cast(&i), sizeof(double)); 61 | assert(!a.i->fail()); 62 | return a; 63 | } 64 | 65 | iarchive& deserialize(iarchive& a, void* const i,const size_t length) { 66 | // Save the length and check if lengths match 67 | size_t length2; 68 | operator>>(a, length2); 69 | assert(length == length2); 70 | 71 | //operator>> the rest 72 | a.i->read(reinterpret_cast(i), length); 73 | assert(!a.i->fail()); 74 | return a; 75 | } 76 | 77 | iarchive& operator>>(iarchive& a, char*& s) { 78 | // Save the length and check if lengths match 79 | size_t length; 80 | operator>>(a, length); 81 | if (s == NULL) s = new char[length+1]; 82 | //operator>> the rest 83 | a.i->read(reinterpret_cast(s), length); 84 | s[length] = 0; 85 | assert(!a.i->fail()); 86 | return a; 87 | } 88 | 89 | iarchive& operator>>(iarchive& a, std::string& s){ 90 | //read the length 91 | size_t length; 92 | a >> length; 93 | //resize the string and read the characters 94 | s.resize(length); 95 | a.i->read(const_cast(s.c_str()), length); 96 | assert(!a.i->fail()); 97 | return a; 98 | } 99 | 100 | 101 | iarchive& operator>>(iarchive& a, void* &t) { 102 | size_t tmp; 103 | a >> tmp; 104 | t = (void*)tmp; 105 | return a; 106 | } 107 | } // namespace prl 108 | 109 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/support/binary_vertex_task_set.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BINARY_VERTEX_TASK_SET 2 | #define BINARY_VERTEX_TASK_SET 3 | 4 | 5 | /** 6 | * \file Simple task set that only keeps record of whether 7 | * function was scheduled for given vertex. 8 | **/ 9 | 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace graphlab { 18 | 19 | template 20 | class binary_vertex_task_set { 21 | public: 22 | typedef Graph graph_type; 23 | typedef update_task update_task_type; 24 | typedef typename update_task_type::update_function_type 25 | update_function_type; 26 | 27 | 28 | 29 | std::vector vertexbits; 30 | std::vector updatefuncs; 31 | size_t num_of_updatefunctions; 32 | spinlock updflock; 33 | 34 | const static size_t MAX_UPDATEFUNCTIONS; 35 | 36 | public: 37 | 38 | binary_vertex_task_set(size_t numvertices) : 39 | vertexbits(numvertices, 0), 40 | updatefuncs(MAX_UPDATEFUNCTIONS, 0), 41 | num_of_updatefunctions(0) { 42 | // std::cout << "Constructed for " << numvertices 43 | // << " vertices" << std::endl; 44 | } 45 | 46 | 47 | bool get(const update_task_type& task) { 48 | update_function_type func = task.function(); 49 | vertex_id_t vid = task.vertex(); 50 | size_t mask = get_update_func_mask(func); 51 | return ((vertexbits[vid] & mask) != 0); 52 | } 53 | 54 | bool add(const update_task_type& task) { 55 | update_function_type func = task.function(); 56 | vertex_id_t vid = task.vertex(); 57 | size_t mask = get_update_func_mask(func); 58 | if ((vertexbits[vid] & mask) == 0) { 59 | size_t before = __sync_fetch_and_or(&vertexbits[vid], mask); 60 | return (before & mask) == 0; // did someone else already set the bit 61 | } 62 | return false; 63 | } 64 | 65 | void remove(const update_task_type& task) { 66 | update_function_type func = task.function(); 67 | vertex_id_t vid = task.vertex(); 68 | size_t mask = get_update_func_mask(func); 69 | 70 | // Set bit for this function to 0 71 | __sync_fetch_and_and(&vertexbits[vid], ~mask); 72 | } 73 | 74 | size_t pop_all_tasks(size_t vid) { 75 | size_t val = __sync_lock_test_and_set(&vertexbits[vid], 0); 76 | return val; 77 | } 78 | 79 | private: 80 | size_t get_update_func_mask(update_function_type upf) { 81 | for(size_t i = 0; i < num_of_updatefunctions; i++ ){ 82 | if (updatefuncs[i] == upf) return 1< 109 | const size_t binary_vertex_task_set::MAX_UPDATEFUNCTIONS = 110 | sizeof(size_t) * 8; 111 | 112 | } 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/checkgraph.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * checkgraph.c 5 | * 6 | * This file contains routines related to I/O 7 | * 8 | * Started 8/28/94 9 | * George 10 | * 11 | */ 12 | 13 | #include 14 | 15 | 16 | 17 | /************************************************************************* 18 | * This function checks if a graph is valid 19 | **************************************************************************/ 20 | idxtype CheckGraph(GraphType *graph) 21 | { 22 | idxtype i, j, k, l; 23 | idxtype nvtxs, ncon, err=0; 24 | idxtype minedge, maxedge, minewgt, maxewgt; 25 | float minvwgt[MAXNCON], maxvwgt[MAXNCON]; 26 | idxtype *xadj, *adjncy, *adjwgt, *htable; 27 | float *nvwgt, ntvwgts[MAXNCON]; 28 | 29 | nvtxs = graph->nvtxs; 30 | ncon = graph->ncon; 31 | xadj = graph->xadj; 32 | nvwgt = graph->nvwgt; 33 | adjncy = graph->adjncy; 34 | adjwgt = graph->adjwgt; 35 | 36 | htable = idxsmalloc(nvtxs, 0, "htable"); 37 | 38 | if (ncon > 1) { 39 | for (j=0; j 1) { 50 | for (j=0; j maxvwgt[j]) ? nvwgt[i*ncon+j] : maxvwgt[j]; 54 | } 55 | } 56 | 57 | for (j=xadj[i]; j maxedge) ? k : maxedge; 62 | minewgt = (adjwgt[j] < minewgt) ? adjwgt[j] : minewgt; 63 | maxewgt = (adjwgt[j] > maxewgt) ? adjwgt[j] : maxewgt; 64 | 65 | if (i == k) { 66 | mprintf("Vertex %D contains a self-loop (i.e., diagonal entry in the matrix)!\n", i); 67 | err++; 68 | } 69 | else { 70 | for (l=xadj[k]; l 1) { 100 | for (j=0; j 0.0001) { 102 | mprintf("Normalized vwgts don't sum to one. Weight %D = %.8f.\n", j, ntvwgts[j]); 103 | err++; 104 | } 105 | } 106 | } 107 | 108 | /* 109 | mprintf("errs: %D, adjncy: [%D %D], adjwgt: [%D %D]\n", 110 | err, minedge, maxedge, minewgt, maxewgt); 111 | if (ncon > 1) { 112 | for (j=0; j 0) { 119 | mprintf("A total of %D errors exist in the input file. Correct them, and run again!\n", err); 120 | } 121 | 122 | gk_free((void **)&htable, LTERM); 123 | return (err == 0 ? 1 : 0); 124 | } 125 | 126 | -------------------------------------------------------------------------------- /src/graphlab/shared_data/ishared_data_manager.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file Interface for shared data manager implementations. 3 | **/ 4 | 5 | #ifndef GRAPHLAB_ISHARED_DATA_MANAGER 6 | #define GRAPHLAB_ISHARED_DATA_MANAGER 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | namespace graphlab { 14 | 15 | template 16 | class ishared_data_manager : 17 | public ishared_data { 18 | 19 | public: 20 | typedef Graph graph_type; 21 | typedef ishared_data base; 22 | 23 | typedef typename base::iscope_type iscope_type; 24 | typedef typename base::iscope_factory_type iscope_factory_type; 25 | 26 | typedef typename base::sync_function_type sync_function_type; 27 | typedef typename base::apply_function_type apply_function_type; 28 | 29 | 30 | /** 31 | * \brief run sync on a particular field 32 | * 33 | * User code should not call this function and instead use the 34 | * sync which takes a graph argument. 35 | * 36 | * \todo this should be optimized 37 | */ 38 | virtual void sync(size_t index) = 0; 39 | 40 | /** 41 | * \brief Run the particular sync task using the graph data. 42 | * 43 | * This function should not be called by user code outside of the 44 | * graphlab engine. 45 | * 46 | * \todo this should be optimized 47 | * 48 | */ 49 | virtual void sync_all() = 0; 50 | 51 | 52 | /** 53 | * \brief Run the particular sync task using the graph data. 54 | * 55 | * This function can be called by user code outside of the 56 | * graphlab engine. 57 | * 58 | */ 59 | virtual void sync(Graph& graph, size_t index) = 0; 60 | 61 | 62 | /** 63 | * \brief Run all sync tasks using the graph data. 64 | * 65 | * This function can be called by user code outside of the 66 | * graphlab engine. 67 | * 68 | */ 69 | 70 | virtual void sync_all(Graph& graph) = 0; 71 | 72 | 73 | 74 | /** Notify that a sync may be needed on index */ 75 | virtual void signal(size_t index) = 0; 76 | virtual void signal_all() = 0; 77 | 78 | 79 | /** syncs as soon as possible */ 80 | virtual void trigger_sync(size_t index) = 0; 81 | virtual void trigger_sync_all() = 0; 82 | 83 | /* Note: only used by pushy engine (Added by Aapo 5/31/10) */ 84 | virtual void progress(size_t cpuid, iscope_type * scope) {} 85 | 86 | /** 87 | * \brief register a sync. 88 | * 89 | * If the sync_interval is 0 then the sync is never run in the 90 | * background. 91 | * vertices in the range [rangelow, rangehigh) will be executed. 92 | * (including rangelow, not including rangehigh) 93 | */ 94 | virtual void set_sync(size_t index, 95 | sync_function_type sync_fun, 96 | apply_function_type apply_fun, 97 | const any& zero, 98 | size_t sync_interval, 99 | size_t rangelow = 0, 100 | size_t rangehigh = -1) = 0; 101 | 102 | virtual void create_atomic(size_t index, const any& initial_value) = 0; 103 | 104 | 105 | /** Set the scpe factory, called by the engine */ 106 | virtual void set_scope_factory(iscope_factory_type* factory) = 0; 107 | 108 | /** Creates a constant value*/ 109 | virtual void set_constant(size_t index, const any& new_value) = 0; 110 | 111 | 112 | }; // end of class ishared data manager 113 | 114 | 115 | }; // end of graphlab namespace 116 | 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /src/graphlab/util/synchronized_unordered_map.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SYNCHRONIZED_UNORDERED_MAP 2 | #define SYNCHRONIZED_UNORDERED_MAP 3 | #include 4 | #include 5 | #include 6 | 7 | namespace graphlab { 8 | template 9 | class synchronized_unordered_map { 10 | public: 11 | typedef boost::unordered_map container; 12 | typedef typename container::iterator iterator; 13 | typedef typename container::const_iterator const_iterator; 14 | 15 | typedef std::pair datapointer; 16 | typedef std::pair const_datapointer; 17 | typedef Data value_type; 18 | typedef size_t key_type; 19 | 20 | private: 21 | std::vector data; 22 | std::vector lock; 23 | size_t nblocks; 24 | public: 25 | synchronized_unordered_map(size_t numblocks):data(numblocks), 26 | lock(numblocks), 27 | nblocks(numblocks) { 28 | for (size_t i = 0;i < numblocks; ++i) { 29 | data[i].max_load_factor(1.0); 30 | } 31 | } 32 | 33 | std::pair find(size_t key) { 34 | size_t b = key % nblocks; 35 | lock[b].readlock(); 36 | iterator iter = data[b].find(key); 37 | std::pair ret = std::make_pair(iter != data[b].end(), &(iter->second)); 38 | lock[b].rdunlock(); 39 | return ret; 40 | } 41 | 42 | /** 43 | return std::pair 44 | if not found, iterator is invalid 45 | */ 46 | std::pair find(size_t key) const { 47 | size_t b = key % nblocks; 48 | lock[b].readlock(); 49 | const_iterator iter = data[b].find(key); 50 | std::pair ret = std::make_pair(iter != data[b].end(), &(iter->second)); 51 | lock[b].rdunlock(); 52 | return ret; 53 | } 54 | 55 | // care must be taken that you do not access an erased iterator 56 | void erase(size_t key) { 57 | size_t b = key % nblocks; 58 | lock[b].writelock(); 59 | data[b].erase(key); 60 | lock[b].wrunlock(); 61 | } 62 | 63 | template 64 | void erase_if(size_t key, Predicate pred) { 65 | size_t b = key % nblocks; 66 | lock[b].writelock(); 67 | iterator iter = data[b].find(key); 68 | 69 | if (iter != data[b].end() && pred(iter->second)) data[b].erase(key); 70 | lock[b].wrunlock(); 71 | } 72 | 73 | value_type& insert(size_t key, const value_type &val) { 74 | size_t b = key % nblocks; 75 | lock[b].writelock(); 76 | data[b][key] = val; 77 | value_type& ret = data[b][key]; 78 | lock[b].wrunlock(); 79 | return ret; 80 | } 81 | 82 | /** 83 | returns std::pair 84 | on success, iterator will point to the entry 85 | on failure, iterator will point to an existing entry 86 | */ 87 | std::pair insert_with_failure_detect(size_t key, const value_type &val) { 88 | std::pair ret ; 89 | 90 | size_t b = key % nblocks; 91 | lock[b].writelock(); 92 | //search for it 93 | iterator iter = data[b].find(key); 94 | // if it not in the table, write and return 95 | if (iter == data[b].end()) { 96 | data[b][key] = val; 97 | ret = std::make_pair(true, &(data[b].find(key)->second)); 98 | } 99 | else { 100 | ret = std::make_pair(false, &(iter->second)); 101 | } 102 | lock[b].wrunlock(); 103 | return ret; 104 | } 105 | 106 | void clear() { 107 | for (size_t i = 0;i < data.size(); ++i) { 108 | data[i].clear(); 109 | } 110 | } 111 | }; 112 | } 113 | #endif -------------------------------------------------------------------------------- /src/graphlab/scope/synchronous_scope.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHLAB_SYNCHRONOUS_SCOPE_HPP 2 | #define GRAPHLAB_SYNCHRONOUS_SCOPE_HPP 3 | 4 | #include 5 | 6 | 7 | #include 8 | 9 | 10 | namespace graphlab { 11 | 12 | /** 13 | * This defines a scope type which is meant for "synchronous" type of 14 | * algorithms. This type of scope should only be used by synchronous_engine 15 | */ 16 | template 17 | class synchronous_scope : 18 | public iscope { 19 | public: 20 | typedef iscope base; 21 | typedef typename Graph::vertex_data_type vertex_data_type; 22 | typedef typename Graph::edge_data_type edge_data_type; 23 | 24 | using base::_vertex; 25 | using base::_graph_ptr; 26 | 27 | public: 28 | synchronous_scope() : base(NULL,0) { } 29 | 30 | // TODO: Why 3 graph arguments? 31 | synchronous_scope(Graph* srcgraph, Graph* destgraph, 32 | Graph* vertexdatagraph, 33 | vertex_id_t vertex) : 34 | base(srcgraph, vertex) { 35 | _srcgraph = srcgraph; 36 | _destgraph = destgraph; 37 | _vertexdatagraph = vertexdatagraph; 38 | } 39 | 40 | 41 | ~synchronous_scope() { } 42 | 43 | void commit() {}; 44 | 45 | void init(Graph* srcgraph, 46 | Graph* destgraph, 47 | Graph* vertexdatagraph, vertex_id_t vertex) { 48 | base::_graph_ptr = srcgraph; 49 | base::_vertex = vertex; 50 | _srcgraph = srcgraph; 51 | _destgraph = destgraph; 52 | _vertexdatagraph = vertexdatagraph; 53 | } 54 | 55 | /// Returns the data on the base vertex 56 | vertex_data_type& vertex_data() { 57 | return (_vertexdatagraph->vertex_data( _vertex )); 58 | } 59 | 60 | const vertex_data_type& vertex_data() const { 61 | return const_vertex_data(); 62 | } 63 | 64 | const vertex_data_type& const_vertex_data() const { 65 | return (_vertexdatagraph->vertex_data( _vertex )); 66 | } 67 | 68 | /// Direct calls to access edge data 69 | const edge_data_type& edge_data(edge_id_t eid) const { 70 | return const_edge_data(eid); 71 | } 72 | 73 | /// Direct calls to access edge data 74 | const edge_data_type& const_edge_data(edge_id_t eid) const { 75 | // TODO: make sure edge is associated with this vertex 76 | if (_srcgraph->target(eid) == _vertex ) { 77 | // in edge 78 | return (_srcgraph->edge_data(eid)); 79 | } else { 80 | // outedge 81 | return (_destgraph->edge_data(eid)); 82 | } 83 | } 84 | 85 | edge_data_type& edge_data(edge_id_t eid) { 86 | // TODO: make sure edge is associated with this vertex 87 | if (_srcgraph->target(eid) == _vertex) { 88 | // in edge 89 | return (_srcgraph->edge_data(eid)); 90 | } else { 91 | // outedge 92 | return (_destgraph->edge_data(eid)); 93 | } 94 | } 95 | 96 | const vertex_data_type& neighbor_vertex_data(vertex_id_t vertex) const { 97 | return const_neighbor_vertex_data(vertex); 98 | } 99 | 100 | const vertex_data_type& const_neighbor_vertex_data(vertex_id_t vertex) const { 101 | return _srcgraph->vertex_data(vertex); 102 | } 103 | 104 | vertex_data_type& neighbor_vertex_data(vertex_id_t vertex) { 105 | // this totally does not make sense for synchronous execution 106 | assert(false); 107 | return _srcgraph->vertex_data(vertex); 108 | } 109 | 110 | 111 | 112 | private: 113 | Graph* _srcgraph; 114 | Graph* _destgraph; 115 | Graph* _vertexdatagraph; 116 | }; // end of synchronous_scope 117 | 118 | } // end of graphlab namespace 119 | 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /src/graphlab/engine/engine_options.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ENGINE_OPTIONS_HPP 2 | #define ENGINE_OPTIONS_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace graphlab { 9 | 10 | 11 | /** 12 | * The engine options class is really a simple struct that contains 13 | * the basic options needed to create an engine. These options 14 | * include: 15 | 16 |
    17 | 18 |
  • size_t ncpus: The number of cpus (threads) to use for this 19 | engine.
  • 20 | 21 |
  • std::string engine_type: The type of engine to use. Currently 22 | we support {async, async_sim, synchronous}.
  • 23 | 24 |
  • std::string scope_type: The type of locking protocol (scope) 25 | to use. Currently we support {none, vertex, edge, full}.
  • 26 | 27 |
  • std::string scheduler_type: The type of scheduler to user. 28 | Currently we support a wide range of schedulers: {synchronous, 29 | fifo, priority, sampling, splash, sweep, multiqueue_fifo, 30 | multiqueue_priority, set, clustered_priority, round_robin, 31 | colored}
  • 32 | 33 |
  • size_t splash_size: The size parameter for the splash 34 | scheduler.
  • 35 |
36 | */ 37 | struct engine_options { 38 | //! The number of cpus 39 | size_t ncpus; 40 | //! The type of engine {async, async_sim, synchronous} 41 | std::string engine_type; 42 | //! The type of scope 43 | std::string scope_type; 44 | //! The type of scheduler to use 45 | std::string scheduler_type; 46 | //! The compiler flags 47 | std::string compile_flags; 48 | 49 | 50 | engine_options() : 51 | ncpus(2), 52 | engine_type("async"), 53 | scope_type("edge"), 54 | scheduler_type("fifo") { 55 | // Grab all the compiler flags 56 | #ifdef COMPILEFLAGS 57 | #define QUOTEME_(x) #x 58 | #define QUOTEME(x) QUOTEME_(x) 59 | compile_flags = QUOTEME(COMPILEFLAGS); 60 | #undef QUOTEME 61 | #undef QUOTEME_ 62 | #endif 63 | } // end of constructor 64 | 65 | 66 | /** 67 | * create an engine for the given graph using the engine options. 68 | * If the engine options are not set correctly this will return 69 | * NULL. 70 | */ 71 | template 72 | iengine* create_engine(Graph& graph) { 73 | iengine* eng = 74 | engine_factory::new_engine(engine_type, 75 | scheduler_type, 76 | scope_type, 77 | graph, 78 | ncpus); 79 | return eng; 80 | } 81 | 82 | 83 | /** 84 | * Display the current engine options 85 | */ 86 | virtual void print() const { 87 | std::cout << "GraphLab Options -------------------\n" 88 | << "ncpus: " << ncpus << "\n" 89 | << "engine: " << engine_type << "\n" 90 | << "scope: " << scope_type << "\n" 91 | << "scheduler: " << scheduler_type << std::endl; 92 | } 93 | 94 | 95 | 96 | /** 97 | * Save the engine options to a serialized archive 98 | */ 99 | void save(oarchive& arc) const { 100 | arc << ncpus 101 | << engine_type 102 | << scope_type 103 | << scheduler_type 104 | << compile_flags; 105 | } // end of save 106 | 107 | 108 | /** 109 | * Load the engine options from a serialized archive 110 | */ 111 | void load(iarchive& arc) { 112 | arc >> ncpus 113 | >> engine_type 114 | >> scope_type 115 | >> scheduler_type 116 | >> compile_flags; 117 | } // end of load 118 | }; 119 | 120 | 121 | 122 | } 123 | #endif 124 | -------------------------------------------------------------------------------- /cmake/FindMatlab.cmake: -------------------------------------------------------------------------------- 1 | # - this module looks for Matlab 2 | # Defines: 3 | # MATLAB_INCLUDE_DIR: include path for mex.h, engine.h 4 | # MATLAB_LIBRARIES: required libraries: libmex, etc 5 | # MATLAB_MAT_LIBRARY: path to libmat.lib 6 | # MATLAB_MEX_LIBRARY: path to libmex.lib 7 | # MATLAB_MX_LIBRARY: path to libmx.lib 8 | # MATLAB_ENG_LIBRARY: path to libeng.lib 9 | 10 | 11 | SET(MATLAB_FOUND 0) 12 | IF(WIN32) 13 | IF(${CMAKE_GENERATOR} MATCHES "Visual Studio .*" OR ${CMAKE_GENERATOR} MATCHES "NMake Makefiles") 14 | SET(MATLAB_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/lib/win32/microsoft/") 15 | ELSE(${CMAKE_GENERATOR} MATCHES "Visual Studio .*" OR ${CMAKE_GENERATOR} MATCHES "NMake Makefiles") 16 | IF(${CMAKE_GENERATOR} MATCHES "Borland") 17 | # Same here, there are also: bcc50 and bcc51 directories 18 | SET(MATLAB_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/lib/win32/microsoft/bcc54") 19 | ELSE(${CMAKE_GENERATOR} MATCHES "Borland") 20 | MESSAGE(FATAL_ERROR "Generator not compatible: ${CMAKE_GENERATOR}") 21 | ENDIF(${CMAKE_GENERATOR} MATCHES "Borland") 22 | ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio .*" OR ${CMAKE_GENERATOR} MATCHES "NMake Makefiles") 23 | FIND_LIBRARY(MATLAB_MEX_LIBRARY 24 | libmex 25 | ${MATLAB_ROOT} 26 | ) 27 | FIND_LIBRARY(MATLAB_MX_LIBRARY 28 | libmx 29 | ${MATLAB_ROOT} 30 | ) 31 | FIND_LIBRARY(MATLAB_ENG_LIBRARY 32 | libeng 33 | ${MATLAB_ROOT} 34 | ) 35 | FIND_LIBRARY(MATLAB_MAT_LIBRARY 36 | libmat 37 | ${MATLAB_ROOT} 38 | ) 39 | 40 | FIND_PATH(MATLAB_INCLUDE_DIR 41 | "mex.h" 42 | "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/include" 43 | ) 44 | ELSE( WIN32 ) 45 | IF(NOT MATLAB_ROOT) 46 | IF($ENV{MATLAB_ROOT}) 47 | SET(MATLAB_ROOT $ENV{MATLAB_ROOT}) 48 | ELSE($ENV{MATLAB_ROOT}) 49 | SET(MATLAB_ROOT /opt/matlab) 50 | ENDIF($ENV{MATLAB_ROOT}) 51 | ENDIF(NOT MATLAB_ROOT) 52 | IF(CMAKE_SIZEOF_VOID_P EQUAL 4) 53 | # Regular x86 54 | SET(MATLAB_SYS 55 | ${MATLAB_ROOT}/bin/glnx86 56 | ) 57 | ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4) 58 | # AMD64: 59 | SET(MATLAB_SYS 60 | ${MATLAB_ROOT}/bin/glnxa64 61 | ) 62 | ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4) 63 | FIND_LIBRARY(MATLAB_MEX_LIBRARY 64 | mex 65 | ${MATLAB_SYS} 66 | ) 67 | FIND_LIBRARY(MATLAB_MX_LIBRARY 68 | mx 69 | ${MATLAB_SYS} 70 | ) 71 | FIND_LIBRARY(MATLAB_MAT_LIBRARY 72 | mat 73 | ${MATLAB_SYS} 74 | ) 75 | FIND_LIBRARY(MATLAB_ENG_LIBRARY 76 | eng 77 | ${MATLAB_SYS} 78 | ) 79 | FIND_PATH(MATLAB_INCLUDE_DIR 80 | "mex.h" 81 | ${MATLAB_ROOT}/extern/include 82 | ) 83 | 84 | ENDIF(WIN32) 85 | 86 | # This is common to UNIX and Win32: 87 | SET(MATLAB_LIBRARIES 88 | ${MATLAB_MEX_LIBRARY} 89 | ${MATLAB_MX_LIBRARY} 90 | ${MATLAB_ENG_LIBRARY} 91 | ) 92 | 93 | IF(MATLAB_INCLUDE_DIR 94 | AND MATLAB_MEX_LIBRARY 95 | AND MATLAB_MAT_LIBRARY 96 | AND MATLAB_ENG_LIBRARY 97 | AND MATLAB_MX_LIBRARY) 98 | SET(MATLAB_LIBRARIES ${MATLAB_MX_LIBRARY} ${MATLAB_MEX_LIBRARY} ${MATLAB_ENG_LIBRARY} ${MATLAB_MAT_LIBRARY}) 99 | ENDIF(MATLAB_INCLUDE_DIR 100 | AND MATLAB_MEX_LIBRARY 101 | AND MATLAB_MAT_LIBRARY 102 | AND MATLAB_ENG_LIBRARY 103 | AND MATLAB_MX_LIBRARY) 104 | 105 | MARK_AS_ADVANCED( 106 | MATLAB_MEX_LIBRARY 107 | MATLAB_MX_LIBRARY 108 | MATLAB_ENG_LIBRARY 109 | MATLAB_INCLUDE_DIR 110 | MATLAB_ROOT 111 | ) 112 | 113 | INCLUDE(FindPackageHandleStandardArgs) 114 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Matlab 115 | MATLAB_INCLUDE_DIR 116 | MATLAB_MEX_LIBRARY 117 | MATLAB_MAT_LIBRARY 118 | MATLAB_ENG_LIBRARY 119 | MATLAB_MX_LIBRARY ) 120 | 121 | -------------------------------------------------------------------------------- /src/graphlab/extern/metis/libmetis/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * util.c 5 | * 6 | * This function contains various utility routines 7 | * 8 | * Started 9/28/95 9 | * George 10 | * 11 | * $Id: util.c,v 1.4 2003/04/13 04:45:12 karypis Exp $ 12 | */ 13 | 14 | #include 15 | 16 | 17 | 18 | 19 | /************************************************************************* 20 | * The following are utility functions defined for idxtype using GKlib's 21 | * function generating macros 22 | **************************************************************************/ 23 | GK_XMALLOC(idxmalloc, idxtype) 24 | GK_XREALLOC(idxrealloc, idxtype) 25 | GK_XSMALLOC(idxsmalloc, idxtype, idxset) 26 | GK_SET(idxset, idxtype) 27 | GK_ARGMAX(idxargmax, idxtype) 28 | GK_ARGMIN(idxargmin, idxtype) 29 | GK_SUM(idxsum, idxtype, idxtype) 30 | GK_AXPY(idxaxpy, idxtype) 31 | 32 | 33 | 34 | 35 | /************************************************************************* 36 | * These functions return the index of the maximum element in a vector 37 | **************************************************************************/ 38 | idxtype idxargmax_strd(size_t n, idxtype *x, idxtype incx) 39 | { 40 | size_t i, max=0; 41 | 42 | n *= incx; 43 | for (i=incx; i x[max] ? i : max); 45 | 46 | return max/incx; 47 | } 48 | 49 | 50 | 51 | 52 | /************************************************************************* 53 | * These functions return the index of the almost maximum element in a vector 54 | **************************************************************************/ 55 | idxtype famax2(size_t n, float *x) 56 | { 57 | size_t i, max1, max2; 58 | 59 | if (x[0] > x[1]) { 60 | max1 = 0; 61 | max2 = 1; 62 | } 63 | else { 64 | max1 = 1; 65 | max2 = 0; 66 | } 67 | 68 | for (i=2; i x[max1]) { 70 | max2 = max1; 71 | max1 = i; 72 | } 73 | else if (x[i] > x[max2]) 74 | max2 = i; 75 | } 76 | 77 | return max2; 78 | } 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | /************************************************************************* 87 | * This file randomly permutes the contents of an array. 88 | * flag == 0, don't initialize perm 89 | * flag == 1, set p[i] = i 90 | **************************************************************************/ 91 | void RandomPermute(size_t n, idxtype *p, idxtype flag) 92 | { 93 | size_t i, u, v; 94 | idxtype tmp; 95 | 96 | if (flag == 1) { 97 | for (i=0; i 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | #include 21 | 22 | namespace graphlab { 23 | 24 | 25 | class distributed_metrics { 26 | 27 | private: 28 | 29 | 30 | distributed_metrics(distributed_control * _dc) : 31 | stats(_dc->numprocs()) { 32 | dc = _dc; 33 | } 34 | 35 | public: 36 | 37 | 38 | 39 | static distributed_metrics * instance(distributed_control * dc); 40 | 41 | // Remote call 42 | static void remote_set_value(distributed_control& _dc, size_t source, void *ptr, size_t len, 43 | std::string key, double value); 44 | 45 | void set_value(std::string key, double value) { 46 | set_value(dc->procid(), key, value); 47 | } 48 | 49 | void set_value(size_t procid, std::string key, double value) { 50 | if (dc->procid() == 0) { 51 | synclock.lock(); 52 | stats[procid][key] = value; 53 | synclock.unlock(); 54 | } else { 55 | dc->remote_callxs(0, distributed_metrics::remote_set_value, 56 | NULL, 0, key, value); 57 | } 58 | } 59 | 60 | double get_value(int procid, std::string key) { 61 | std::map::iterator iter = stats[procid].find(key); 62 | if (iter == stats[procid].end()) { 63 | ASSERT_MSG("A key %s was not found for procid %d!", key.c_str(), procid); 64 | return -1; // Not reached, prevents warning. 65 | } else return iter->second; 66 | } 67 | 68 | void report() { 69 | ASSERT_EQ(dc->procid(), 0); 70 | 71 | char fname[255]; 72 | sprintf(fname, "stats_%d.txt", dc->numprocs()); 73 | 74 | FILE * statsf = fopen(fname,"w"); 75 | FILE * benchf = fopen(".runstats.R", "w"); 76 | int np = stats.size(); 77 | 78 | printf("=============== REPORT (see also stats.txt) ============== \n"); 79 | printf("key,"); 80 | fprintf(statsf, "key,"); 81 | for(int i=0; i::iterator iter = stats[0].begin(); 89 | for(; iter != stats[0].end(); ++iter) { 90 | std::string key = iter->first; 91 | printf("%s,", key.c_str()); 92 | fprintf(statsf, "%s,", key.c_str()); 93 | double sum = 0.0; 94 | 95 | for(int p=0; p > stats; 127 | 128 | }; 129 | 130 | 131 | } // end of namespace graphlab 132 | #include 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /src/graphlab/schedulers/set_scheduler/set_generic_typedefs.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SET_GENERIC_TYPEDEFS_HPP 2 | #define SET_GENERIC_TYPEDEFS_HPP 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace graphlab { 13 | /* typedef std::set ss_set_type; 14 | typedef std::set::iterator ss_set_type_iterator ; 15 | 16 | inline ss_set_type_iterator begin(const ss_set_type &s) { 17 | return s.begin(); 18 | } 19 | 20 | inline ss_set_type_iterator end(const ss_set_type &s) { 21 | return s.end(); 22 | } 23 | inline void ss_insert(ss_set_type &s, vertex_id_t v) { 24 | s.insert(v); 25 | } 26 | 27 | inline void ss_union(ss_set_type &lhs, const ss_set_type &rhs) { 28 | lhs = set_union(lhs, rhs); 29 | } 30 | 31 | inline void ss_intersect(ss_set_type &lhs, const ss_set_type &rhs) { 32 | lhs = set_intersect(lhs, rhs); 33 | } 34 | 35 | inline void ss_subtract(ss_set_type &lhs, const ss_set_type &rhs) { 36 | lhs = set_difference(lhs, rhs); 37 | } 38 | 39 | inline size_t ss_size(const ss_set_type &s) { 40 | return s.size(); 41 | } 42 | 43 | inline bool ss_contains(const ss_set_type &s, vertex_id_t v) { 44 | return s.find(v) != s.end(); 45 | }*/ 46 | 47 | 48 | 49 | struct ss_set { 50 | typedef bm::bvector<> type; 51 | typedef bm::bvector<>::enumerator iterator; 52 | }; 53 | typedef ss_set::type ss_set_type; 54 | typedef ss_set::iterator ss_set_type_iterator; 55 | 56 | inline ss_set_type_iterator begin(const ss_set_type &s) { 57 | return s.first(); 58 | } 59 | 60 | inline ss_set_type_iterator end(const ss_set_type &s) { 61 | return s.end(); 62 | } 63 | 64 | inline void ss_insert(ss_set_type &s, vertex_id_t v) { 65 | s.set_bit(v); 66 | } 67 | 68 | inline void ss_remove(ss_set_type &s, vertex_id_t v) { 69 | s.clear_bit(v); 70 | } 71 | 72 | inline void ss_union(ss_set_type &lhs, const ss_set_type &rhs) { 73 | lhs |= rhs; 74 | } 75 | 76 | inline void ss_intersect(ss_set_type &lhs, const ss_set_type &rhs) { 77 | lhs &= rhs; 78 | } 79 | 80 | inline void ss_subtract(ss_set_type &lhs, const ss_set_type &rhs) { 81 | lhs -= rhs; 82 | } 83 | 84 | inline size_t ss_size(const ss_set_type &s) { 85 | return s.count(); 86 | } 87 | 88 | inline bool ss_contains(const ss_set_type &s, vertex_id_t v) { 89 | return s.test(v); 90 | } 91 | 92 | 93 | 94 | 95 | struct ss_small_set { 96 | typedef std::vector type; 97 | typedef std::vector::const_iterator iterator; 98 | }; 99 | 100 | typedef ss_small_set::type ss_small_set_type; 101 | typedef ss_small_set::iterator ss_small_set_type_iterator; 102 | 103 | 104 | inline ss_small_set_type_iterator begin(const ss_small_set_type &s) { 105 | return s.begin(); 106 | } 107 | 108 | inline ss_small_set_type_iterator end(const ss_small_set_type &s) { 109 | return s.end(); 110 | } 111 | 112 | inline void ss_insert(ss_small_set_type &s, vertex_id_t v) { 113 | s.push_back(v); 114 | } 115 | 116 | inline void ss_union(ss_small_set_type &lhs, const ss_small_set_type &rhs) { 117 | std::copy(rhs.begin(), rhs.end(), std::inserter(lhs, lhs.end())); 118 | } 119 | 120 | inline size_t ss_size(const ss_small_set_type &s) { 121 | return s.size(); 122 | } 123 | 124 | inline bool ss_contains(const ss_small_set_type &s, vertex_id_t v) { 125 | return find(s.begin(), s.end(), v) != s.end(); 126 | } 127 | 128 | inline void ss_remove(ss_small_set_type &s, vertex_id_t v) { 129 | std::vector::iterator i = find(s.begin(), s.end(), v); 130 | if (i == s.end()) return; 131 | else { 132 | *i = s[s.size() - 1]; 133 | s.resize(s.size() - 1); 134 | } 135 | 136 | } 137 | 138 | }; 139 | 140 | #endif 141 | --------------------------------------------------------------------------------