[scala] scalablitz

scala 2017. 7. 27. 19:49

coursera의 scala 강의 중에 scalablitz의 흔적(monoid 설명)이 있어서 함 찾아봤다.



scala 2.9(2011년)부터 parallel 패키지가 추가되었다. 


그러나 3rd party로 scalablitz(http://scala-blitz.github.io/)로 있긴 했지만, 2014년 쯔음부터는 더 이상 운영되지 못했다. 이제는 역사속으로 사진 라이브러리이지만... 


Parallel Collections were originally introduced into Scala in release 2.9. Why another data-parallel collections framework? While they provided programmers with seamless data-parallelism and an easy way to parallelize their computations, they had several downsides. First, the generic library-based approach in Scala Parallel Collections had some abstraction overheads that made them unsuitable for certain types of computations involving number crunching or linear algebra. To make efficient use of parallelism, overheads like boxing or use of iterators have to be eliminated. Second, pure task-based preemptive scheduling used in Scala Parallel Collections does not handle certain kinds of irregular data-parallel operations well. The data-parallel operations in this framework are provided for a wide range of collections, and they greatly reduce both of these overheads.




libraryDependencies += "com.github.scala-blitz" %% "scala-blitz" % "1.1"



스칼라의 병렬 콜렉션은 scala.collection.par 패키지를 이용할 수 있다. 스칼라 병렬 콜렉션처럼 일반 콜렉션에서 toPar 메소드를 호출하면 병렬 객체를 리턴한다. 


import scala.collection.par._
import scala.collection.par.Scheduler.Implicits.global

def mean(a: Array[Int]): Int = {
val sum = a.toPar.reduce(_ + _)
sum / a.length
}

val m = mean(Array(1, 3, 5))
print(m)

결과 값은 3이다.



이후에 예제 코딩을 진행하면 기존 스칼라 코드와 충돌이 나면서 테스트를 계속하기 애매해진다.


Error:(25, 5) reference to text is ambiguous;

it is both defined in method totalLength and imported subsequently by 

import scala._




slideshare에서 scalablitz 맛을 보는데 도움이 되는 것 같다. generic 관련해서 깔끔해진 느낌이 있긴 하다.. 

(가뜩이나 스칼라는 공부할수록 복잡해지는 느낌이 있긴 하다.......)


ScalaBlitz from Aleksandar Prokopec



더 궁금하면 아래 링크를 참조한다.


http://apprize.info/programming/scala/7.html


Posted by '김용환'
,