Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an implementation of rapid concurrent syntactical sugar in scala? eg. map-reduce

Passing messages around with actors is great. But I would like to have even easier code.

Examples (Pseudo-code)

val splicedList:List[List[Int]]=biglist.partition(100)
val sum:Int=ActorPool.numberOfActors(5).getAllResults(splicedList,foldLeft(_+_))

where spliceIntoParts turns one big list into 100 small lists the numberofactors part, creates a pool which uses 5 actors and receives new jobs after a job is finished and getallresults uses a method on a list. all this done with messages passing in the background. where maybe getFirstResult, calculates the first result, and stops all other threads (like cracking a password)

like image 427
TiansHUo Avatar asked Dec 17 '22 01:12

TiansHUo


1 Answers

With Scala Parallel collections that will be included in 2.8.1 you will be able to do things like this:

val spliced = myList.par // obtain a parallel version of your collection (all operations are parallel)
spliced.map(process _)   // maps each entry into a corresponding entry using `process`
spliced.find(check _)    // searches the collection until it finds an element for which
                         // `check` returns true, at which point the search stops, and the element is returned

and the code will automatically be done in parallel. Other methods found in the regular collections library are being parallelized as well.

Currently, 2.8.RC2 is very close (this or next week), and 2.8 final will come in a few weeks after, I guess. You will be able to try parallel collections if you use 2.8.1 nightlies.

like image 51
axel22 Avatar answered May 16 '23 04:05

axel22