-
Notifications
You must be signed in to change notification settings - Fork 5
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
Starting point for a modern fortran module #6
Conversation
Sorry for not integrating with the cwrapper module in #5. I didn't see it at first. |
@ivan-pi Yes, I am using the same low-level C interfaces in the We could provide both interfaces in separate modules. One low level module with only the C interfaces and one module with object oriented features using the lower level interface module. Perhaps #5 could be merged (even if not 100% done) and then it would be easier to rebase #6 (together with potential changes) on top. As a side note: I am using the trick outlined here to avoid memory leaks for temporary objects https://www.researchgate.net/publication/255677530_Avoiding_memory_leaks_with_derived_types |
This article is written by @arjenmarkus, he will be happy to see his article being used. |
Thanks @arjenmarkus for the excellent article! I spent several hours of debugging the memory leak until I found and was saved by your article. |
There was a follow up article to the one by @arjenmarkus,
It can be downloaded here. It covers the problem of nested subprogram invocation. |
Thanks @ivan-pi for the follow up. I'll see if the issue can be reproduced with these bindings. In that case we'll need to try the same trick. Stewart also talks about this potentially being solved in Fortran 2000 (meaning Fortran 2003 I guess). |
Given the example in the paper by Stewart I tested the following program using the module in this PR: subroutine foo(x, y)
use symengine
type(basic), intent(in) :: x
type(basic), intent(inout) :: y
y = x
y = x + y
end subroutine
subroutine dostuff()
use symengine
type(Basic) :: a, b
a = SymInteger(28)
call foo(a, b)
print *, b%str()
end subroutine
program test
implicit none
call dostuff
end program When running this I cannot see any memory leak. I am linking with a debug compiled version of symengine and with the previous problem I got direct printouts of symengine objects that wasn't freed correctly, but not in this case. Perhaps this isn't a problem any longer. |
Looks great. Ironically, I never use OO in Fortran, but this would be the first example where I would use OO, to ensure memory safety and reasonable syntax. @rikardn how do you want to move forward? I am happy for you to merge this and go from there, or whatever else you want to do. |
Thanks @certik. After merging this the following needs to be done
I would like to work on 4 and potentially 1 and 3. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rikardn if you are ready, go ahead and merge this.
@certik could you please give permissions to this repo (symengine.f90) for the push-access team? Otherwise I will not be able merge. |
Done! Can you merge now? |
No, I still cannot. The permissions for the team is set to read for this repo. |
Fixed |
Sorry about that. Try now. |
Thanks! Now it works. |
This is a starting point for modern fortran bindings for symengine
The module is in symengine.f08 and a small test program is in test.f08. It at least needs Fortran 2003. To build I have used:
It implements
parse
,Basic
,Integer
andSymbol
astr
-method and overloading of arithmetic operators.The implementation is using the object oriented features and the iso_c_binding module of Fortran 2003. Binding to the symengine cwrapper. It focuses on giving as native Fortran feel of the interface as possible.