Skip to content

Commit

Permalink
making apple compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
lseman committed Sep 29, 2024
1 parent 2b87f20 commit 934f5b7
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 112 deletions.
71 changes: 40 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -flto")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -march=native -flto")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -Wall -Wextra")

if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(APPLE)
set(CMAKE_OSX_ARCHITECTURES "arm64") # Or "arm64" for Apple Silicon (M1/M2 chips)
endif()

# Define a config.h.in template
configure_file("config.h.in" "config.h")
Expand All @@ -58,7 +65,7 @@ option(RIH "Enable RIH compilation option" OFF)
option(RCC "Enable RCC compilation option" OFF)
option(SRC3 "Enable 3SRC compilation option" OFF)
option(SRC "Enable SRC compilation option" OFF)
option(GET_TBB "Enable TBB compilation option" OFF)
#option(GET_TBB "Enable TBB compilation option" OFF)
option(UNREACHABLE_DOMINANCE "Enable Unreachable Dominance compilation option"
OFF)
option(SORTED_LABELS "Enable Sorted Labels compilation option" OFF)
Expand Down Expand Up @@ -184,7 +191,11 @@ cpmaddpackage(
"STDEXEC_BUILD_DOCS OFF"
"BUILD_TESTING OFF")

cpmaddpackage(NAME fmt GITHUB_REPOSITORY fmtlib/fmt GIT_TAG 11.0.2)
find_package(FMT)
if (NOT FMT_FOUND)
message(STATUS "FMT not found, using bundled version")
cpmaddpackage(NAME fmt GITHUB_REPOSITORY fmtlib/fmt GIT_TAG 11.0.2)
endif()

