
Signature
Knute Johnson
email s/nospam/knute/
Thanks for that. I think that is good as far as to multi threading.
How about single threading? For example, if my program has a thread
that do a lot of computations, and these computations do not affect
each other. Say, the thread is scanning through a list of records, and
do some computation within each record.
One way is of course to use many threads to do this. But if I just put
them in one loop in one thread, will JVM and its compiler be "smart"
enough to realize it and use multi CPUs to do them in parallel?
The reason I am asking is that, as I remembered years back on my
compiler course in school, they said good compilers can know certain
codes can be paralleled, and the complier will tune the code
automatically. Is that available in today's common compliers (and
languages) such as in java?
Hum, my question may be some what off the topic for a Java group
though.
:-)
Chris Uppal - 03 Feb 2006 09:59 GMT
> The reason I am asking is that, as I remembered years back on my
> compiler course in school, they said good compilers can know certain
> codes can be paralleled, and the complier will tune the code
> automatically. Is that available in today's common compliers (and
> languages) such as in java?
Not Java.
There are some special-purpose compilers for languages like Fortran than /can/
do that kind of thing, but they still need plenty of help from the programmer
to do it /well/.
There are languages designed from the ground up to parallelise too.
-- chris
Roedy Green - 03 Feb 2006 11:30 GMT
>One way is of course to use many threads to do this. But if I just put
>them in one loop in one thread, will JVM and its compiler be "smart"
>enough to realize it and use multi CPUs to do them in parallel?
no. There is a fair overhead to creating a thread and starting it up.
You can't do it just for tiny bits of code. Further as soon as you
introduce threads you introduce terrible uncertainty as they meddle
with each other's variables. It requires a much higher level of skill.
It is still far from being automatic.
You want your threads to have ZERO interaction ideally.
See http://mindprod.com/jgloss/queue.html
for stereotyped ways of interacting that have been coded by the gods.
Rolling you own interactions is very difficult to get 100%. Getting it
90% is easy.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Nigel Wade - 03 Feb 2006 11:56 GMT
> Thanks for that. I think that is good as far as to multi threading.
>
[quoted text clipped - 6 lines]
> them in one loop in one thread, will JVM and its compiler be "smart"
> enough to realize it and use multi CPUs to do them in parallel?
No.
> The reason I am asking is that, as I remembered years back on my
> compiler course in school, they said good compilers can know certain
> codes can be paralleled, and the complier will tune the code
> automatically. Is that available in today's common compliers (and
> languages) such as in java?
Normally, only in very expensive parallelising compliers. Even then there are
only some very specific types of code which can be automatically parallelised,
it normally requires specific parallel constructs to be used in the code (my
only knowledge of parallelising compilers is for FORTRAN, it may be different
for other languages). It's also quite easy to write code which takes longer to
execute on multiple processors than it does on one...

Signature
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
Oliver Wong - 03 Feb 2006 17:05 GMT
> How about single threading? For example, if my program has a thread
> that do a lot of computations, and these computations do not affect
[quoted text clipped - 14 lines]
> though.
> :-)
A lot of people have been saying "No, there's no such thing." I also
acknowledge that what you're asking for is difficult enough that I would be
"surprised" to discover a compiler which can automatically insert threading
when appropriate, but I don't presume to know of all the latest and greatest
in compiler advancements.
You might want to redirect your question to comp.compilers.
- Oliver
Dimitri Maziuk - 03 Feb 2006 17:27 GMT
Kevin sez:
> Thanks for that. I think that is good as far as to multi threading.
>
> How about single threading? For example, if my program has a thread
> that do a lot of computations, and these computations do not affect
> each other. Say, the thread is scanning through a list of records, and
> do some computation within each record.
There 2 kinds of parallel: single-instruction-multiple-data and
multiple-instructions-multiple-data, they require different kinds
of hardware. What you're talking about is SIMD (same computation
on different records) and unless you happen to have a MasPar in
your basement, you're SOL. These things come with specialized
languages (or at least specialized C dialects) and specialized
programming techiniques (e.g. "wavefront").
Your regular SMP machines and multi-core CPUs are MIMD, designed
for multiple threads/processes, not for SIMD tasks. You could
potentially do SIMD on them if you could bypass everything
including on-chip instruction pipeline & parallelizer and get
direct access to chip's cores. Definitely not in Java, for
obvious reasons.
> One way is of course to use many threads to do this. But if I just put
> them in one loop in one thread, will JVM and its compiler be "smart"
> enough to realize it and use multi CPUs to do them in parallel?
Nope.
> The reason I am asking is that, as I remembered years back on my
> compiler course in school, they said good compilers can know certain
> codes can be paralleled, and the complier will tune the code
> automatically. Is that available in today's common compliers (and
> languages) such as in java?
IIRC Ada has "parbegin ... parend" blocks, allowing the programmer
to mark code segments for parallel execution. They may become common
if IBM's new playstation chip takes off (PPC "dispatcher" core + a
bunch of SIMD "processing" cores). Then come parallelizing compilers...
Dima

Signature
The most horrifying thing about Unix is that, no matter how many times you hit
yourself over the head with it, you never quite manage to lose consciousness.
It just goes on and on. -- Patrick Sobalvarro
Roedy Green - 03 Feb 2006 23:39 GMT
> if you could bypass everything
>including on-chip instruction pipeline & parallelizer and get
>direct access to chip's cores. Definitely not in Java, for
>obvious reasons.
most chips nowadays come with one or more specialised auxiliary
processors, DSPs which are a sort of miniature array processor. These
are primarily intended for video or audio processing. You might see
Java using them, but only a in a native method. The most common place
you see them used are in CODECs.
see http://mindprod.com/jgloss/dsp.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.