Hi, I've got a bit of a problem. I wanted to use scala.concurrent.ops.replicate to parallelize my program. But I found out, that the algorithm actually becomes much slower. So I wrote a little test and still got the same result. So here they are.
Serial Code: Takes about 63 seconds to finish
object SerTest {
def main(args: Array[String]) {
for(x <- 1 to 10){
for(i <- 1 to 4) {
for(j <- 1 to 100000) {
val a = BigInt(j).isProbablePrime(1000)
if(!a && j == 100000) println(i + " is ready")}}}}}
Concurrent Code: Takes about 161 seconds to finish
object ParTest {
def main(args: Array[String]) {
for(x <- 1 to 10){
replicate(1,5) { i =>
for(j <- 1 to 100000) {
val a = BigInt(j).isProbablePrime(1000)
if(!a && j == 100000) println(i + " is ready")}}}}}
So where is the completely obvious and embarrassing error I made? :)
Edit: Ohh, and I am running this on a Quadcore-CPU. So it should actually be faster :)
Edit2: Because of the answer of Kevin Wright I changed the programs slightly to have a longer time to run.