Hello,
I'm trying to run a C++ function within a cs_user_physical_properties.f90 subroutine. Everything has been implemented just fine following how this C++/Fortran coupling is done in other standard routines, but i don't get why when passing fields from the fortran to C++ NaN values will appear. The only additional processing that the data will be getting in the C++ routine is a stacking operation, to have a single input tensor instead of multiple ones. I posted the routines as well to give more context.
I tried on a separate testing case and this seems to not be happening.
What can possibly be the cause of this behavior? And eventually how can i fix it?
Thanks to everyone for the help,
Francesco
NaN values when passing from a subroutine to another
Forum rules
Please read the forum usage recommendations before posting.
Please read the forum usage recommendations before posting.
NaN values when passing from a subroutine to another
- Attachments
-
- predict4fort.cpp
- (23.19 KiB) Downloaded 679 times
-
- cs_user_physical_properties.f90
- (26.4 KiB) Downloaded 685 times
-
- Posts: 4206
- Joined: Mon Feb 20, 2012 3:25 pm
Re: NaN values when passing from a subroutine to another
Hello,
Did you try running this on a debug build under Valgrind, or on a build with AddressSanitizer ? Since you have many arguments, a typo could easily hide in your code.
If this does not find any error, than printing outputs or checking for isnan() of values in the C code just before reading them back in Fortran can help determine whether the NaN"s are actually a product of the called code, or a problem with the iso-c bindings.
Also, using the C version of cs_user_physical_properties can remove the need for complex iso-C bindings, and simplify the whole thing.
You can even move cs_user_physical_properties from C to C++ by changing its extension to .cxx or .cpp, so as to be able to place the code in predict4fort.cpp directly in it. In this case, you simply need to use
instead of just
To ensure the code links and is called correctly.
Best regards,
Yvan
Did you try running this on a debug build under Valgrind, or on a build with AddressSanitizer ? Since you have many arguments, a typo could easily hide in your code.
If this does not find any error, than printing outputs or checking for isnan() of values in the C code just before reading them back in Fortran can help determine whether the NaN"s are actually a product of the called code, or a problem with the iso-c bindings.
Also, using the C version of cs_user_physical_properties can remove the need for complex iso-C bindings, and simplify the whole thing.
You can even move cs_user_physical_properties from C to C++ by changing its extension to .cxx or .cpp, so as to be able to place the code in predict4fort.cpp directly in it. In this case, you simply need to use
Code: Select all
extern "C" void
cs_user_physical_properties
Code: Select all
void
cs_user_physical_properties
Best regards,
Yvan