C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Should I use C++ or Java for Numeric Intensive Calculations

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Arindam Chakraborty
Guest





PostPosted: Wed Aug 11, 2004 10:48 am    Post subject: Should I use C++ or Java for Numeric Intensive Calculations Reply with quote



Hi,
My apoligies for posting the age-old question of C++ vs. Java.
I am a FORTRAN programmer and I my work mainly involve numeric
computation.
I am new to both C++ and Java and I will like to know how do these two
languages perform when it comes to numeric computation.

Some of the topics that I am interested in (but not limited to):
[1]. Availability of Math Lib and other canned math routines.
[2]. Implementation of OpenMP and MPI (both MPI-1 and MPI-2)
[3]. Portability issues: Is C++ codes are more portable that Java or
vise-versa?
[4]. Speed of floating point calculations (Saxpy and Daxpy).
[5]. Memory management
[6]. Availability of debugger support (gui and non-gui)
[7]. Handling of unformatted files and endianness (big endian and
little endian)
[8]. 64-bit compilation
[9]. Is one language more strongly typed than other?
[10]. Very important: Ability to call existing fortran routine and
vise-versa.

This list is not exhaustive by any means; please free feel to add any
detail that you feel is an important difference between the two
languages.

I have also heard a couple of *rumors* which I have listed below:
(Please ignore them if they don't make sense)

[A]. Pointers are implemented very differently in the two languages. I
am not sure what are the differences or how it effects execution.
[B]. The OOP concept is implemented differently in the two languages
and so potential bugs show up as compilation errors in one of the
languages.


I am hoping to learn from your experiences,
Thanks in advance.
--Ari

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Hendrik Belitz
Guest





PostPosted: Wed Aug 11, 2004 7:42 pm    Post subject: Re: Should I use C++ or Java for Numeric Intensive Calculati Reply with quote



Arindam Chakraborty wrote:

Quote:
[1]. Availability of Math Lib and other canned math routines.
Tons of stuff has been published. Some things even compete with FORTRAN with

regards to computation speed.

Quote:
[2]. Implementation of OpenMP and MPI (both MPI-1 and MPI-2)
Both C++ and Java could use the C interfaces of MPI


Quote:
[3]. Portability issues: Is C++ codes are more portable that Java or
vise-versa?

If you stick to standard C++, you can use C++ in nearly any environment.
Java, through it's virtual machine, can also be used everywhere. By using
non-standard libraries, both languages could get very "inportable".

Quote:
[4]. Speed of floating point calculations (Saxpy and Daxpy).

These are primarly determined by your hardware environment and the efficieny
of the used compilers (C++) and virtual machines (Java). So this
vendor-specific and not easy to answer.

Quote:
[5]. Memory management

Java uses an garbage collection strategy. Implementing optimized containers
with special memory layouts may get very complicated or even impossible in
Java. C++ may be better suited for such optimizations.

Quote:
[6]. Availability of debugger support (gui and non-gui)

Available for both languages from different vendors.

Quote:
[7]. Handling of unformatted files and endianness (big endian and
little endian)

That depends on your implementation. A language has nothing to say on that.
System functions to access files exist for both languages.

Quote:
[8]. 64-bit compilation

Is available at least for C++. This may not make sense for Java if not
compiled to native code.

Quote:
[9]. Is one language more strongly typed than other?

Both are strong typed languages. Weak typing can be emulated in C++ via
dynamic casts, but this is quite slow.

Quote:
[10]. Very important: Ability to call existing fortran routine and
vise-versa.

In C++ calling fortran routines is quite easy. For Java I dunno. Calling
C++/java routines from Fortran
1) IMHO won't make any sense
2) May get very complicated
But feel free to call C routines from Fortran which should not cause any
problems.

Quote:
This list is not exhaustive by any means; please free feel to add any
detail that you feel is an important difference between the two
languages.

Both lamguages are (as oppossed to common meaning) very different. Java is
much easier to learn, but not capable of many "nice" things C++ has: These
are mainly
- Class and function templates
- Operator overloading
- Superbe support for user-defined data types

Both languages could be learned in a few weeks. Learning all the tricks to
write stable and fast software takes years, as in any language. Since C++
has many pitfalls, it may be easier to learn Java. But writing really
efficient Java code is also a quite demanding task.

