Overview
General Overview

The f2j project is composed of several phases:

  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.


f2j Example

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

  • dsymm.f, a 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

  • Only scalars that are determined to be modified are wrapped in objects.
  • Limited support for READ (but not formatted).
  • Limited support for WRITE/FORMAT.
  • 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.

However, 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. User interface issues have not yet been resolved
  • 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.
  • 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.


Nov 23 2009 Admin Login