Writing functional programs in non-functional languages

Suppose I write a program using immutable data structures in Java. Although this is not a functional language, it should be able to run in parallel. How to ensure that my program runs using all the cores of my processing? How can a computer decide which code can be run in parallel?

PS My intention to ask this question was not to learn how to parrallelize java programs. But to know how the computer parallelizes the code. Can this be done in a functional program written in a non-functional language?

+4
source share
5 answers

I don’t think that you can β€œforce” the JVM to parallelize your program, but having a separate thread executing each β€œtask”, if you can break your program this way, it will probably be a trick in most cases? parallelism is still not guaranteed.

+3
source

Java programs are parallelized across threads. A computer cannot magically figure out how to distribute parts of your application across all cores in an imperative language such as Java. Only a functional language such as Erlang or Haskell could do this. Read on Java threads.

+8
source

I do not know automatic parallelization of the JVM. They exist for other languages ​​such as FORTRAN.

You can find the JSR166y fork-join framework planned for JDK7.

+5
source

You can write functions with automatic parallel tasks, they are quite easy to do for specific cases, however, I do not know any built-in Java API that does this. (Except, possibly, the Contractor / Contractor)

+1
source

Something I used at school that did a lot for you.

http://www.cs.rit.edu/~ark/pj.shtml

It has the ability to do SMP or parallelism based messages.

Regardless of whether another question is useful to you :-)

0
source

All Articles