Weekly Progress Update: As of 24th June 2025
This week I focused on understanding and automating character argument handling in PETSc’s Fortran bindings.
Concepts learnt
- PeNS Functions and Character Arguments: PETSc uses
PeNS
macro to mark non-standard functions that bypass automatic Fortran binding generation. Many contain character arguments (char*
,const char[]
, singlechar
) requiring manual Fortran interfaces. - C-fortran String Interoperability: C uses null-terminated strings while Fortran uses space-padded strings with hidden length parameters. PETSc provides
FIXCHAR
/FREECHAR
macros for conversion, handling memory allocation and null termination between languages. - PETSc Automation Tools: Went through
getAPI.py
(function signature parser) andgenerateFortranBindings.py
(binding generator). Current limitations include incomplete character type detection and exclusion of PeNS-marked functions from automation.
Work Done
For automation of fortran bindings generation for functions with char
arguments:
- Extended the
getAPI.py
to recognize and categorize different character argument types, storing metadata about input/output direction and string vs single character use. - Modified the
generateFortranBindings.py
with templates to automatically generate appropriate Fortran interfaces and C stub functions for each character argument pattern. - As proof-of-concept, automated
PetscTestFile()
bindings that compile correctly and match PETSc’s Fortran conventions, eliminating need for manual binding. - Wrote tests verifying generated bindings work correctly for string input/output scenarios.
Merge Requests Status
Active MRs (as author)
Issues Assigned:
- #1779 - Keep C variable names for Fortran interfaces
Next steps:
- Resolve the pipeline issues
- Implement review feedback
- Work on fixing assigned issue
- Meeting with mentors to discuss the next incremental step.