- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I asked this question here. But since this is more relevant to fortran compiler, so I reask the question again.
Basically, I have fortran dll as my backend, and C# as my front end. My backend is something like this ( trimmed down):
[fxfortran] subroutine chartest(maxncv,ldv) !DEC$ ATTRIBUTES DLLEXPORT::chartest !DEC$ ATTRIBUTES ALIAS:'chartest'::chartest !DEC$ ATTRIBUTES VALUE :: maxncv,ldv & integer, intent(in) :: maxncv, ldv Double precision & v(ldv,maxncv),d(maxncv,2) print *, 'hello' end[/fxfortran]
And my C# code is something like this:
[bash] public static extern void chartest( [MarshalAs(UnmanagedType.I4)] int maxncv, [MarshalAs(UnmanagedType.I4)] int ldv );[/bash]
If I call
chartest(546, 547)
, I would get a stackoverflowexception.I understand and verify that by turning on the/heap_arrays I can overcome this exception, but from what I've read, my code shouldn't generate any stackoverflowexception, since the array assignment is done inside fortran code. Is there anything missing here?
If not then I have to turn on the \\heap_arrays option as mentioned. Is there is a better solution?
I'm using version 11.0.066
링크가 복사됨
5 응답
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Suggest you search the forum for C#. From what I can see, you need to use REFERENCE rather than VALUE:
By default scalar type like integer is passed by reference in fortran so its corresponding in C# should be declared as reference type.
Regards,
David
By default scalar type like integer is passed by reference in fortran so its corresponding in C# should be declared as reference type.
Regards,
David
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Thanks for your advice, but I'm not sure whether by changing to "passed by reference ", will it solve my problem?
For small input parameters, my code can run fine, so I don't think pass by reference/ value is the problem here.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
My concern was about the value of the array size which you are passing as an argument. Is the value on in C# and in Fortran the same or is it being corrupted? You may need to use STDCALL for the argument passing as well.
Regards,
David
Regards,
David
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
David,
But it were corrupted, why for small values of ints, there were no sign of corruption?
Also, in my fortran code, I explicitly specify the pass in parameters as value:
[fortran]!DEC$ ATTRIBUTES VALUE :: maxncv,ldv [/fortran]So I don't think there is any issue of corruption
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Your Fortran local arrays d and v are "automatic" which means they will be created on the stack by default. You can either use /heap_arrays or change the arrays to allocatable and add code to manage the allocate and deallocate.
