visit-dav / visit

VisIt - Visualization and Data Analysis for Mesh-based Scientific Data
https://visit.llnl.gov
BSD 3-Clause "New" or "Revised" License
408 stars 109 forks source link

LibsimV2 Fortran-interface is missing hidden arguments #2446

Open aowen87 opened 5 years ago

aowen87 commented 5 years ago

Hi everyone, if one calls a Cfunction from Fortran and it includes a CHARACTER argumentFortran will call that function with an additional hidden argument for the length of the CHARACTER at the end of the argument list(as long as you are not using BIND, which is part of Fortran2003).Example: CHARACTER :: name = "foo" INTEGER :: arg2, arg3 [...] call foo_C_function(name, arg2, arg3)Required function definition in Clib: void foo_C_function(char name, int arg2, int arg3, int name_f77len) Currently this is not considered in the VisIt Fortran interface.Hence, with each function call from Fortran to VisIt an additional int is written to the stack, which is not expected. This can lead to unexpected errors, which are hard to track. It can be solved for all functions defined in visitfortransimV2interface.c easily.I attached a fix, which works fine for me. It changes all function definitions expecting on or more CHARACTER arguments in Fortran.Example: FORTRANF_VISITSETDIRECTORY(VISIT_F77STRING dir, VISIT_F77_MIXED_STRLEN(dir) int ldir VISIT_F77_END_STRLEN(dir)) with VISIT_F77_MIXED_STRLEN and VISIT_F77_END_STRLEN defined in VisItFortran.h like this: #ifdef USE_VISIT_F77_MIXED_STRLEN#define VISIT_F77_MIXED_STRLEN(a) ,int a ## _f77hiddenlen#define VISIT_F77_MIXED_STRLEN_DECL ,int#define VISIT_F77_END_STRLEN(a)#define VISIT_F77_END_STRLEN_DECL#else#define VISIT_F77_MIXED_STRLEN(a)#define VISIT_F77_MIXED_STRLEN_DECL#define VISIT_F77_END_STRLEN(a) ,int a ## _f77hiddenlen#define VISIT_F77_END_STRLEN_DECL ,int#endif This is the common approach for Fortran77 interfaces you can find for example in MPIC](http://compbio.cs.toronto.edu/repos/snowflock/mpich-1.2.7/mpid/ch_nt/nt_ipvishm/include/mpidefs.h) MPI_GET_PROCESSOR_NAME( char FORT_MIXED_LEN_DECL, MPI_Fint , MPI_Fint FORT_END_LEN_DECL );http://sourcecodebrowser.com/mpich2/1.2.1/mpi__fortimpl_8h_source.html #define FORT_MIXED_LEN_DECL, #define FORT_END_LEN_DECL more: https://gcc.gnu.org/onlinedocs/gfortran/Argumentpassingconventions.html Microsoft Fortran adds the argument not at the end, but just after the CHARACTER arg - hence, FORT_MIXEDLEN is also provided, but just for completeness.

-----------------------REDMINE MIGRATION----------------------- This ticket was migrated from Redmine. As such, not all information was able to be captured in the transition. Below is a complete record of the original redmine ticket.

Ticket number: 2442 Status: Pending Project: VisIt Tracker: Bug Priority: Normal Subject: LibsimV2 Fortran-interface is missing hidden arguments Assigned to: - Category: - Target version: - Author: Jens Henrik Goebbert Start: 11/02/2015 Due date: % Done: 0% Estimated time: Created: 11/02/2015 11:06 am Updated: 11/03/2015 07:00 pm Likelihood: 3 - Occasional Severity: 2 - Minor Irritation Found in version: trunk Impact: Expected Use: OS: All Support Group: Any Description: Hi everyone, if one calls a Cfunction from Fortran and it includes a CHARACTER argumentFortran will call that function with an additional hidden argument for the length of the CHARACTER at the end of the argument list(as long as you are not using BIND, which is part of Fortran2003).Example: CHARACTER :: name = "foo" INTEGER :: arg2, arg3 [...] call foo_C_function(name, arg2, arg3)Required function definition in Clib: void foo_C_function(char name, int arg2, int arg3, int name_f77len) Currently this is not considered in the VisIt Fortran interface.Hence, with each function call from Fortran to VisIt an additional int is written to the stack, which is not expected. This can lead to unexpected errors, which are hard to track. It can be solved for all functions defined in visitfortransimV2interface.c easily.I attached a fix, which works fine for me. It changes all function definitions expecting on or more CHARACTER arguments in Fortran.Example: FORTRANF_VISITSETDIRECTORY(VISIT_F77STRING dir, VISIT_F77_MIXED_STRLEN(dir) int ldir VISIT_F77_END_STRLEN(dir)) with VISIT_F77_MIXED_STRLEN and VISIT_F77_END_STRLEN defined in VisItFortran.h like this: #ifdef USE_VISIT_F77_MIXED_STRLEN#define VISIT_F77_MIXED_STRLEN(a) ,int a ## _f77hiddenlen#define VISIT_F77_MIXED_STRLEN_DECL ,int#define VISIT_F77_END_STRLEN(a)#define VISIT_F77_END_STRLEN_DECL#else#define VISIT_F77_MIXED_STRLEN(a)#define VISIT_F77_MIXED_STRLEN_DECL#define VISIT_F77_END_STRLEN(a) ,int a ## _f77hiddenlen#define VISIT_F77_END_STRLEN_DECL ,int#endif This is the common approach for Fortran77 interfaces you can find for example in MPIC](http://compbio.cs.toronto.edu/repos/snowflock/mpich-1.2.7/mpid/ch_nt/nt_ipvishm/include/mpidefs.h) MPI_GET_PROCESSOR_NAME( char FORT_MIXED_LEN_DECL, MPI_Fint , MPI_Fint FORT_END_LEN_DECL );http://sourcecodebrowser.com/mpich2/1.2.1/mpi__fortimpl_8h_source.html #define FORT_MIXED_LEN_DECL, #define FORT_END_LEN_DECL more: https://gcc.gnu.org/onlinedocs/gfortran/Argumentpassingconventions.html Microsoft Fortran adds the argument not at the end, but just after the CHARACTER arg - hence, FORT_MIXEDLEN is also provided, but just for completeness.

Comments:

griffin28 commented 5 years ago

2446_archive.zip