snopt / snopt-interface

C/C++ API for SNOPT7
MIT License
27 stars 12 forks source link

setting integer/real workspace #18

Closed hongkai-dai closed 6 years ago

hongkai-dai commented 6 years ago

I recently switched from using the f2c interface to snopt_cwrap.h, and the solution to the problem is different. I checked the print out files, and it looks that the only big difference in the problem setting is on the size of the integer/real workspace. Attached are the print out files. In f2c_out.txt f2c_out.txt, it prints out the workspace on top of the file as

 SNMEMA EXIT 100 -- finished successfully
 SNMEMA INFO 104 -- memory requirements estimated
      Total character workspace             501
      Total integer workspace          500000
      Total real workspace          500000

, while on snopt_cwrap_out.txtsnopt_cwrap_out.txt, it does not print out the workspace.

I am wondering how I can set the workspace size in snopt_cwrap.h. I tried two ways.

  1. Calling reallocI and reallocR.
  2. Calling setIntParameter(problem, "Total integer workspace", 500000l) and setIntParameter(problem, "Total real workspace", 500000l).

In both cases, the solution to the problem using snopt_cwrap.h remains different from f2c (the solutions to these two cases are the same), and snopt_cwrap_out [snopt_cwrap_out.txt](https://github.com/snopt/snopt-interface/files/2178347/snopt_cwrap_out.txt) still does not print out the size of the workspace.

hongkai-dai commented 6 years ago

I changed the code using f2c, such that the workspace is not set manually, and the results are still different. From the print out file, the only difference in the setup is the "Unbounded objective". f2c_out.txt snopt_cwrap_out.txt

I will close this issue and open another one to accurately summarize the problem

gnowzil commented 6 years ago

Just a follow up on this.

The workspace sizes are hardcoded to 500 (here and here). snMem* is called automatically to determine the appropriate amount of workspace in the C/C++ interfaces.

You could always not use the C/C++ interface and instead directly call the iso_c_binding subroutines in snopt_wrapper.f90. It would give you more control over the workspace. I wrote the interface with only "one-off" solves in mind, so it's may not the best choice for certain applications.

hongkai-dai commented 6 years ago

Got it, thanks! Now I do not set the workspace, but just let C/C++ interfaces to figure out the workspace by itself.