Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing functional programs in non-functional languages

Suppose I write a program using immutable data structures in Java. Even though it is not a functional language, it should be able to execute parallely. How do I ensure that my program is being executed using all the cores of my processer? How does the computer decide which code can be run parallely?

P.S. My intent in asking this question was not to find out how to parrallelize java programs. But to know - how does the computer parallelize code. Can it do it in a functional program written in a non functional language?

like image 235
Pranav Avatar asked May 11 '09 09:05

Pranav


2 Answers

Java programs are parallelized through threads. The computer can't magically figure out how to distribute the pieces of your application across all the cores in an imperative language like Java. Only a functional language like Erlang or Haskell could do that. Read up on Java threads.

like image 146
Sasha Chedygov Avatar answered Oct 12 '22 13:10

Sasha Chedygov


I am not aware of automatic parallelization JVMs. They do exist for other languages such as FORTRAN.

You might find the JSR166y fork-join framework scheduled for JDK7 interesting.

like image 22
Tom Hawtin - tackline Avatar answered Oct 12 '22 13:10

Tom Hawtin - tackline