Skip to content

Commit

Permalink
Pardiso works when mkl_rt is dinamically loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
gbanjac committed Sep 27, 2017
1 parent f9f4884 commit 1c422a5
Show file tree
Hide file tree
Showing 13 changed files with 385 additions and 190 deletions.
18 changes: 0 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,6 @@ option (ENABLE_MKL_PARDISO "Enable MKL Pardiso solver" ON)
message(STATUS "MKL Pardiso: ${ENABLE_MKL_PARDISO}")


# Find linear system solvers
# ---------------------------------------------
if (ENABLE_MKL_PARDISO)
option(MKL_USE_SINGLE_DYNAMIC_LIBRARY "Use MKL single dynamic library interface" ON)
message(STATUS "MKL single dynamic library (SDL) ${MKL_USE_SINGLE_DYNAMIC_LIBRARY}")
if (NOT MKL_USE_SINGLE_DYNAMIC_LIBRARY)
option(MKL_USE_STATIC_LIBRARIES "Use MKL in static library interface" ON)
message(STATUS "MKL static library interface ${MKL_USE_STATIC_LIBRARIES}")
option(MKL_MULTI_THREADED "Use MKL multi threading in static library interface" ON)
message(STATUS "MKL multi threading ${MKL_MULTI_THREADED}")
endif()

# Find MKL Pardiso
find_package(MKL REQUIRED)
endif()

# Generate header file with the global options
# ---------------------------------------------
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/glob_opts.h.in
Expand Down Expand Up @@ -265,7 +249,6 @@ include_directories(${linsys_solvers_includes})


add_library (osqpstatic STATIC ${osqp_src} ${osqp_headers} ${linsys_solvers})
target_link_libraries(osqpstatic ${linsys_solvers_libraries})


if (MATLAB)
Expand All @@ -283,7 +266,6 @@ if (NOT PYTHON AND NOT MATLAB)
# Create osqp shared library
# NB: Add all the linear system solvers here
add_library (osqp SHARED ${osqp_src} ${osqp_headers} ${linsys_solvers})
target_link_libraries(osqp ${linsys_solvers_libraries})

# Create demo executable (linked to static library)
add_executable (osqp_demo ${PROJECT_SOURCE_DIR}/examples/osqp_demo.c)
Expand Down
106 changes: 0 additions & 106 deletions configure/cmake/FindMKL.cmake

This file was deleted.

23 changes: 12 additions & 11 deletions configure/glob_opts.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@ typedef float c_float; /* for numerical values */
#endif


#if EMBEDDED != 1

#include <math.h>
#ifndef DFLOAT // Doubles
#define c_sqrt sqrt
#else // Floats
#define c_sqrt sqrtf
#endif

#endif // end EMBEDDED


/* Use customized constants ----------------------------------------------- */
#ifndef OSQP_NULL
Expand Down Expand Up @@ -147,6 +136,18 @@ typedef float c_float; /* for numerical values */

/* Use customized functions ----------------------------------------------- */

#if EMBEDDED != 1

#include <math.h>
#ifndef DFLOAT // Doubles
#define c_sqrt sqrt
#else // Floats
#define c_sqrt sqrtf
#endif

#endif // end EMBEDDED


#ifdef PRINTING
#include <stdio.h>
#include <string.h>
Expand Down
37 changes: 19 additions & 18 deletions interfaces/python/tests/general/big_prob.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
l = -1 * np.ones(n)
u = 1 * np.ones(n)

l += 10
u += 10
# l += 10
# u += 10

# l *= 1000
# u *= 1000
Expand All @@ -44,9 +44,9 @@
# q = q

# Test
rho = 10.
rho = 0.1
# rho=10.0
q /= 100
# q /= 100
# P *= 100
# q *= 2000

Expand All @@ -62,17 +62,18 @@
'scaling': True,
'scaling_norm': -1,
'max_iter': 2500,
'verbose': True
'verbose': True,
'linsys_solver': 2
}

qp = mpbpy.QuadprogProblem(P, q, A, l, u)
res_gurobi = qp.solve(solver=mpbpy.GUROBI, verbose=True)
res_gurobi = qp.solve(solver=mpbpy.GUROBI, verbose=False)
# res_purepy = qp.solve(solver=mpbpy.OSQP_PUREPY, **osqp_opts)
# res_osqp = qp.solve(solver=mpbpy.OSQP, **osqp_opts)

model = osqppurepy.OSQP()
model.setup(P=P, q=q, A=A, l=l, u=u, **osqp_opts)
res_osqppurepy = model.solve()
#
# model = osqppurepy.OSQP()
# model.setup(P=P, q=q, A=A, l=l, u=u, **osqp_opts)
# res_osqppurepy = model.solve()

model = osqp.OSQP()
model.setup(P=P, q=q, A=A, l=l, u=u, **osqp_opts)
Expand All @@ -83,20 +84,20 @@
if res_gurobi.status == 'optimal':
print("Difference Purepy vs Gurobi")
print(" - primal = %.4f" %
(np.linalg.norm(res_gurobi.x - res_osqppurepy.x) /
(np.linalg.norm(res_gurobi.x - res_osqp.x) /
np.linalg.norm(res_gurobi.x)))
print(" - dual = %.4f" %
(np.linalg.norm(res_gurobi.y - res_osqppurepy.y) /
(np.linalg.norm(res_gurobi.y - res_osqp.y) /
np.linalg.norm(res_gurobi.y)))


# Solve with SCS
import cvxpy
x = cvxpy.Variable(n)
objective = cvxpy.Minimize(cvxpy.quad_form(x, P) + q * x)
constraints = [l <= A * x, A * x <= u]
problem = cvxpy.Problem(objective, constraints)
problem.solve(solver=cvxpy.SCS, verbose=True)
# import cvxpy
# x = cvxpy.Variable(n)
# objective = cvxpy.Minimize(cvxpy.quad_form(x, P) + q * x)
# constraints = [l <= A * x, A * x <= u]
# problem = cvxpy.Problem(objective, constraints)
# problem.solve(solver=cvxpy.SCS, verbose=True)


# # Store optimal values
Expand Down
17 changes: 12 additions & 5 deletions lin_sys/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Add subdirectory for each linear systems solver

# Include this directory for library handler
# NB Needed for subfolders
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# Direct solver
add_subdirectory(direct)

Expand All @@ -9,10 +13,13 @@ add_subdirectory(direct)

# Combine solvers
# TODO: Add indirect ones
set(linsys_solvers ${direct_linsys_solvers} PARENT_SCOPE)

# Combine solvers external libraries
set(linsys_solvers_libraries ${direct_linsys_solvers_libraries} PARENT_SCOPE)
set(linsys_solvers
${CMAKE_CURRENT_SOURCE_DIR}/LibraryHandler.c
${CMAKE_CURRENT_SOURCE_DIR}/LibraryHandler.h
${direct_linsys_solvers}
PARENT_SCOPE)

# Combine solvers external libraries
set(linsys_solvers_includes ${direct_linsys_solvers_includes} PARENT_SCOPE)
set(linsys_solvers_includes
${direct_linsys_solvers_includes}
PARENT_SCOPE)
Loading

0 comments on commit 1c422a5

Please sign in to comment.