[PDF] [PDF] Java and Numerical Computing

It fails, however, to provide some of the features that hard-core numerical programmers have grown accustomed to, such as complex numbers and true 



Previous PDF Next PDF





[PDF] Java and Numerical Computing

It fails, however, to provide some of the features that hard-core numerical programmers have grown accustomed to, such as complex numbers and true 



[PDF] MJ: An imperative core calculus for Java and Java with effects

The key difficulty is the interaction between the effects system and the abstraction facilities (mainly the notions of class and subclass) that makes Java, and object-  



[PDF] Featherweight Java: A Minimal Core Calculus for Java - UPenn CIS

Featherweight Java to Featherweight GJ, which includes generic classes and methods Section 4 presents an erasure map from FGJ to FJ, modeling the



[PDF] Comparing Observed Bug and Productivity Rates for Java and C++

When defects were measured against development time, Java and C++ showed no difference, but C++ had two to three times as many bugs per hour Statistics 



[PDF] Design Pattern Implementation in Java and AspectJ

As an initial experiment we chose to develop and compare Java [27] and AspectJ [25] implementations of the 23 GoF patterns AspectJ is a seamless aspect- 



[PDF] Comparative Study of C, C++, C# and Java Programming - CORE

In this thesis, the research in programming language was conducted Four of the most popular programming languages C, C++, C# and Java are chosen to be the  



[PDF] Comparison of Software Structures in Java and - CEUR-WSorg

Comparison of Software Structures in Java and Erlang Programming Languages ANA VRANKOVI ´C, TIHANA GALINAC GRBAC, University of Rijeka, Faculty 



[PDF] Introduction to Java and object-oriented programming Volume 1

This is an extract from a subject guide for an undergraduate course offered as part of the University of London International Programmes in Computing

[PDF] conditions java

[PDF] aide memoire java

[PDF] comparer chaine de caractere java

[PDF] operateur java

[PDF] java & operator

[PDF] javascool boucle for

[PDF] exemple situation probleme

[PDF] javascool string

[PDF] tableau javascool

[PDF] fonction javascool

[PDF] javascool random

[PDF] situation problème dans l'enseignement

[PDF] situation problème didactique

[PDF] caractéristiques démographique définition

[PDF] exercices de démographie

JavaandNumerical Computing

Ronald F.Boisvert Jos¥eMoreira MichaelPhilippsenRoldanPozo

1 Introduction

Westart thisarticle byasking: DoesJa va hav ea roletoplayintheworld ofnumericalcomputing?We strongly believeso.Jav ahas toomuchtoofferto beignored. Firstof all,Ja va isportableatboth the source andobject formatle vels. ThesourceformatforJav ais thete xtin a.javale. Theobject format is thebytecode ina .classle. Eithertype ofle ise xpectedto behav ethesameon any computerwith the appropriateJa vacompilerandJav avirtual machine.Second, Javacodeissafeto thehost computer. Programs (morespecically ,applets)canbe ex ecutedin asandbox environmentthatprevents themfrom doing anyoperation(such aswriting toa leor openinga socket)which they arenot authorizedto do.The combinationofportability andsafetyopensthewaytoanewscaleofweb-basedglobalcomputing,inwhich an applicationcan rundistrib utedo verthe Internet[?]. Third,Ja vaimplementsasimpleobject-oriented

model withimportant features( e.g., singleinheritance, garbagecollection) thatfacilitate thelearning curve

for newcomers.Butthe mostimportant thingJa va hasto offer isitspervasiveness, inall aspects.Ja va runs onvirtually ev eryplatformUniversitiesall ov ertheworldareteaching Jav atotheirstudents.Many

specialized classlibraries, fromthree-dimensional graphicsto onlinetransaction processing,are av ailable

in Java. Withsuch univ ersalavailabilityandsupport, itonlymakessensetoconsider Jav afor thede velopment of numericalapplications. Indeed,a growing communityof scientistsandengineersde veloping new appli- cations inJa vahasbeenslowly dev eloping.A rallyingpointforthis communityhasbeentheJav aGrande

