-
Notifications
You must be signed in to change notification settings - Fork 389
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
Modify EnergyPlus structure to expose it as a callable shared library #4522
Conversation
…rary - This built successfully on Linux. - There are CMake rules added that should be cleaned. - The library wont compile on Linux because I added a unistd.h; need to figure out how to best chdir on Windows [#80310170]
Exposed EnergyPlusPgm in main.cc Added program.cc that links against the dynamic library
- Only set fPIC flag on Linux...Windows DLLs don't need it, not sure about Mac...... - Import a couple Windows headers to gain access to _chdir - Add decoration to exported functions on Windows so a .lib file is created - Adjustment of file path in test program for Windows
@mjwitte @kbenne @lefticus @DeadParrot @nealkruis @lgentile SummaryThis pull request would bring in the code necessary to build EnergyPlus as a shared library. This is how GUIs like DesignBuilder prefer to run EnergyPlus, as it lets them register callbacks within EnergyPlus, which EnergyPlus then calls back to with updates on messages and simulation progress. ChangesThe changes made include:
StatusI have tested this on Windows and Linux. Previously this had never been available for anything but Windows, so this is actually an enhancement. Right now the library code should be isolated from any non-library operation, so there should be no issue there. It works really great with the test program I put in there, so at this point, I would just like some of you to provide feedback on the #includes, the CMake rules, etc., in case there is anything I missed. I'm not looking to really add any more functionality, as this satisfies the capabilities from before the C++ translation, and as yet I haven't had to invest any significant amount of time, and I'd like to keep it that way. |
@Myoldmopar this seems good to me -- no obvious red flags. For this kind of EnergyPlus-as-a-service use the typical problems of throwing exceptions and heap management across DLL boundaries should not be an issue. |
Thanks a lot @DeadParrot! In that case, @mjwitte, I think this is ready to |
Um, OK, I'm not sure I know how to review this, so handing it off to @kbenne or @nealkruis |
Well, I don't know what that whole unhandled elemental failure is about (@lefticus), but in any case, I would say the review process could be:
|
Also retested on Windows and it works great.
@kbenne Do you have time to verify this? If not I'll find someone else to give it a try. Thanks! |
This work makes EnergyPlusLib a shared library, with main becoming a very light wrapper that calls into the function EnergyPlusPgm. EnergyPlusPgm is the main function in the shared library's interface. The EnergyPlusLib shared library is installed alongside the main energyplus executable and distributed in the normal package. In this way there is no separate distribution of the EnergyPlus DLL. It will come with the regular installer package.
…EnergyPlusTeam into 80310170-EnergyPlusLibrary
…cks; re-delete program.cc
- Surgical export of symbols necessary to get EnergyPlusLib_Test working. Note that this is kind of messy since all data is global. Lots of individual symbols to export instead of just one or two classes. [#80310170] @Myoldmopar
[#80310170]
@kbenne @Myoldmopar @lgentile it has been 7 days since this pull request was last updated. |
Just merged develop into this branch to get it to pick up the parametric processor fixes, but this should be good to go. @kbenne ? |
@kbenne CI is pleased with this branch now; care to merge? Any reason to wait? |
- This has the benefit of allowing unit tests to link statically so we dont need to decorate all the unit test functions and variables as we add more unit tests - This causes a 3-layer build process: - First build a static library of nearly all the EnergyPlus source code. Unit tests are linked against this - Second build a shared library that is linked against the static library and EnergyPlusPgm.cc, which just exposes the public API - Third build the EnergyPlus binary which is a super thin wrapper over the shared library
@mjwitte @rraustad @kbenne @lefticus @DeadParrot @lgentile OverviewI figure this could involve you guys quite a bit, so I wanted to give you a heads up as to the status here. While in the past we had built the EnergyPlus DLL as a little side project, we decided moving forward, it would be better to include it directly in the build/test process so it is always available and always tested. HistoryWe have been, for a few months now, building EnergyPlus as a static library first, then building the executable directly against this. It worked well, because unit tests could be linked to the static library. Since we were building a shared library (dll) now, we decided, OK we'll just convert that static library into a dynamic library. However, this was problematic. When the library is dynamic, all the symbols (variables, functions) that are needed by unit tests must be exported. @lefticus did this here. With our few (6) unit tests, this started revealing an ugly pattern. Pretty soon variables and functions across the code would require this decoration to be unit tested. New ProcessSo, we decided on a little longer list of build steps. I must note here that with CMake creating your projects, you will be almost not affected, which is awesome. Here are the build steps now:
Action items
Status
|
Minor quibble. I suggest EnergyPlusLib for the static library and EnergyPlusAPI for the dll. |
@kbenne Quibble understood. I'll update those names and also try to implement a CI test for this work. Then I'll merge develop in to resolve whatever merge conflict occurred and this should be ready to merge later today. |
@Myoldmopar I just happened to be working on this branch myself. I have resolved the conflict and will push momentarily. |
Bonus! |
…sLibrary [#80310170]
@kbenne So, if I'm following correctly, the EnergyPlus install folder will contain a tiny EnergyPlus.exe and a large EnergyPlusAPI.dll with the API and all the rest of EnergyPlus? EnergyPlusLib seems to describe the contents better that EnergyPlusAPI. Or am I misunderstanding your quibble. |
@Myoldmopar not sure. |
@mjwitte you are understanding correctly. The build directory on the other hand will have a large static library, an equivalently sized DLL due to that fact that the static library is linked in, and a small execrable. This PR does not explicitly install the static library, it has little value besides providing a compilation unit to link the tests to. |
@mjwitte Oh and the root of my minor quibble is that I believe core is rather vague and arbitrary. It becomes ambiguous as to what constitutes "core". We used the term in OpenStudio and I think looking back now it seem rather silly. I was just suggesting, recognize the arbitrariness and use words that indicate something more concrete. Such as these things are public (meaning we support their consumption by our clients - API) and these other things are private, meaning you should not even need to know they exist as a client. The physical size doesn't really factor in. Yes the API is small in number of functions, but it happens that those functions (run program) pack a wallop. |
@kbenne Whatever you and @Myoldmopar have agreed upon is fine with me. |
@kbenne Will you be able to merge this in or should I gather a different dev? |
I'm very curious about how this feature works. Is there any further documentation or examples of using the API? Thanks |
Not as of right now, outside of the discussion above. The development team has goals to expose more underlying energy plus stuff in the api, but right now that's just in the plans. If you want to use the energypluspgm public function mentioned above just write back here and I can add detail. |
Thanks Myoldmopar; will do. |
This is starting to look very promising.
void EnergyPlusPgm()
Thus everything works perfectly on Linux.
ToDo: