-
Notifications
You must be signed in to change notification settings - Fork 2
Remove C-Wrapper for MPI_Init #16
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
Conversation
I haven't given a look at the changes closely, but one important thing for this PR would be the addition of tests, so we definitely need a test case which makes use of |
Added a simple Test |
Haha Tests Passed |
src/mpi_c_bindings.f90
Outdated
function c_mpi_init(argc, argv) bind(C, name="MPI_Init") | ||
use iso_c_binding, only : c_int, c_ptr | ||
integer(c_int), value :: argc | ||
type(c_ptr), value :: argv |
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.
Why do both the arguments have to be pass-by-value here? What if I keep it intent(inout)
?
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.
I would like to see an explanation for why this needs to be passed with value
attribute with it.
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.
I thought that passing pointers/reference would make it complex , Hence to keep it safe i used value
Although i didn't checked with intent(inout)
So this is the current situation
Wihout value
attribute all tests passes locally
with intent(inout)
lfortran fails
with this error
code generation error: asr_to_llvm: module failed verification. Error:
Call parameter type does not match function signature!
%argv = alloca void*, align 8
void* %0 = call i32 @MPI_Init(i32* %argc, void** %argv)
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.
So, I tried locally, and when no intent is specified, then ./run_tests.sh
passes with both LFortran and GFortran.
While, when intent(inout)
is specified, then LFortran fails, but GFortran succeeds. By default, when no intent is specified, then the intent is actually intent(inout)
I think.
So, there is anyways a bug in LFortran, which should be extracted and reported against LFortran.
I thought that passing pointers/reference would make it complex
I don't really understand this. @certik any thoughts on this?
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.
I'm reading: https://docs.open-mpi.org/en/v5.0.x/man-openmpi/man3/MPI_Init.3.html#description, which says:
All MPI programs must contain a call to MPI_Init or MPI_Init_thread. Open MPI accepts the C argc and argv arguments to main, but neither modifies, interprets, nor distributes them:
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.
Let's Do one thing
We know that LFortran gives error in the intent(inout) declaration
So for now let me create an MRE and open an issue on LFortran and till then we would use value parameter,
Once that issue is resolved we will remove this workaround and things won't get blocked.
Here is the MRE:-lfortran/lfortran#6696
What's your view @gxyd
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.
Let me create issue in this repo too so that we do not skip it
Here:- #27
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.
While, when
intent(inout)
is specified, then LFortran fails, but GFortran succeeds. By default, when no intent is specified, then the intent is actuallyintent(inout)
I think.
Like I mentioned here, LFortran doesn't fail when no intent is specified, so we still need to answer, whether value
is the correct way or not specifying any intent at all.
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.
I guess maybe we need to look at any documentation for what to use
My intuition is not to use value or intent at all, (also i used GROK to do some research and the first thing it told me is not to use it)
maybe i read it somewhere, but i did not found the exact line stating that which parameter is ideal enough.
As with the value approach we might add an extra instruction of storing and then loading
Also i referred this https://gcc.gnu.org/onlinedocs/gfortran/Interoperable-Subroutines-and-Functions.html
It does not use intent(),
Also intent should not affect the passing of the objects at the runtime right?
Hence that issue iss the one which we have to fix at lfortran, but what i feel what ideal to do is not to use anything at all, until unless something comes up again with similar argument
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.
As with the value approach we might add an extra instruction of storing and then loading
Also i referred this https://gcc.gnu.org/onlinedocs/gfortran/Interoperable-Subroutines-and-Functions.html
It does not use intent()
This is good, it makes it clear that we don't need value
attribute specified here.
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.
Looks perfect now, I've removed the value
attribute from the arguments of MPI_Init
Towards
lfortran/lfortran#6564 (comment) and #21
and mimicing gxyd/POT3D#73