Forum( http://www.javagrande.org) (seesidebar).

There aresome difculties, though,withthewide-scale adoptionof Jav aas alanguage fornumerical computing. Java,initscurrent stateofspecicationand lev el of implementation,is probablyquiteadequate for someof theGUI, postprocessing,and coordinationcomponents ofalarge numericalapplication.Itfails, however,toprovidesomeof thefeatures thathard-corenumericalprogrammers hav egro wnaccustomed to, suchas complex numbersandtruemultidimensional arrays.Finally ,a sa ny languagethat catersto programmers ofnumerical applications,Ja va hastopassthecriticaltest: itsperformance onoating-point intensivecodemust be(at least)on parwith theincumbents Cand Fortran.

2 TheP erformanceofJava

A commonreaction ofnumericalprogrammerswhenrstconfronted withthe thoughtofusingJa vafortheir

code isìBut Jav aissoslow!îIndeed, whenthe rstJavavirtualmachines appeared,the yworkedbystrictly

interpretingthebytecodein.classles, anddeli veredverypoorperformance.SomepeoplereportedJava programs runningup to500 timesslo werthan theequi valentCo rF ortrancodes. Much haschanged inthe pastfe wyears. Today nearlyevery JVMfor traditionalcomputingdevices

(i.e., PCs,workstations, andservers)uses just-in-time(JIT)compilertechnology .JITs operateaspartof the

JVM, compilingJa vabytecodeintonativ emachine codeat runtime.Oncethemachinecodeis generated, it executesatraw machinespeed. ModernJITsperformsophisticated optimizations,such asarray bounds 1 checking elimination,method devirtualization, andstackallocationof objects.Dri ve nb ythe enormous market forJa va,vendorsaremotiv atedtocontinuouslyimpro ve theirJVMsandJITs.

2.1 Examplesof Ja vaperformance

Tohelp understandJa va numericalperformance,wetookasampling ofcommon computationalkernels foundinscienticapplications:FastF ourierTransforms(FFT),successiveo ver-relaxation (SOR)iterations, Monte-Carlo quadrature,sparse matrixmultiplication, anddense matrixfactorization (LU)for thesolution oflinearsystems.Eachkerenel typiesadifferentcomputationalstylewithdifferentmemoryaccesspatterns and oatingpoint manipulations. Together,thesecodesmakeuptheSciMark[3]benchmark, oneofthemorepopularJa vabenchmarksfor scientic computing,and whosecomponents hav ealso beenincorporatedintotheJav aGrande Benchmark Suite [?]. SciMarkwas originallyde veloped inJava,not translatedfrom FortranorC,soitrepresentsa realistic viewof howone wouldprograminthatlanguage.Furthermore, itis easyto useñ an yonewith a Java-enabledWe bbrowsercanrunit byafe wclicks oftheir mouseb utton. At thebenchmarkí swebsite,http://math.nist.gov/scimark, weha vecollectedSciMark scores foro ver1,000differentJav a/hardware/operating-system combinations,fromlaptopsto highend workstations, representinga thoroughsample ofJa va performanceacross thecomputationallandscape.As of thiswriting, SciMarkscores ofo ve r130 Mops(theaverageforthe ve kernels)ha ve beendemon- strated. Figure1 shows thecompositescore(in Mops)of thisbenchmark onsix different architectures, and illustratesthewiderange inperformanceov er commonplatforms. TherstobservationisthatJav aper - formance isclosely tiedto theimplementation technologyof theJVM, ratherthantheunderlying hardware performance. Fromthis gurewe seethat PCplatforms typicallyout-perform highend workstations. To of progressivelynewv ersionsoftheSun JVMonthesame hardwareplatform.

123456

0 20 40
60
80
100
120
Java SciMark performance across computing platforms

Intel PIII

AMD Athlon

Intel Celeron

Sun UltraSPARC 50

SGI MIPS

Alpha EV6

Mflops

Figure 1:Performance ofJa va variesgreatlyacrosscomputingplatforms. Thisdifferenceis mainlydue to differentimplementations oftheJVM,rather thanunderlying hardwarearchitecture. Today,weareseeingJavacodesperformcompetitivelywithoptimizedCandFortran.Figure3 compares three ofthe morecommonlyav ailableJa vaenvironments(IBM,Sun,andMicrosoft)againsttwoofthemost popularoptimizingCcompilersfor theWindows PC:MicrosoftandBorland.Inbothcasesfulloptimization C. Whilethismayseemsurprising,remember thatwe arenotcomparingthe twolanguagesperse, bu trather differentimplementationsof compilersandexecutionenvironments,whichdifferfromvendortovendor.We 2 1234
0 5 10 15 20 25
30
35

1.1.61.1.8

1.2.1 1.3

JVM version

Mflops

Improvement of Java Performance

Figure 2: Evolutionof Java performance on the same computationalplatform: a 333 MHz Sun Ultra 10.

shouldalsopointoutthat for other platforms, the resultsare notas good. For example, a similar comparison

on a Sun UltraSPARC 1 , shows that Java is only 60% the speed of compiled C. Nevertheless, it is safe to

say in thiscase thatJava performance is certainly competitivewithC. One common rule of thumb isthat for

thesetypesof numeric codes, Javacurrentlyrunsat about50%of theperformance of conventionalcompiled languages. 12345
0 10 20 30
40
50
60
70
80

C (Borland 5.5)C (MS VC++ 5.0)Java (Sun 1.2)

Java (MS 1.1.4)

Java (IBM 1.1.8)

Mflops

SciMark performance on 500 MHz Intel PIII

Figure 3: Surprisingly, Java outperforms some of the most common optimizing C compilers on Windows platforms. These results are on a 500 MHz Intel Pentium III, running Windows 98. Results for other platforms are not as good, but nevertheless Java can remain competitive with C and Fortran. The technologyto applyadvanced compiler optimizations,includingautomaticlooptransformationand parallelization,hasalreadybeendemonstratedinaresearchenvironment. Table1illustratestheperformance

achieved by the Ninjacompiler from IBM T. J. Watson [6] in a set of eight Java numerical benchmarks. For

each benchmark, the table shows absolute performance achieved on a 200 MHz POWER3 machine, that

performance as a percentage of the equivalent Fortran code in the same machine, and the speedup obtained

through automatic parallelization on four processors. For many of the benchmarks the performance of Java

1

SunUltraSPARC60, 360MHz, runningSunOS 5.7,usingcc(WorkshopCompilers5.0), with SunSolarisVM (JDK 1.1.2.05a,

native threads, sunwjit). 3 Table1: Asummary ofJa va performancewith theNinjacompiler. benchmark Mops % ofFortran speedup on

4 processors

MATMUL

340
84%
3.84

MICRODC

210
102%
3.05 LU 154
93%
2.27

CHOLESKY

167
97%
1.44 BSOM 175
81%
2.04

SHALLOW

156
83%
2.40

TOMCATV

75
40%
1.16 FFT 104
54%
2.40 is betterthan 80%of theperformance ofequi valent Fortran code,and inmostofthemareasonablespeedup is achievedbythecompiler .

2.2 Ther oleoflanguagespeciÞcations

Not allthe performanceimpro vements duringthelastfewyears areattrib utedto enhancementsin JVMand JIT technology.In somecases,theJa va languagespecication itselfwas detrimentaltoperformance,and the specicationwas changed.More specically, Ja va1.2onwards allowsforoating-pointcomputations to beperformed withe xtendede xponentrange,whichis moreefcienton x86class processors(e.g., the Pentium). Theresult isthat Jav aclass lesutilizingoating-pointcansometimesproduce slightlydif ferent resultsonthex86thanonthePowerPCortheSPARC, forexample.Javaprogrammerswho stillrequirestrict reproducibilitycanuse thene wk eywordstrictfpon methodsand classesto enforceit, bu tperformance degradationmay result. In anotherrecent dev elopment,Java1.3no wallowsvendorsto usedif ferentimplementationofelemen- tary functions( i.e.,sin,cos,exp, andother functionsin java.lang.Math), aslong asthe ydeli ver resultsthatdifferbyatmost onebit inthe lastplacefromthe correctlyroundedexactresult.Reproducibility of resultscan beenforced throughthe useof methodsin thene wjava.lang.StrictMathclass. This class denesa specicimplementation ofthe elementaryfunctions thatguarantees thesame resulton all platforms.

2.3 Arewe thereyet?

Problems withJa vaperformancestillremain,and they willha ve tobe tackledintheway they havebeen tackled before:with acombinationoflanguage specicationchangesandne wJVM andcompilertechnolo-

gies. Itis stillpossible towrite Jav acode thatis orderofmagnitudesslowerthan equiv alentF ortrancode.

Because JITsoperate atruntime, they ha vealimited timebudgetandcannotperformextensi ve analysisand transformations ofthe scaledone bycurrent staticcompilers. Therepresentation ofelementary numerical values(such ascomple xnumbers) asfull-edgedobjectse xerts ahea vytoll onperformance. Thesechal- lenges toJa vaperformance,andsomeproposed solutions,will bediscussed below in moredetail. Fo rn ow , it isimportant torealize thatthe currentperformance ofJa va canbe very competitiv einsomecases. WhileJavaisnotyet asef cientasoptimizedF ortranor C,thespeedof Jav aisbetterthanitsreputation

suggests. Carefullywritten Jav acodecanperformquitewell [2,4]. (Seesidebar ondoí sand dontís for

numerical computinginJav a.)Javacompilerand JITtechnologyisstillinits infancy ,and likelyto continue 4

toimprove signicantlyin thenear future. Takenwiththe otheradvantagesof Java, there isa real possibility

for Java to become the best ever environment for numerical applications.

3 Numerical Libraries inJava

An important consideration in selecting a programming environment is the availability of tools to make

the job of developing applications easier. Libraries are a particularly important example of programming

tools. For one thing, standardized libraries serve as an extension of the programming language. They

provide powerful application-specic primitives that tailor the language to a particular area and facilitate

code development. Standardized libraries also dene a notation for expressing domain-specic operations

thatare commonlyunderstoodbythepractitionersintheeld. Finally,thecomponentsofalibraryconstitute a specic group of operations that can be highly optimized, both by expert programmers and by smart compilers. The straightforward mechanism to provide Java with libraries for numerical computing is through the

Java Native Interface (JNI). With JNI, Java programs can access native code libraries for the platform on

whichthey execute. Thisapproach makes availablein Java a large bodyof tested and optimizedlibrariesfor

numerical computing. It has been used, in particular, to provide Java with access to MPI and LAPACK [7].

The disadvantagesof usingnative librarieswith Java lie inve areas: safety, robustness,reproducibility,

portability, and performance. First of all, native code cannot typically be executed in an environment as

controlled as Java, and therefore it is not as safe to the host computer. Second, native code does not include

all the run-time validityand consistencychecks of Java bytecode and, therefore, is less robust. Third, native

code, even for a standard library, is likely to have small differences from platform to platform, which may

result in different outcomes in each one. Fourth, native code is not portable across machine architectures

and operating systems. Finally, there is the performance issue. Invoking a native method from Java incurs

on run-time overhead. If the granularity of the operation is large, then the cost of the invocation can be

amortized. However, for simple operations the cost of going through JNI can completely dominate the execution time. Because of all the problems associated with the use of native method from Java, it makes sense to

pursue the development of numerical libraries written directly in Java. One of the rst such libraries was

the Java Numerical Library (JNL), which has been freely distributed by Visual Numerics since 1997. It

provides basic facilities in linear algebra, special functions, and elementary statistics. In 1998, another

proposal for a standardized linear algebra library called JAMA was developed by MathWorks and NIST.

This library includes facilities for solving linear systems and least squares problems, computing standard

matrix decompositions(LU, Cholesky, QR, SVD, eigenvalue), and for computingquantitiessuch as norms,

determinants, ranks, and inverses. OpsResearch.com has developed a substantial set of Java classes to aid

in the development of science and engineering applications, with an emphasis on operations research. A

fairly comprehensive listing of available class libraries for numerical computing can be found on the Java

Numerics Web page (http://math.nist.gov/javanumerics).

Developmentof numerical libraries in Java present a particularchallenge: the preservation of consistent

results across multiple versions and multiple implementations of the same version. In many cases, the

precise behavior of a library is dened by a reference implementation. Because of the precise oating-point

and exception semantics of Java, this reduces the freedom of implementers. Any other implementation

is forced to throw the same exceptions and produce the same results as the reference implementation. If

the reference implementation uses an algorithm that produces suboptimal results, it becomes impossible

to improve on it. That was the case with the originalMathclass in Java. One could not replace it by

an implementation that produced more accurate results for the elementary functions, since they would be

different than those produced by the reference implementation. 5 We wanttoemphasizethatoptimizedlibrariesare an importantperformance tool,buttheydonotconsti-

tute a panacea for performance problems. Programming with librarieshas itslimitations,as discussedinthe

sidebar. Because of the intrinsic limitations of programming with libraries, one needs language and com-

piler support. Compilers need to optimize code constructed with language elements, potentially extended

with standard library constructs.

4 Remaining DifÞculties for Numerical Computing withJava

Despite the very impressive progress in Java performance during the last few years, some challenges still

remain. We identifythree major remainingdifcultiesfornumerical computingwithJava: (i) overrestrictive

(iii) no direct support for true multidimensionalarrays. We discuss each of these difcultiesin detail.

4.1 Java ßoating-pointsemantics

Despite some relaxations in Java 1.2 and 1.3, reproducibility of oating-point results is still a feature very

central to Java. As a consequence, Java currently forbids common optimizations, such as making use of

the associativity property of mathematical operators, which does not hold in a strict sense in oating-point

arithmetic: (a+b)+cmayproduceadifferentroundedresultthana+(b+c). Fortrancompilers,inparticular,

routinelymake use of the associativeproperty of real numbers to optimizecode. Java also forbidsthe use of

fusedmultiply-add(FMA) operations. Thisoperationcomputesthequantity ax+yasa singleoating-point

operation. Operations of this type are found in many compute-intensive applications, particularly in matrix

operations. With thisinstruction,onlya singleroundingoccurs for the twoarithmetic operations, yieldinga

more accurate result in less time than would be required for two separate operations. Java's strict language

denition does not permit use of FMAs and thus sacrices up to 50% of performance on some platforms. InordertomakeJavausablebyprogrammersthatrequirethefastestperformance possible,itisnecessary

to further relax the above restrictions in Java. This can be accomplished by introducing afastmode for

execution of oating-point operations in Java. This mode would only be used in those classes and methods

explicitly marked with afastfpmodier. In this fast mode, FMAs and numerical properties such as

associativity could be used by an optimizing compiler. We note that the default mode would continue to

lead to more reproducible results (as today) and that the fast mode can only be enabled by the programmer

by explicitlyidentifyingclasses and methods where it can be used.

4.2 Complex numbers and alternativearithmetic systems

Another indicator of the ability of a programming language to support serious scientic and engineering

computing is the ease and efciency in which computation with complex numbers can be done. Many

applications,suchas thosein electromagnetic and acousticmodeling, for example, are bestaccomplished in

the complex domain. Complex is just one example of an important alternate arithmetic. Others of growing

importance are interval arithmetic and multiprecision arithmetic. A good scientic computing language

wouldhave the exibilityto incorporatenew arithmetics likethese in a way that is bothefcient and natural

to use. In Java, complex numbers can only be realized in the form of aComplexclass whose objects contain, forexample, twodoublevalues. AskeletonofsuchclassisshowninFigure 4. Complex-valuedarithmetic

must then be expressed by means of complicated method calls, as in the following code fragment, which

computes z=ax+y, wherex=5+2iandy=23i.

Complex x = new Complex(5,2);

6

Complex y = new Complex(2,-3);

Complex z = a.times(x).plus(y);

This has several disadvantages. First, such arithmetic expressions are quite difcult to read, code, and

maintain. In addition, although conceptually equivalent to real numbers implemented with primitive types

(e.g.double),Complexobjects behave differently. For example, the semantics of assignment (=) and

equals (==) operators are different for objects. Finally, complex arithmetic is slower than Java's arithmetic

on primitive types, since it takes longer to create and manipulate objects. Objects also incur more storage

overhead than primitive types. In addition, temporary objects must be created for almost every method call.

Since every arithmetic operation is a method call, this leads to a glut of temporary objects which must be

frequently dealt with by the garbage collector. In contrast, Java primitive types are directly allocated on the

stack, leading to very efcient manipulation. Another disadvantage is that class-based complex numbers do

notseamlesslyblendwithprimitivetypesand theirrelationships. For example, an assignmentofadouble-

value to aComplex-object will not cause an automatic type cast - although such a cast would be expected

for a genuine primitive typecomplex. public final class Complex { private double re; private double im; public Complex(double r, double i) { re = r; im = i; public Complex plus(Complex x) { return new Complex(this.re+x.re, this.im+x.im); public Complex times(Complex x) { double r = this.re*x.re - this.im*x.im; double i = this.re*x.im + this.im*x.re; return new Complex(r,i); Figure 4: Skeleton of aComplexclass for complex numbers. A general solutionto these problems wouldbe afforded by the introductionof two additionalfeatures toquotesdbs_dbs16.pdfusesText_22