if(GET_SUITESPARSE)
cpmaddpackage(
Expand All @@ -201,28 +212,6 @@ if(GET_SUITESPARSE)
set(SUITESPARSE_CONFIG_ONLY TRUE)
endif()

find_package(TBB)
if(TBB_FOUND)
message(STATUS "TBB found: ${TBB_VERSION}")
else()
message(STATUS "TBB not found, will download it")
# set GET_TBB to true
set(GET_TBB ON)
endif()

if(GET_TBB)
cpmaddpackage(
NAME
TBB
GITHUB_REPOSITORY
oneapi-src/oneTBB
GIT_TAG
v2021.13.0
OPTIONS
"TBB_TEST OFF"
"TBB_EXAMPLES OFF"
"TBB_BUILD_SHARED OFF")
endif()

if(WITH_PYTHON)
cpmaddpackage(NAME pybind11 GITHUB_REPOSITORY pybind/pybind11 GIT_TAG v2.13.6)
Expand All @@ -236,7 +225,7 @@ if(IPM OR CLIQUER)
endif()
include_directories(/usr/include/suitesparse/)

set(GUROBI_HOME /home/seman/gurobi1101/linux64)
set(GUROBI_HOME $ENV{GUROBI_HOME})

include_directories(${GUROBI_HOME}/include)

Expand Down Expand Up @@ -308,8 +297,14 @@ add_executable(vrptw ${EXECUTABLE_SOURCES})

# Linking libraries
target_link_libraries(vrptw PRIVATE STDEXEC::stdexec)

find_package(FMT)
if (NOT FMT_FOUND)
message(STATUS "FMT not found, using bundled version")
target_link_libraries(vrptw PRIVATE fmt::fmt)
target_link_libraries(vrptw PRIVATE TBB::tbb)
else()
target_link_libraries(vrptw PRIVATE fmt::fmt)
endif()

if(IPM)
target_link_libraries(vrptw PRIVATE Eigen3::Eigen)
Expand All @@ -320,9 +315,25 @@ set(GUROBI_VERSION_MAJOR 110) # Adjust based on Gurobi version
message(STATUS "Gurobi version: ${GUROBI_VERSION_MAJOR}")

# Link Gurobi libraries
target_link_libraries(
vrptw PRIVATE ${GUROBI_HOME}/lib/libgurobi_c++.a
${GUROBI_HOME}/lib/libgurobi${GUROBI_VERSION_MAJOR}.so tbb)
if(APPLE)
# macOS detected, use .dylib for linking
target_link_libraries(
vrptw PRIVATE ${GUROBI_HOME}/lib/libgurobi_c++.a
${GUROBI_HOME}/lib/libgurobi100.dylib
)
else()
# Non-macOS (Linux or other platforms), use .so and .a files
target_link_libraries(
vrptw PRIVATE ${GUROBI_HOME}/lib/libgurobi_c++.a
${GUROBI_HOME}/lib/libgurobi${GUROBI_VERSION_MAJOR}.so
)
endif()

if(APPLE)
find_package(OpenMP REQUIRED)
target_link_libraries(vrptw PRIVATE OpenMP::OpenMP_CXX)
endif()


# Find jemalloc
find_library(JEMALLOC_LIBRARY jemalloc)
Expand All @@ -337,7 +348,6 @@ if(WITH_PYTHON)
pybind11_add_module(baldes src/BucketBindings.cpp ${EXECUTABLE_SOURCES})
target_link_libraries(baldes PRIVATE pybind11::module)
target_link_libraries(baldes PRIVATE fmt::fmt)
target_link_libraries(baldes PRIVATE TBB::tbb)
target_link_libraries(baldes PRIVATE STDEXEC::stdexec)
set_target_properties(baldes PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(baldes PRIVATE -Wno-c++26-extensions
Expand All @@ -351,7 +361,6 @@ if(CLIQUER)
add_executable(cliquer src/Original.cpp src/BucketGraph.cpp)
target_link_libraries(cliquer PRIVATE STDEXEC::stdexec)
target_link_libraries(cliquer PRIVATE fmt::fmt)
target_link_libraries(cliquer PRIVATE TBB::tbb)
target_link_libraries(
cliquer PRIVATE ${GUROBI_HOME}/lib/libgurobi_c++.a
${GUROBI_HOME}/lib/libgurobi${GUROBI_VERSION_MAJOR}.so tbb)
Expand Down
5 changes: 4 additions & 1 deletion examples/VRPTW.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include "Cut.h"
#include "Definitions.h"

#include "bucket/BucketGraph.h"
Expand Down Expand Up @@ -968,7 +969,8 @@ class VRProblem {

// Adding cols
auto colAdded = addColumn(node, paths, false);
// remove all cuts
// remove all cuts
#ifdef SRC
if (bucket_graph.getStatus() == Status::Rollback) {
for (int i = SRCconstraints.size() - 1; i >= 0; --i) {
GRBConstr constr = SRCconstraints[i];
Expand All @@ -981,6 +983,7 @@ class VRProblem {
// r1c.cutStorage = cuts;
matrix = extractModelDataSparse(node);
}
#endif

#ifdef SCHRODINGER
// Adding schrodinger paths
Expand Down
2 changes: 1 addition & 1 deletion include/bucket/BucketJump.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void BucketGraph::BucketArcElimination(double theta) {
auto &buckets_size = assign_buckets<D>(fw_buckets_size, bw_buckets_size);

// Reset fixed_buckets in parallel
std::for_each(std::execution::par, fixed_buckets.begin(), fixed_buckets.end(),
std::for_each(fixed_buckets.begin(), fixed_buckets.end(),
[](auto &fb) { std::fill(fb.begin(), fb.end(), 0); });

// Print direction of arc elimination
Expand Down
4 changes: 2 additions & 2 deletions include/bucket/BucketUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void BucketGraph::generate_arcs() {
}

// Clear all buckets in parallel, removing any existing arcs
std::for_each(std::execution::par_unseq, buckets.begin(), buckets.end(), [&](auto &bucket) {
std::for_each(buckets.begin(), buckets.end(), [&](auto &bucket) {
bucket.clear(); // Clear bucket data
bucket.clear_arcs(D == Direction::Forward); // Clear arcs in the bucket
});
Expand Down Expand Up @@ -331,7 +331,7 @@ void BucketGraph::generate_arcs() {
};

// Iterate over all jobs in parallel, generating arcs for each
std::for_each(std::execution::par_unseq, jobs.begin(), jobs.end(), [&](const VRPJob &VRPJob) {
std::for_each(jobs.begin(), jobs.end(), [&](const VRPJob &VRPJob) {
std::vector<double> res_inc = {static_cast<double>(VRPJob.duration)}; // Resource increment vector
std::vector<std::pair<int, int>> local_arcs; // Local storage for arcs

Expand Down
7 changes: 6 additions & 1 deletion third_party/fpmax/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include "buffer.h"
#include "common.h"
#include <malloc.h>
#ifdef __APPLE__
#include <stdlib.h>
#else
#include <malloc.h>
#endif


memory::memory()
{
Expand Down
6 changes: 3 additions & 3 deletions third_party/fpmax/fp_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void update_cfi_trees(int treeno, int Count)
}
}

stack::stack(int length, bool close)
fpstack::stack::stack(int length, bool close)
{
top= 0;
FS = new int[length];
Expand All @@ -123,12 +123,12 @@ stack::stack(int length, bool close)
counts = NULL;
}

stack::~stack()
fpstack::stack::~stack()
{
delete []FS;
}

void stack::insert(FI_tree* fptree)
void fpstack::stack::insert(FI_tree* fptree)
{
for(Fnode* node=fptree->Root->leftchild; node!=NULL; node=node->leftchild)
{
Expand Down
Loading

0 comments on commit 934f5b7

Please sign in to comment.