Extrait du support de cours java and numerical computing
1 Introduction
We start this article by asking: Does Java have a role to play in the world of numerical computing? We strongly believe so. Java has too much to offer to be ignored. First of all, Java is portable at both the source and object format levels. The source format for Java is the text in a.javafile. The object format is the bytecode in a .classfile. Either type of file is expected to behave the same on any computer with the appropriate Java compiler and Java virtual machine. Second, Java code is safeto the host computer. Programs (more specifically, applets) can be executed in a sandbox environment that prevents them from doing any operation (such as writing to a file or opening a socket) which they are not authorized to do. The combination of portability and safety opens the way to a new scale of web-basedglobal computing, in which an application can run distributed over the Internet [?]. Third, Java implements a simple object-oriented model with important features (e.g., single inheritance, garbage collection) that facilitate the learning curve for newcomers. But the most important thing Java has to offer is its pervasiveness, in all aspects. Java runs on virtually every platform Universities all over the world are teaching Java to their students. Many specialized class libraries, from three-dimensional graphics to online transaction processing, are available in Java.
2 The Performance of Java
A common reaction of numerical programmers when first confronted with the thought of using Java for their code is “But Java is so slow!” Indeed, when the first Java virtual machines appeared, they worked by strictly interpreting the bytecode in.classfiles, and delivered very poor performance. Some people reported Java programs running up to 500 times slower than the equivalent C or Fortran codes.
Much has changed in the past few years. Today nearly every JVM for traditional computing devices (i.e., PCs, workstations, and servers) uses just-in-time (JIT) compiler technology. JITs operate as part of the JVM, compiling Java bytecode into native machine code at runtime. Once the machine code is generated, it executes at raw machine speed. Modern JITs perform sophisticated optimizations, such as array bounds checking elimination, method devirtualization, and stack allocation of objects. Driven by the enormous market for Java, vendors are motivated to continuously improve their JVMs and JITs.
2.1 Examples of Java performance
To help understand Java numerical performance, we took a sampling of common computational kernels found in scientific applications: Fast Fourier Transforms (FFT), successive over-relaxation (SOR) iterations, Monte-Carlo quadrature, sparse matrix multiplication, and dense matrix factorization (LU) for the solution of linear systems. Each kerenel typifies a different computational style with different memory access patterns
and floating point manipulations. Together, these codes make up the SciMark [3] benchmark, one of the more popular Java benchmarks for scientific computing, and whose components have also been incorporated into the Java Grande Benchmark Suite [?]. SciMark was originally developed in Java, not translated from Fortran or C, so it represents a realistic view of how one would program in that language. Furthermore, it is easy to use – anyone with a Java-enabled Web browser can run it by a few clicks of their mouse button
2.2 The role of language specifications
Not all the performance improvements during the last few years are attributed to enhancements in JVM and JIT technology. In some cases, the Java language specification itself was detrimental to performance, and the specification was changed. More specifically, Java 1.2 onwards allows for floating-point computations to be performed with extended exponent range, which is more efficient on x86class processors (e.g., the Pentium). The result is that Java class files utilizing floating-point can sometimes produce slightly different results on thex86than on the PowerPC or the SPARC, for example. Java programmers who still require strict reproducibility can use the new keywordstrictfpon methods and classes to enforce it, but performance degradation may result.
2.3 Are we there yet?
Problems with Java performance still remain, and they will have to be tackled in the way they have been tackled before: with a combination of language specification changes and new JVM and compiler technologies. It is still possible to write Java code that is order of magnitudes slower than equivalent Fortran code. Because JITs operate at runtime, they have a limited time budget and cannot perform extensive analysis and transformations of the scale done by current static compilers. The representation of elementary numerical values (such as complex numbers) as full-fledged objects exerts a heavy toll on performance. These challenges to Java performance, and some proposed solutions, will be discussed below in more detail. For now, it is important to realize that the current performance of Java can be very competitive in some cases.
……..
Support de cours Java and numerical computing (149 KO) (Cours PDF)