progs/sudoku.scala
changeset 449 d67c5f7177a6
parent 384 6e1237691307
child 450 61eb4f9b8d84
equal deleted inserted replaced
448:db2a3e3287a9 449:d67c5f7177a6
   187        ".....2.......7...17..3...9.8..7......2.89.6...13..6....9..5.824.....891..........",
   187        ".....2.......7...17..3...9.8..7......2.89.6...13..6....9..5.824.....891..........",
   188        "3...8.......7....51..............36...2..4....7...........6.13..452...........8..",
   188        "3...8.......7....51..............36...2..4....7...........6.13..452...........8..",
   189        "....14....3....2...7..........9...3.6.1.............8.2.....1.4....5.6.....7.8...",
   189        "....14....3....2...7..........9...3.6.1.............8.2.....1.4....5.6.....7.8...",
   190        "4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......")
   190        "4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......")
   191 
   191 
   192 //println("108:\n" ++ pretty(hard_games(108).replaceAll("\\.", " ")) ++ "\n")
       
   193 //println("109:\n" ++ pretty(hard_games(109).replaceAll("\\.", " ")) ++ "\n")
       
   194 
   192 
   195 
   193 
   196 // for measuring time
   194 // for measuring time
   197 def time_needed[T](i: Int, code: => T) = {
   195 def time_needed[T](i: Int, code: => T) = {
   198   val start = System.nanoTime()
   196   val start = System.nanoTime()
   201   (end - start) / i / 1.0e9
   199   (end - start) / i / 1.0e9
   202 }
   200 }
   203 
   201 
   204 
   202 
   205 val total = 
   203 val total = 
   206   (for ((game, i) <- hard_games.zipWithIndex) yield {
   204   (for ((game, i) <- hard_games.zipWithIndex.par) yield {
   207     val secs = time_needed(1, search(game))
   205     val secs = time_needed(1, search(game))
   208     println(f"${i}%2.0f: ${game} |${secs}%2.3f secs")
   206     println(f"${i}%2.0f: ${game} |${secs}%2.3f secs")
   209     secs
   207     secs
   210   }).sum
   208   }).sum
   211 
   209 
   214 }
   212 }
   215 
   213 
   216 
   214 
   217 
   215 
   218 // 1 single thread version 800 secs
   216 // 1 single thread version 800 secs
       
   217 //
   219 // 4 cores parallel version on a moderate laptop 400 secs
   218 // 4 cores parallel version on a moderate laptop 400 secs
   220 // 8 cores: 290 secs
   219 // 8 cores: 290 secs
       
   220 // 10 cores: 156 secs
   221 // 18 cores: 142 secs
   221 // 18 cores: 142 secs
   222 
   222