Overview
General Overview

The f2j project has several objectives:

  1. Writing a Fortran front-end capable of lexing and parsing the subset of Fortran necessary to translate BLAS and LAPACK.
  2. Generating Java source and JVM bytecode to produce class files for use with a JVM.
  3. Testing, documenting and distributing the translated BLAS and LAPACK class files.
  4. Extending the compiler to handle a wider subset of Fortran code.

We have completed stages 1-3 and are currently working on stage 4.

 


f2j Example

All of the single and double precision BLAS and LAPACK Fortran source codes have been translated directly to JVM bytecode and Java sources. Some sample files to examine:

  • dsymm.f, a symmetric matrix-matrix multiplication subroutine.
  • The translated Java source produced by f2java Dsymm.java   Dsymm.java was filtered through Percolator using the default formatting options.
  • Output class Xerbla.java to display error conditions.

 

The JVM instruction set provides a straightfoward method to translate Fortran GOTO statements. Since Fortran 77 does not specify while loops, these are implemented in BLAS and LAPACK using goto statements, which are supported at the JVM level.

  • A simple Fortran source: loops.f
  • The bytecode produced by f2j (in Jasmin output format for convenience): Loops.j

 


Current Status

 

  • Started implementing file I/O, but it's very rudimentary at this point (not
    released yet - only in the CVS code)
  • Removed all the jasmin codegen stuff since we can emit bytecode directly
  • Improved formatted READ/WRITE by incorporating the Formatter package
  • Implemented ASSIGN and assigned GOTO statements
  • Can now optionally generate the Java code as strictfp (default is not strict)
  • Now supports unlabeled DO loops
  • Support for Hollerith constants in FORMAT statements
  • Only scalars that are determined to be modified are wrapped in objects
  • Very basic handling of EQUIVALENCE
  • COMMON now supported
  • Handling of GOTO statements!
  • Can now handle passing functions as arguments
  • Elementary loop detection for while loops
  • DATA and SAVE statements are now supported
  • Lexer cleaned up and extended to handle character strings and substrings
  • Source files containing multiple functions/subroutines will now translate

 

Since ANSI Fortran 77 does not specify while loops, all such constructions in the BLAS and LAPACK are implemented with goto statements. Since the JVM has built-in goto branching, f2j easily implements all goto statements in the Fortran source by directly generating bytecode. However, we also have a scheme to translate Fortran GOTO statements into Java source code, which involves some post-processing of the generated code.

Complex numbers will most likely have to go directly to bytecode for implementation on the JVM stack. Using the object-oriented methods for complex arithmetic would likely produce unacceptable overhead for large scale numerical problems.


LAPACK

Java LAPACK has now completed the testing stage. Some of the main design issues are:

  • Arrays are being implemented as 1 dimensional in the Java translation. Access is by index arithmetic, using leading dimensions declared in the Fortran source.  This allows emulation of passing array subsections.
  • Certain variables are returned by reference, which has no counterpart in Java. Currently all scalar variables which are determined to be used in a pass-by-reference context will be wrapped as an object with a single (value) field.
  • We are now directly generating JVM class files, so GOTO statements are not a problem anymore, but for generating and recompiling Java source code, the translation of GOTO statements is done with a post-translation processing step. First, we use f2java to translate the Fortran code to Java. GOTOs are automatically translated as calls to a dummy class. So, GO TO 100 would be translated as Dummy.go_to(100); . The labels in the Fortran source are also translated as calls to the dummy class (for example, the label 100 becomes Dummy.label(100); in the Java source). Next we compile the Java file as usual (using javac). We then use a special program to analyze the bytecode and translate the dummy goto calls to real JVM goto instructions. Our tool is based on the bytecode parser in javab, a bytecode parallelizing tool under development at the University of Indiana.

 

A general solution for translating Fortran to Java may not be available without using object methods, possibly incurring large performance penalties. Our alternative is to chose those features most important to efficiency in numerical analysis, and direct the translation using the known structure of the BLAS and LAPACK Fortran source


The BLAS, Basic Linear Algebra Subroutines

Java BLAS is translated from the BLAS Fortran reference source archived at the Netlib numerical software repository. BLAS is composed of three levels of linear algebra operations:

  • Level 1 BLAS consists of vector-vector operations such as dot product, etc.
  • Level 2 BLAS consists of vector-matrix operations.
  • Level 3 BLAS consists of matrix-matrix operations.


Project Handouts

Jun 29 2022 Admin Login