I am working on software that needs to be called a family of optimization solvers. Each solver is an automatically generated piece of C code, with thousands of lines of code. I use 200 of these solvers, differing only in the size of the optimization problem that needs to be solved.
All-in-one, these auto-generated solvers are approximately 180 MB of C code, which I compile in C ++ using the extern "C"{ /*200 solvers' headers*/ } syntax extern "C"{ /*200 solvers' headers*/ } in Visual Studio 2008. Compiling all of this is very slowly (using "maximum speed / O 2", it takes about 8 hours). For this reason, I thought it would be nice to compile the solvers into one DLL, which I can then call from separate software (which will have a reasonable compilation time and allow me to abstract this whole extern) C "from a higher level code.) Compiled The DLL then is about 37 MB.
The problem is that when executing one of these solvers using DLLs, the execution takes about 30 ms. If I were to compile only the one that solves in the DLL and calls it from the same program, the execution is about 100 times faster (<1ms). Why is this? Can I get around this?
The DLL is as follows. Each solver uses the same structures (i.e., they have the same member variables), but they have different names, therefore, all types of casting.
extern "C"{ #include "../Generated/include/optim_001.h" #include "../Generated/include/optim_002.h" #include "../Generated/include/optim_200.h" } namespace InterceptionTrajectorySolver { __declspec(dllexport) InterceptionTrajectoryExitFlag SolveIntercept(unsigned numSteps, InputParams params, double* optimSoln, OutputInfo* infoOut) { int exitFlag; switch(numSteps) { case 1: exitFlag = optim_001_solve((optim_001_params*) ¶ms, (optim_001_output*) optimSoln, (optim_001_info*) &infoOut); break; case 2: exitFlag = optim_002_solve((optim_002_params*) ¶ms, (optim_002_output*) optimSoln, (optim_002_info*) &infoOut); break; case 200: exitFlag = optim_200_solve((optim_200_params*) ¶ms, (optim_200_output*) optimSoln, (optim_200_info*) &infoOut); break; } return exitFlag; }; };
source share