snopt / snopt-interface

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

prevent snmema from running with the snoptA interface #21

Closed stevenjj closed 6 years ago

stevenjj commented 6 years ago

Hi. I've been using the C++ snoptA interface with great success for a while now.
My question is essentially the following: How do I configure the snoptA interface properly so that snmema will not run when I call the solve subroutine?

Currently, I'm in the phase of attempting to speed up the solve routine as much as possible and after implementing all of the analytical constraint Jacobians, my bottleneck appears to be the optional snmema routine that I cannot remove.

According to the documentation, snmema is just for identifying mincw, miniw, and minrw. I attempted to configure the snoptA interface using the wrapper functions setIntParameter and setUserspace. However, snmema still runs at the beginning of every subroutine call.

Am I missing something? I'm not sure if this is simple or not, but I would happily like some guidance about this small configuration problem I am having.

Thank you!

gnowzil commented 6 years ago

Not currently possible...but I can change things so that it is. The C/C++ interface doesn't have the same functionality as the Fortran library. I can add an additional call to snopt so that you can provide the lengths of the workspace arrays and the allocated workspaces.

setUserspace is for the user workspace that can be accessed through the user-defined subroutines (e.g., in funcon/funobj), not the actual workspace.

stevenjj commented 6 years ago

Thank you for the quick response! From your answer, it's quite clear that snmema cannot be skipped for snopt B and C interfaces as well right?

It seems that I just have to wait / hope for that feature to be added in future interfaces.

gnowzil commented 6 years ago

Yeah, it works the same with B and C. I don't think it would take me long to add this -- but I'll need a few days.

gnowzil commented 6 years ago

Try the new branch 'version2.2'. I've added new constructors in C++ where you can pass iw/leniw and rw/lenrw. If all of those values are defined appropriately, then the workspace will be accepted without any internal modification. If leniw or lenrw are < 500, then snMem will be called. If the lengths are acceptable but iw or rw are null, then they will be allocated with your given leniw/lenrw values with no call to snMem.

stevenjj commented 6 years ago

Thank you! It looks like I have to upgrade from 7.6 to 7.7. I have to contact my university to get the new libraries to actually test this out.

gnowzil commented 6 years ago

You can also get trial libraries on our website: https://ccom.ucsd.edu/~optimizers/

stevenjj commented 6 years ago

Alright! I just tried the new interface with the trial snopt 7.7 library. Your new constructor definitely works. :+1: Thanks for the quick response!

After initially setting 500 for leniw and lenrw, it was nice that the solver told me the actual minimum needed. So I increased the lengths appropriately. Now, snmema doesn't run anymore.

For other curious users, my constructor looks like so:

  int leniw = 50000;
  int lenrw = 50000;
  int *iw = new int[leniw]; 
  double *rw = new double[lenrw];   
  snoptProblemA snopt_optimization_problem(iw, leniw, rw, lenrw);