- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a Java code for some numerical simulation (currently most effort seems to be in a sparse linear solver), and am considering whether recoding it in fortran (which may take me a couple of weeks or more, as the Java was written by a colleague) will yield a worthwhile speed up in execution time. The code will be used extensively over the next year or longer, and each run takes 2-8hrs depending on inputs, etc. I realise speed-ups will be highly case-specific (and will depend on the library routine implementing the linear solver), but nevertheless would be interested in hearing anybody's experiences with how Java code compares to Fortran. In particular, from what I understand, Java is not compiled but rather runs as 'virtual machine', and its object-oriented features can be slow.
thanks in advance!
thanks in advance!
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The claim that java code is interpreted is false. Java uses a just in time compiler which compiles the code once you run your program.
I have written a few applets in java solving pde's and the speed was fast. However java always does runtime bounds checking for arrays. Accessing those is significantly slower compared to C/C++. (According to my experience there is no difference in execution speed between fortran and C/C++)
For instance I was unable to use precomputed sine tables in java because the table lookup took more time than the sine calculation. Fortran does not have such an overhead at runtime so it should be significantly faster. If you have just a standalone program with no GUI and this is likely to remain so you may be able to significantly increase the performance but due to fortrans lack of useable object oriented features you will have to put significant effort in porting your app.
I have written a few applets in java solving pde's and the speed was fast. However java always does runtime bounds checking for arrays. Accessing those is significantly slower compared to C/C++. (According to my experience there is no difference in execution speed between fortran and C/C++)
For instance I was unable to use precomputed sine tables in java because the table lookup took more time than the sine calculation. Fortran does not have such an overhead at runtime so it should be significantly faster. If you have just a standalone program with no GUI and this is likely to remain so you may be able to significantly increase the performance but due to fortrans lack of useable object oriented features you will have to put significant effort in porting your app.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As an addition:
You should have a look at the following site which feature benchmarks for a variety of problems calculated on almost any available language:
http://shootout.alioth.debian.org/great/index.php?sort=fullcpu
You should have a look at the following site which feature benchmarks for a variety of problems calculated on almost any available language:
http://shootout.alioth.debian.org/great/index.php?sort=fullcpu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have never used java, but Intel Fortran compilerhas quite some options for optimizations, including once that will help to reduce run-time.
And any way, you can always write a small benchmark, that represents the type of calculations you are using most. That may give you the closest answer to your question with regard to your specific needs.
Message Edited by dima333a on 04-03-2005 08:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
My experience is thatusing a newcompiler almost never gives youany significant speedup if you are not willing to adapt the implementation somewhat to the technology that comes with the new compilers.
However, if you are able to rewrite your code in a way that reduces the number of cache misses and also enablesintra-register vectorization and takes advantage of efficient out of order execution, a very significant speedup can be seen.
Recentlywe have recently seen that porting an application to Intel Fortran initially reduced the run time efficiency with 20%, but with some minor source code modifications (in about 50 linesin a project with500 000 lines), the resulting speedup was 250%.
So when going from Java to Fortran, switching language and compiler may give you a large speedup, but you probably cannot boost the efficiency of your application without adapting the code to the advanced technology that is being included in the new Intel Fortran compiler.
The resulting speedup is of course dependent of thearchitecture of your program and some problems are not very suitable for software optimization, so it is always dangerous to do accurate predictions in these matters.
Best regards,
Lars Petter Endresen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks for all the helpful advices! some details that will be relevant - the main effort is in a sparse linear solver, which is called repeatedly (100's if not 1000's of times, with ~10,000 unknowns, possibly more in the future) within a "time-stepping"-type outer loop.
Currently the solver algorithm comes from some java library, and I would probably be looking at replacing it with a call to a netlib (or maybe IMSL or CXML) Fortran routine. Given what has been said about array bound checking this might suggest that a move to an efficient Fortran routine might be rather beneficial, right?
thanks in advance!
Currently the solver algorithm comes from some java library, and I would probably be looking at replacing it with a call to a netlib (or maybe IMSL or CXML) Fortran routine. Given what has been said about array bound checking this might suggest that a move to an efficient Fortran routine might be rather beneficial, right?
thanks in advance!
Message Edited by forall on 04-06-2005 12:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
In some situations a good algorithm is much more important than a good implementation, and I am not an expert in sparse matrix solvers, but I remember that selecting the suitable algorithm is particularly important if the matrix is sparse. When a suitable algorithm has been found, and the algorithm do not contain too many branches (if-tests), it may be possible to vectorize the solver, that is, enable simultaneous calculations on packed floating point numbers, like for example the SSE2 instruction "divps" that does 4 single precision division simultaneously. Note that the elements in the matrix should be traversed in the order they are stored in memory in the inner loops (for example A(i,j) may in a particular need to be replaced with A(j,i)), otherwise you will probably get many cache misses and the code will not vectorize. You can either compile and vectorize the solver yourself using Intel Visual Fortran, or check if Intel (or others) already has an implementation or library that is suitable.
Best regards,
Lars Petter Endresen

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page