Make MCPL a Runtime Optional Dependency#3429
Conversation
paulromano
left a comment
There was a problem hiding this comment.
@tkittel Does this PR look sensible to you? From a quick scan, it looks very similar to what we did with the NCrystal interface.
|
This PR would be useful for getting the sci kit build core working again. Any objections to merging |
paulromano
left a comment
There was a problem hiding this comment.
Just putting a placeholder review as I'd like to take a look before we merge this. I was also hoping to get @tkittel's vote of confidence on this. I'm assuming he's been in the loop on this?
I've not seen any conversations on this PR outside of this PR thread. |
|
Hi guys. Sorry, I am on vacation so I didnt have a chance to look at this. I like the aim of this PR though :-) Not 100% sure when I might have a chance to have a look at the details, but perhaps I can find a quiet moment within the next few days. |
|
Hi guys, So I had a very quick skim through, and I have a few comments. Do keep in mind though, that the OpenMC-MCPL bindings were initially contributed by @ebknudsen not me. In general, big thumbs up to the work here. And yes, the intention is to have the MCPL C ABI stable enough to do these kinds of things. I have a few minor issues though:
Anyway, apart from the points above and the fact that it was just a quick skim-through, it all looks great to me :-) |
37bdd16 to
adeec84
Compare
|
Hi @tkittel, Thank you very much for taking the time to review the changes and for your excellent, detailed feedback. Here’s a summary of the key changes based on your points:
|
|
Great @ahnaf-tahmid-chowdhury, all looks good as far as I am concerned then 😄 |
|
Many thanks for the suggested improvements @tkittel and updated implementation @ahnaf-tahmid-chowdhury |
|
@paulromano is this one ok to merge, I see you have a holding review on it. |
paulromano
left a comment
There was a problem hiding this comment.
Just made a few small updates here but otherwise looks good. Thanks all!
Description
This pull request refactors the MCPL interface in OpenMC to make MCPL a runtime optional dependency rather than a build-time one. This version enhances the previous effort by implementing cross-platform dynamic library loading and discovery mechanisms, including support for Windows.
Benefits
Key Changes
CMake Modifications:
OPENMC_USE_MCPLCMake option.Cross-Platform Runtime Library Loading (
mcpl_interface.cpp):dlopen()on POSIX-like systems (Linux, macOS).LoadLibraryA()on Windows.dlsym()on POSIX.GetProcAddress()on Windows.void*orHMODULE) and cleanup functions (dlcloseorFreeLibrary) are used.McplApistruct holds these function pointers.initialize_mcpl_interface_if_needed) handles the loading and symbol resolution.Library Discovery Mechanisms:
The
initialize_mcpl_interface_implfunction attempts to locate the MCPL library in the following order:mcpl-config --show libpathCommand:popen()on POSIX systems._popen()on Windows systems (requiresmcpl-config.bator.exeto be in the systemPATH).libmcpl.so,libmcpl.dylibon POSIX.mcpl.dll,libmcpl.dllon Windows. These are searched in standard system library locations (e.g., those covered byPATHon Windows orLD_LIBRARY_PATHon Linux).Avoidance of
mcpl.hat Compile Time:mcpl.his not included to ensure MCPL is not a compile-time dependency.Necessary MCPL data structures (e.g.,
mcpl_particle_t) and function signatures are manually re-declared withinmcpl_interface.cppasmcpl_particle_repr_t, etc.Error Handling and User Guidance:
fatal_errors with an informative message, suggesting installation (e.g.,pip install mcpl) and how to make the library findable.is_mcpl_interface_available()function can be used to programmatically check MCPL availability.Code Updates:
mcpl_interface.cppuse the dynamically resolved function pointers.MCPL_ENABLEDpreprocessor logic has been removed.