I personally prefer C++ for numerics and I'm doing well with efficient C++
data structures and calls to Fortran BLAS routines when needed.

Quote:
I have also heard a couple of *rumors* which I have listed below:
(Please ignore them if they don't make sense)

[A]. Pointers are implemented very differently in the two languages. I
am not sure what are the differences or how it effects execution.

Java encapsulates pointers so the programmer won't see them. It only uses
references. In C++ references and pointers could be used. Since pointers
are essentially the same as in C, this may lead to problems if you don't
know what you're exactly doing.

Quote:
[B]. The OOP concept is implemented differently in the two languages
and so potential bugs show up as compilation errors in one of the
languages.

Nope. C++ uses multiple inheritance, which Java doesn't provide. But in most
cases you won't need that (Java provides an interface definition for this).
I don't see what this has to do with compilation errors. OOP is a generic
design concept, both implementation can handle that. Bugs surely throw
compilation errors. Potential bugs would throw warnings. This is a must for
compiler to generate meaningful code.

--
To get my real email adress, remove the two onkas
--
Hendrik Belitz
- Abort, Retry, Fthagn? -


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Kevin Saff
Guest





PostPosted: Fri Aug 13, 2004 1:41 pm    Post subject: Re: Should I use C++ or Java for Numeric Intensive Calculati Reply with quote



"Arindam Chakraborty" <arimail77 (AT) yahoo (DOT) com> wrote

Quote:
Hi,
My apoligies for posting the age-old question of C++ vs. Java.
I am a FORTRAN programmer and I my work mainly involve numeric
computation.
I am new to both C++ and Java and I will like to know how do these two
languages perform when it comes to numeric computation.

May I ask, what's wrong with Fortran? Many people, especially engineers,
still like it for numeric calculation. If you can explain the things you
don't like about Fortran, that might help others advise you on a language.

Also, if you are mostly doing calculation, I recommend you look into
Mathematica and Matlab. These are both languages designed for
number-crunching, with some rather powerful functionality. Mathematica even
allows formatting code to look more like mathematics. Matlab has a simple
syntax especially suited to linear algebra and engineering applications.
Both of these will probably have every mathematical function you will ever
need, and may even replace most of your old fortran calculation code with
strong builtin routines. If you need integration or fourier transforms,
then a math language might be just the thing for you.

I'm sure others (and the many websites) will be able to answer your
questions about the differences between C++ and Java. I would say that they
are similar languages, with similar strengths but different annoyances. I
don't think one language has especially more or worse annoyances than the
other.

I assume there is some reason you are no longer satisfied with Fortran. To
better offer advice, I have some questions for you:

1) Do you need to provide software to customers? If not, then a math
language would probably be a better choice, and there's nothing really wrong
with Fortran. If so, then Java offers some extra flexibility here since
many browsers support running Java programs - and while Java GUI libraries
may not be great, C++ GUI libraries tend to be worse.

2) Do you need the program to run on an embedded (limited resource)
environment? If so, I think C/C++ offers distinct advantages.

3) Is this skill meant to pad your resume? If so, Java currently buzzes in
more managers' ears. It's possible a language like Python or Ruby will be
the next "big thing" if you're looking a bit further down the road.

4) Do you just want to learn a new language? Great! Then it doesn't matter
which you choose.

If you do decide to learn Java or C++, I strongly recommend that you also
study some basic computer science topics like data structures if you haven't
already. I think this would help you use C++/Java for better
object-oriented programming. If you don't know much CS, you may be better
off using C++ as just a better C, or in your case, a better Fortran.

HTH
--
+---- Kevin C. Saff ----+ F-15 | |Eagle
Quote:
Engineer, Boeing, StL | _____|_^_|_____
Tracking/Fleet Support| * + [_(x)_] + *




[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Keith H Duggar
Guest





PostPosted: Fri Aug 13, 2004 1:45 pm    Post subject: Re: Should I use C++ or Java for Numeric Intensive Calculati Reply with quote

Quote:
This list is not exhaustive by any means; please free feel to add any
detail that you feel is an important difference between the two
languages.

My primary numerical simulation and analysis work is in C++. I have
ported about 5% of that work to Java.

For my part, the most significant difference between the two languages
has been operator overloading and templates both of which C++ has and
neither of which Java has. Combined they allow you to write highly
concise and readable numerical code. Perhaps more importantly, they
allow you to use the same generic algorithm for a variety of numerical
types. As a simple example consider the following forward Euler
integration routine

template <
class Variable , // here class means "any type"
class Derivative , // classes, functions, scalars,
class Time > // etc, and it temporarily gives
// names to these types
Variable forward_euler_step (

Variable x ,
Derivative d ,
Time t ) {

return x + t*d(x) ;

}

After defining such a generic routine you can perform an Euler
integration step on ANY types that can satisfy the equation x +
t*d(x). For example, d can be a regular function or a class that
supplies a function call operator () (these are called functors), x
can be a simple type like a double or it could be a vector where d is
a vector function, t could be a constant or a vector, etc, etc. Thus,
you have written a single Euler step routine that can be used for any
reasonable types.

Of course, this is a simple example and you could easily write Euler
steps over and over again. However, as routines grow in complexity the
power of templates and overloading saves on time, efficiency, and
errors. For example, I have dozens of routines for such things as
integration, optimization, and root finding written as templates that
I use on a great variety of "numerical" types (scalars, vectors,
function spaces, etc).

If you do decide to use C++ there is an excellent book with an
excellent intro chapter specifically for Fortran programmers (there is
also one for C programmers). The book is called "Scientific and
Engineering C++ : An Introduction with Advanced Techniques and
Examples" by John J. Barton, Lee R. Nackman. I highly recommend this
book. In fact, I recommend you read the preface and section 1.2 to
help answer some of your questions about whether to chose C++.

Unless you need to produce numerical toys that users can run on the
web, chose C++, you won't be disappointed.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Walter
Guest





PostPosted: Tue Aug 17, 2004 9:57 am    Post subject: Re: Should I use C++ or Java for Numeric Intensive Calculati Reply with quote


"Arindam Chakraborty" <arimail77 (AT) yahoo (DOT) com> wrote

Quote:
Hi,
My apoligies for posting the age-old question of C++ vs. Java.
I am a FORTRAN programmer and I my work mainly involve numeric
computation.
I am new to both C++ and Java and I will like to know how do these two
languages perform when it comes to numeric computation.

Some C++ compilers (certainly not all) support 80 bit long doubles, or even
longer. Such extra precision can make or break many calculations, especially
things like matrix inversion, numerical integration, and finite elements.
Insufficient precision can result in totally bogus answers with no obvious
indication that they've gone awry.

Java does not offer floating point precision beyond 64 bits.

-Walter
www.digitalmars.com free C/C++/D compilers


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
nospam@nowhere.com
Guest





PostPosted: Thu Aug 19, 2004 11:59 am    Post subject: Re: Should I use C++ or Java for Numeric Intensive Calculati Reply with quote

Walter <walter (AT) digitalmars (DOT) nospamm.com> wrote:
Quote:
Java does not offer floating point precision beyond 64 bits.

Java's BigDecimal class offers arbitrary-precision signed decimal
numbers.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Walter
Guest





PostPosted: Fri Aug 20, 2004 1:36 am    Post subject: Re: Should I use C++ or Java for Numeric Intensive Calculati Reply with quote


<nospam (AT) nowhere (DOT) com> wrote

Quote:
Walter <walter (AT) digitalmars (DOT) nospamm.com> wrote:
Java does not offer floating point precision beyond 64 bits.

Java's BigDecimal class offers arbitrary-precision signed decimal
numbers.

Is that decimal or floating point?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Fri Aug 20, 2004 2:37 pm    Post subject: Re: Should I use C++ or Java for Numeric Intensive Calculati Reply with quote

"Walter" <walter (AT) digitalmars (DOT) nospamm.com> wrote

Quote:
nospam (AT) nowhere (DOT) com> wrote in message
news:4123a2a9$0$8086$a1866201 (AT) newsreader (DOT) visi.com...
Walter <walter (AT) digitalmars (DOT) nospamm.com> wrote:
Java does not offer floating point precision beyond 64 bits.

Java's BigDecimal class offers arbitrary-precision signed decimal
numbers.

Is that decimal or floating point?

Aren't the two aspects orthogonal?

(In fact, if memory serves me right, BigDecimal does arbitrary precision
fixed point arithmetic, and not floating point, i.e.: the results of 0.1
* 0.1 is 0.0, and there is a subtle difference between 0 and 0.0.)

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.