SE - Software Engineering

Projects for summer 2016

Automating Fortran - C Interoperability

Scientific programs supported by the large systems at NCAR are often written in a combination of Fortran and C. For about a decade now, Fortran compilers have supported the “Interoperability with C” features of Fortran 2003. This provides high-level Fortran syntax for sharing data and executable code within a program between software written in Fortran and software written in C. A common step is linking a library whose interfaces are written in C to a program written largely in Fortran. Several versions of the library may exist on target HPC systems, and on any one system as software is updated.

However, for non-trivial uses of Interoperability with C, a Fortran module must be written to express the C interfaces and data in a manner that the Fortran compiler can use to connect the C software to the rest of the program. In many instances, all the necessary information is already expressed in a C header file. Having to re-express that information in a Fortran module is tedious and error-prone, and is an ongoing maintenance issue, because the C header file and the Fortran module must be kept in synch as the library evolves, and, perhaps, as the library usage evolves.

Since the source is available for the gcc compiler, the C compiler of the GNU Compiler Collection (GCC), this source may be modified to produce the Fortran output (instead of the intermediate language emitted now), and tested via gfortran (the Fortran compiler of GCC, which supports the Interoperability features). This becomes an automated conversion tool. Of course, of all the features supported by gcc, there will be some code constructs that can be translated more easily, and other code constructs that will be difficult to translate reliably (for example, micro-editing).

Thus, the scope of this summer project is anticipated as follows:

  • Gain a sufficient understanding of the language-independent GENERIC form produced by the language front-ends of GCC to proceed.
  • Find a mapping from the GENERIC tree produced by gcc to the GENERIC tree that would be produced by gfortran that can be used to generate the Fortran module.
  • Implement the same.
  • Iterate the build, test, improve cycle using header files found on NCAR systems.

For several levels of reliability of the conversion tool, the following advantages are expected:

  • Any aid in writing an interoperability module will assist the applications programmer, even in cases where the automatic conversion is, by itself, not entirely correct.
  • A reasonably mature tool, likely with a few known weaknesses, will nevertheless assist programmers when porting mixed-language programs.
  • A more reliable tool would allow versions of libraries written in C to be tested without the overhead of manually making, or manually updating, interface modules.
  • The ultimate goal is to produce a tool of such reliability that it may be included in build scripts with confidence.

Skills/qualifications: Open to CS upper-division undergraduates (or graduate students), experience with GCC internals is needed. Experience in software testing, and fluency in Fortran and C will be very helpful. Knowledge of configuring and building GCC is also helpful (but can be learned quickly).