3

So, I have a couple of questions about scala.

1) Would writing a new project in scala be speedier (in terms of performance) or should I just stick to regular java? The project that I am going to inherit is already written in java, but it can be massively parallelized. Also, this project is for academic purposes, so I'm a little worried that it's not such a good idea. I know I'd have to run it by my supervisor first, but it's just a thought.

2) Just to be sure, I can compile my scala code on my computer and execute the "binaries" (compiled byte code) on a cluster that has the JVM installed?

3) If I were to compile the inherited java program, should it work? And should it be faster?

(The cluster uses SGE)

2
  • 1
    How well do you know Scala or Java? If you're in a time crunch this could be critical. If not, I'd hands-down go for Scala. You may not realize the benefit at first, but you will eventually. The win is huge. Commented Apr 11, 2011 at 1:09
  • to me the showstopper was that I couldn't easily call Scala code from Java. You should read the Artima article where they interview the Twitter guys about Scala: basically everytime perfs were needed they had to fall back to Java, particularly so for multi-threaded thinggies. (thankfully calling Java from Scala is a breeze, but the inverse is the biggest pain ever). Commented Apr 11, 2011 at 9:24

2 Answers 2

6
  1. This depends entirely on how much work you want to put into parallelizing your code (and how parallelizable the algorithms are). Scala makes it easier, but it does just run on the JVM, and Java can employ every threading trick known to the compiler. So if you want to put the effort into the Java, it will be at least as fast as Scala. (Then again, if you write your Scala like Java, there are very few instances where Java will be faster, so basically it's a tie.)

  2. Yes, as long as you supply the scala-library.jar file (and any others that are needed e.g. if you use Swing, which would be a strange thing to do on a massively parallelized system).

  3. Compiling java bytecode almost never is faster than running the bytecode on the JVM. The JVM is more clever than most static compilers.

  4. You didn't ask, but Scala doesn't have built-in support for the Sun Grid Engine. You could potentially set up something with remote actors, for example, but you'd have significant work to do there.

Sign up to request clarification or add additional context in comments.

5 Comments

So, the algorithm is just a monte carlo method. for 3) i meant for executing the code, would it be considerably faster? But i guess maybe not. 4) So is there a better language or framework that would be more beneficial for me, in terms of exploiting the SGE?
@thejinkx0r - Monte Carlo without dependence is "embarrassingly parallel" in that you can just start N different programs each working on 1/Nth of the possible variations. Then it doesn't matter what language you use--just have the SGE submit the different runs of your program to the cluster. At the other extreme, sequential Monte Carlo is typically communications-bound. There, you don't want to use a cluster at all (sometimes not even threads!)--just use the largest shared-memory-architecture machine you can get your hands on (unless you've got something with an amazing interconnect).
@thejinkx0r - If you didn't mean you were going to use something like gcj to produce a machine binary instead of JVM bytecode, then I have no idea what you mean by (3). If you did mean that, see my answer to (3).
I just reread your point number 3. I misinterpreted what you said. Anyways, I didn't realize that they were called, but it's actually an evolutionary algorithm that uses a Monte Carlo method to generate the population of inputs. So there's going to be a need to communicate between the different inputs to determine if they are fit enough.
@thejinx0r - Is the runtime dominated by the creation of new individuals, or by fitness testing? Can you test fitness in an absolute sense, or must it be competitive? If you can create and score individuals on separate machines and then simply send the numeric answers back for a final tally of who is best, you probably want to use a bunch of remote actors (unless generation & scoring are so slow that you can just use a bunch of programs writing to text files).
3

1) No, you won't get superior performance. Your speed as a programmer will be superior, once you get over the learning curve, but this doesn't seem to be your question.

It might be easier to parallelize by using Scala actors & futures or upcoming 2.9's parallel collections. Also, if the code is heavy on generics but has frequent use of boxed primitives, then Scala's specialization feature is much easier than doing the equivalent by hand in Java.

On the other hand, there's Akka actors and futures that are arguably superior and can be used fine from Java, and Java's own parallel stuff isn't bad.

2) Yes.

3) Err, what?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.