Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python solve is faster than C code-generated one #110

Open
xkhainguyen opened this issue Apr 26, 2023 · 4 comments
Open

Python solve is faster than C code-generated one #110

xkhainguyen opened this issue Apr 26, 2023 · 4 comments

Comments

@xkhainguyen
Copy link

Hi,

I ran the quadrotor example in Python and generated C code in the standard way. I noticed that it intentionally generated code with an EMBEDDED flag then I have to use time.h to measure the solve time of the osqp_solve(&workspace) function.

Both Python and C gave me the same results but the solve times are unexpected. Python one is like 1ms and C one is like 3ms. I don't really get why this happened. Did anyone see this problem before?

Thanks.

@goulart-paul
Copy link
Collaborator

Do you have the same compiler optimization flags enabled in both cases?

@xkhainguyen
Copy link
Author

xkhainguyen commented Apr 26, 2023

I just ran the Python code normally from .py file. My function looks like this
prob.codegen('code', project_type='Makefile', force_rewrite=True, FLOAT=False)

I did not modify anything in the generated CMakeLists.txt.

if (NOT DEFINED EMBEDDED)  # enable embedded anyway
    set (EMBEDDED 1)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")

But I do see this in osqp_configure.h.in

/* DEBUG */
#cmakedefine DEBUG

@imciner2
Copy link
Member

imciner2 commented May 2, 2023

By Python do you mean just calling solve on the problem, not using the codegen wrapper? If so, then there is an expected difference in the solve times because the code generation/embedded mode will disable certain features of the solver - such as the adaptive rho computation. Disabling those can possibly increase the time needed to solve the problem. One thing to try is to take the problem and take the optimal rho values from Python and put it into the code generation version (this should hopefully give you closer timings).

@xkhainguyen
Copy link
Author

xkhainguyen commented May 2, 2023

@imciner2
Thank you for your response.
Intuitively, I thought for embedded mode, the features should encourage faster solve time.
My naive expectation is that the generated C code should be faster given the same problem setup. If not, what is the goal and workflow of the embedded mode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants