SIParCS 2017-Michelle Anderson

Michelle Anderson

Michelle Anderson, University of Minnesota-Twin Cities

Facilitating Fortran and C Interoperability with the h2m-AutoFortran Tool

Recorded Talk

Large, high-performance programs are often written in Fortran because of its excellent features for parallelism. Modern Fortran supports interoperability with C, which is beneficial because C offers a large selection of useful libraries. However, preparing the interface to properly link a Fortran program to a C library can be tedious and error prone. The h2m-AutoFortran tool can greatly simplify this process by harnessing the power of the Clang Compiler's abstract syntax tree to analyze C header files and translate them into corresponding interoperable Fortran modules. The h2m prototype, completed by Sisi Liu, has been improved to provide new functionality including a more reliable build system, warnings for untranslatable features, checks against duplicate declarations, initialization for complicated structures, options for recursive translation of included header files, and automatic changes to invalid names. Documentation, examples, and tests have been written to accompany the software. The tool is capable of translating headers from complicated libraries including the C standard, NetCDF, and Curl libraries. Minimal user intervention is necessary to produce correct, compilable code. An assessment of eleven system and library headers comprising over 19,000 lines of C code resulted in only 27 compilation errors after translation. Most errors were not difficult to correct. In the case that the user only wishes to call library functions and is not interested in using complicated macros, a Fortran interface to a C library can be prepared in minutes, greatly decreasing the necessary time and tedium.

Mentors: Dan Nagle and Davide Del Vento