Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ cmake_minimum_required(VERSION 3.23)

project(easygraph)

option(EASYGRAPH_ENABLE_OPENMP "Enable OpenMP acceleration (auto-detect)" ON)

option(EASYGRAPH_ENABLE_GPU "EASYGRAPH_ENABLE_GPU" OFF)

add_subdirectory(cpp_easygraph)

if (EASYGRAPH_ENABLE_GPU)

message("easygraph gpu module is enabled")

add_subdirectory(gpu_easygraph)

target_include_directories(cpp_easygraph
PRIVATE gpu_easygraph
)

else()

message("easygraph gpu module is disabled")

endif()
endif()
58 changes: 50 additions & 8 deletions cpp_easygraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
cmake_minimum_required(VERSION 3.23)

project(cpp_easygraph)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(EASYGRAPH_ENABLE_OPENMP "Enable OpenMP acceleration (auto-detect)" ON)
option(EASYGRAPH_ENABLE_GPU "EASYGRAPH_ENABLE_GPU" OFF)

file(GLOB SOURCES
classes/*.cpp
Expand All @@ -11,8 +17,6 @@ file(GLOB SOURCES

add_subdirectory(pybind11)

option(EASYGRAPH_ENABLE_GPU "EASYGRAPH_ENABLE_GPU" OFF)

if (EASYGRAPH_ENABLE_GPU)

pybind11_add_module(cpp_easygraph
Expand All @@ -22,7 +26,7 @@ if (EASYGRAPH_ENABLE_GPU)

set_property(TARGET cpp_easygraph PROPERTY CUDA_ARCHITECTURES all)

target_compile_definitions(cpp_easygraph
target_compile_definitions(cpp_easygraph
PRIVATE EASYGRAPH_ENABLE_GPU
)

Expand All @@ -31,14 +35,52 @@ if (EASYGRAPH_ENABLE_GPU)
)

else()

pybind11_add_module(cpp_easygraph
${SOURCES}
)

endif()

set_target_properties(cpp_easygraph PROPERTIES
LINK_SEARCH_START_STATIC ON
LINK_SEARCH_END_STATIC ON
)
if (EASYGRAPH_ENABLE_OPENMP)
if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
find_path(EG_LIBOMP_INCLUDE_DIR
NAMES omp.h
PATHS
/opt/homebrew/opt/libomp/include
/usr/local/opt/libomp/include
)

find_library(EG_LIBOMP_LIBRARY
NAMES omp libomp
PATHS
/opt/homebrew/opt/libomp/lib
/usr/local/opt/libomp/lib
)

if (EG_LIBOMP_INCLUDE_DIR AND EG_LIBOMP_LIBRARY)
message(STATUS "libomp found: ${EG_LIBOMP_LIBRARY}")

set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp" CACHE STRING "" FORCE)
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp" CACHE STRING "" FORCE)

set(OpenMP_CXX_INCLUDE_DIR "${EG_LIBOMP_INCLUDE_DIR}" CACHE PATH "" FORCE)
set(OpenMP_omp_LIBRARY "${EG_LIBOMP_LIBRARY}" CACHE FILEPATH "" FORCE)
else()
message(STATUS
"libomp not found on macOS. OpenMP will be disabled.\n"
"To enable OpenMP, run: brew install libomp"
)
endif()
endif()

find_package(OpenMP QUIET)
endif()

if (OpenMP_CXX_FOUND)
message(STATUS "OpenMP found, enabling parallel acceleration.")
target_link_libraries(cpp_easygraph PRIVATE OpenMP::OpenMP_CXX)
target_compile_definitions(cpp_easygraph PRIVATE EASYGRAPH_USE_OPENMP=1)
else()
message(STATUS "OpenMP not found, building in single-thread mode.")
target_compile_definitions(cpp_easygraph PRIVATE EASYGRAPH_USE_OPENMP=0)
endif()
6 changes: 5 additions & 1 deletion cpp_easygraph/cpp_easygraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,20 @@ PYBIND11_MODULE(cpp_easygraph, m) {
.def_property("pred", &DiGraph::get_pred,nullptr)
.def("generate_linkgraph", &DiGraph_generate_linkgraph,py::arg("weight") = "weight");

m.def("cpp_degree_centrality", &degree_centrality, py::arg("G"));
m.def("cpp_in_degree_centrality", &in_degree_centrality, py::arg("G"));
m.def("cpp_out_degree_centrality", &out_degree_centrality, py::arg("G"));
m.def("cpp_closeness_centrality", &closeness_centrality, py::arg("G"), py::arg("weight") = "weight", py::arg("cutoff") = py::none(), py::arg("sources") = py::none());
m.def("cpp_betweenness_centrality", &betweenness_centrality, py::arg("G"), py::arg("weight") = "weight", py::arg("cutoff") = py::none(),py::arg("sources") = py::none(), py::arg("normalized") = py::bool_(true), py::arg("endpoints") = py::bool_(false));
m.def("cpp_katz_centrality", &cpp_katz_centrality, py::arg("G"), py::arg("alpha") = 0.1, py::arg("beta") = 1.0, py::arg("max_iter") = 1000, py::arg("tol") = 1e-6, py::arg("normalized") = true);
m.def("cpp_eigenvector_centrality", &cpp_eigenvector_centrality, py::arg("G"), py::arg("max_iter") = 100, py::arg("tol") = 1.0e-6, py::arg("nstart") = py::none(), py::arg("weight") = py::none());
m.def("cpp_k_core", &core_decomposition, py::arg("G"));
m.def("cpp_density", &density, py::arg("G"));
m.def("cpp_constraint", &constraint, py::arg("G"), py::arg("nodes") = py::none(), py::arg("weight") = py::none(), py::arg("n_workers") = py::none());
m.def("cpp_effective_size", &effective_size, py::arg("G"), py::arg("nodes") = py::none(), py::arg("weight") = py::none(), py::arg("n_workers") = py::none());
m.def("cpp_efficiency", &efficiency, py::arg("G"), py::arg("nodes") = py::none(), py::arg("weight") = py::none(), py::arg("n_workers") = py::none());
m.def("cpp_hierarchy", &hierarchy, py::arg("G"), py::arg("nodes") = py::none(), py::arg("weight") = py::none(), py::arg("n_workers") = py::none());
m.def("cpp_pagerank", &_pagerank, py::arg("G"), py::arg("alpha") = 0.85, py::arg("max_iterator") = 500, py::arg("threshold") = 1e-6);
m.def("cpp_pagerank", &_pagerank, py::arg("G"), py::arg("alpha") = 0.85, py::arg("max_iterator") = 500, py::arg("threshold") = 1e-6, py::arg("weight") = py::none());
m.def("cpp_dijkstra_multisource", &_dijkstra_multisource, py::arg("G"), py::arg("sources"), py::arg("weight") = "weight", py::arg("target") = py::none());
m.def("cpp_spfa", &_spfa, py::arg("G"), py::arg("source"), py::arg("weight") = "weight");
m.def("cpp_clustering", &clustering, py::arg("G"), py::arg("nodes") = py::none(), py::arg("weight") = py::none());
Expand Down
Loading