Computational & Technology Resources
an online resource for computational,
engineering & technology publications
Civil-Comp Proceedings
ISSN 1759-3433
CCP: 84
PROCEEDINGS OF THE FIFTH INTERNATIONAL CONFERENCE ON ENGINEERING COMPUTATIONAL TECHNOLOGY
Edited by: B.H.V. Topping, G. Montero and R. Montenegro
Paper 107

A Hybrid Concept for Numerical Applications in Java

M. Baitsch, N. Li and D. Hartmann

Ruhr-University of Bochum, Germany

Full Bibliographic Reference for this paper
M. Baitsch, N. Li, D. Hartmann, "A Hybrid Concept for Numerical Applications in Java", in B.H.V. Topping, G. Montero, R. Montenegro, (Editors), "Proceedings of the Fifth International Conference on Engineering Computational Technology", Civil-Comp Press, Stirlingshire, UK, Paper 107, 2006. doi:10.4203/ccp.84.107
Keywords: Java, linear algebra, scientific computing, benchmarking, object-oriented.

Summary
The programming language Java offers many features that make it an attractive choice: a clean object-oriented design, a large collection of ready to use classes, extensive runtime error checking and automatic garbage collection. Despite these obvious advantages, Java is often considered as not being suitable for numerically intensive scientific applications. Two of the major obstacles are that (i) Java has the reputation of being slow compared to C or Fortran [2] and that (ii) the availability of mathematical libraries e.g. for linear algebra is still limited [1]. In this paper, a novel approach for the implementation of numerical software in the Java programming language is presented. By using a hybrid approach that delegates computationally intense tasks to numerical libraries implemented in C or Fortran, the advantages of Java can be combined with the efficiency of procedural languages. The approach presented is based on a two-layer architecture. The first layer makes several numerical libraries implemented mostly in Fortran available to Java applications. The second layer is a class library for linear algebra that wraps the native routines and thus hides many implementation details from the programmer.

In the first layer, access to the native code in the numerical libraries is provided by using the Java Native Interface (JNI) which is part of the Java language specification. In order to use native code through JNI, the programmer has to define a Java class that declares one or more native functions. Furthermore, for each native function, a C function with a predefined signature has to be provided. In our case, the C functions just act as glue between the Java code and the native library. In order to avoid the tedious and error prone task of generating glue code manually the code generator genJNI has been developed. The genJNI program parses a C-header file and generates a Java class and glue code based on configurable conversion rules. The availability of the glue-code generator is a requirement for the approach presented. At the current stage, the packages BLAS (Basic Linear Algebra Subprograms), LAPACK (Linear Algebra PACKage) and ARPACK (ARnoldi PACKage) as well as the NAG (Numerical Algorithms Group) library are included and thus can be comfortably used in Java programs. Hereby, only the use of a code generator makes it possible to include these libraries comprising hundreds of subroutines within reasonable time.

The second layer is a class library that serves as object-oriented interface to the low level numerical functions. The basis of the class library is a set of interfaces and classes for matrices and vectors. The basic matrix and vector operations are defined in Java interfaces. According to the immutable design pattern, a distinction between read-only objects and mutable objects is introduced. For the matrix interface, several implementations using different storage schemes exist. For instance, there are classes for general matrices, symmetric matrices, band matrices etc. In order to keep the implementing classes lightweight, linear algebra operations have consciously not been included in the matrix and vector interfaces. Moreover, a special class called BLAM (Basic Linear Algebra Methods) has a set of static methods that is similar to the Fortran BLAS library. But other than the Fortran pendant, BLAM uses runtime type information to select the most efficient algorithm for the objects actually passed as parameters. Solving linear systems is a fundamental task in numerical applications. For this purpose, several solver classes for different types of matrices have been developed. Hereby, the solver classes encapsulate the coefficient matrix and thus can use any storage scheme to exploit a specific matrix structure (like banded or profile storage). Thus it is easy for the programmer to choose a solver that works best for the actual type of matrix. Currently, solvers for general, banded and profile matrices are provided. The same storage principle is applied to solvers for generalized eigenproblems. The corresponding eigenproblem solver classes use either subroutines from NAG or ARPACK.

In the full paper, several application examples are used to evaluate the hybrid approach for scientific Java applications. The numerical experiments are divided into two parts. In the first part, fundamental operations like matrix-matrix multiplication or the solution of a linear systems of equations are investigated individually. The use of native code can improve performance up to a factor of five to ten compared to a pure Java solution. The second part of the experiments is concerned with a Java based high order finite element system for two and three-dimensional continua. The expensive computations previously performed using Java are now delegated to native (mostly Fortran) code. The overall efficiency of the two versions is compared and the results are discussed. It is shown that the overall performance of a complex Java program can be largely improved when little portions of Java code are replaced by calls to native functions.

References
1
R.F. Boisvert, J. Moreira, M. Philippsen, and R. Pozo. Numerical computing in Java. Computing in Science and Engineering, 3(2):18-24, 2001. doi:10.1109/5992.908997
2
J. M. Bull, L. A. Smith, C. Ball, L. Pottage, and R. Freeman. Benchmarking Java against C and Fortran for scientific applications. Concurrency and Computation: Practice and Experience, 15:417-430, 2003. doi:10.1002/cpe.658

purchase the full-text of this paper (price £20)

go to the previous paper
go to the next paper
return to the table of contents
return to the book description
purchase this book (price £105 +P&P)