试图找到专注多线程的Scala教程。

时间:2021-01-05 20:44:34

Scala appears to have a ton of features and improvements over Java. I am having a hard time isolating the stuff I want to learn first about Scala. What should I look for on Google if I just want to, for example, take for loops and make them run over multiple threads or processes? I am coming from a GPU computing background where it was really simple to get a high-level view of how make things run faster.

Scala似乎比Java有很多特性和改进。我很难把我想首先学到的Scala知识隔离开来。如果我只是想,例如,取for循环,让它们在多个线程或进程上运行,那么我应该在谷歌上寻找什么呢?我来自一个GPU计算的背景,在这个背景下,对于如何让事情运行得更快,从高层次的角度来看是很简单的。

1 个解决方案

#1


21  

  • Scala's parallel collections are particularly easy. Parallelizing an expensive operation f(i) over integers i <- 1 to 10 is as simple as,

    Scala的并行集合特别容易。将一个代价高昂的操作f(i)对整数i <- 1到10进行并行处理非常简单,

    (1 to 10).par.map(i => f(i))
    

    Scala will try to allocate a number of work threads that is comparable to the number of cores/processors available in your system. Here's a video with more details: http://days2010.scala-lang.org/node/138/140

    Scala将尝试分配一些与系统中可用的内核/处理器数量相当的工作线程。这里有一段视频详细介绍:http://days2010.scala-lang.org/node/138/140

  • The Akka framework is a mature, primarily actor based approach to concurrency that allows parallelizing over threads or remote processes. Actors are basically threads that can pass messages rather than share state. The newly formed company Typesafe is developing both the Scala language and Akka.

    Akka框架是一种成熟的、主要基于参与者的并发方法,允许在线程或远程进程上进行并行处理。actor基本上是可以传递消息而不是共享状态的线程。新成立的Typesafe公司正在开发Scala语言和Akka。

  • You can also try a draft release of a software transactional memory (STM) library for Scala. The library is aiming for inclusion in the standard Scala distribution. Compared to manually managed threads, STM is a simpler model of concurrency that reduces the possibility of errors such as dead-locks. It works by grouping sequences of communication operations into a single synchronized block that can fail and roll back if multiple threads do something with shared state that turns out to be mutually incompatible. Presumably there is some performance cost to pay for convenience; I'm not sure how well STM scales to large numbers of threads.

    您还可以尝试Scala软件事务内存(STM)库的草案版本。该库旨在将其包含在标准Scala发行版中。与手动管理的线程相比,STM是一种更简单的并发模型,它减少了出现错误(如死锁)的可能性。它通过将通信操作的序列分组到单个同步块中来工作,如果多个线程以共享状态做某些事情,而这些共享状态实际上是相互不兼容的,那么该块可能会失败并回滚。为了方便起见,可能会有一些性能成本;我不确定STM在大量的线程中扩展得有多好。

  • The Spark framework addresses cluster computing, and seems to be a generalization of MapReduce.

    Spark框架解决了集群计算,似乎是MapReduce的一般化。

  • For GPU programming from Scala, there's ScalaCL. You can also use the Java bindings.

    对于Scala的GPU编程,有ScalaCL。您还可以使用Java绑定。

  • There's also the very interesting language virtualization work being done as a joint effort between the labs at Stanford and EPFL. This page has links to papers, and there is a course at Stanford with many more links. There are several exciting applications for developing DSL's for high performance computing over heterogenous computing environments, including GPUs.

    还有一种非常有趣的语言虚拟化工作是由斯坦福大学和EPFL实验室共同完成的。这一页与论文有联系,在斯坦福有一门课程有更多的链接。有几个令人兴奋的应用程序可以在异构计算环境(包括gpu)上开发用于高性能计算的DSL。

Update. Daniel Sobral also suggested the Tools and Libraries wiki.

更新。丹尼尔·索夫拉尔也推荐了工具和图书馆维基。

#1


21  

  • Scala's parallel collections are particularly easy. Parallelizing an expensive operation f(i) over integers i <- 1 to 10 is as simple as,

    Scala的并行集合特别容易。将一个代价高昂的操作f(i)对整数i <- 1到10进行并行处理非常简单,

    (1 to 10).par.map(i => f(i))
    

    Scala will try to allocate a number of work threads that is comparable to the number of cores/processors available in your system. Here's a video with more details: http://days2010.scala-lang.org/node/138/140

    Scala将尝试分配一些与系统中可用的内核/处理器数量相当的工作线程。这里有一段视频详细介绍:http://days2010.scala-lang.org/node/138/140

  • The Akka framework is a mature, primarily actor based approach to concurrency that allows parallelizing over threads or remote processes. Actors are basically threads that can pass messages rather than share state. The newly formed company Typesafe is developing both the Scala language and Akka.

    Akka框架是一种成熟的、主要基于参与者的并发方法,允许在线程或远程进程上进行并行处理。actor基本上是可以传递消息而不是共享状态的线程。新成立的Typesafe公司正在开发Scala语言和Akka。

  • You can also try a draft release of a software transactional memory (STM) library for Scala. The library is aiming for inclusion in the standard Scala distribution. Compared to manually managed threads, STM is a simpler model of concurrency that reduces the possibility of errors such as dead-locks. It works by grouping sequences of communication operations into a single synchronized block that can fail and roll back if multiple threads do something with shared state that turns out to be mutually incompatible. Presumably there is some performance cost to pay for convenience; I'm not sure how well STM scales to large numbers of threads.

    您还可以尝试Scala软件事务内存(STM)库的草案版本。该库旨在将其包含在标准Scala发行版中。与手动管理的线程相比,STM是一种更简单的并发模型,它减少了出现错误(如死锁)的可能性。它通过将通信操作的序列分组到单个同步块中来工作,如果多个线程以共享状态做某些事情,而这些共享状态实际上是相互不兼容的,那么该块可能会失败并回滚。为了方便起见,可能会有一些性能成本;我不确定STM在大量的线程中扩展得有多好。

  • The Spark framework addresses cluster computing, and seems to be a generalization of MapReduce.

    Spark框架解决了集群计算,似乎是MapReduce的一般化。

  • For GPU programming from Scala, there's ScalaCL. You can also use the Java bindings.

    对于Scala的GPU编程,有ScalaCL。您还可以使用Java绑定。

  • There's also the very interesting language virtualization work being done as a joint effort between the labs at Stanford and EPFL. This page has links to papers, and there is a course at Stanford with many more links. There are several exciting applications for developing DSL's for high performance computing over heterogenous computing environments, including GPUs.

    还有一种非常有趣的语言虚拟化工作是由斯坦福大学和EPFL实验室共同完成的。这一页与论文有联系,在斯坦福有一门课程有更多的链接。有几个令人兴奋的应用程序可以在异构计算环境(包括gpu)上开发用于高性能计算的DSL。

Update. Daniel Sobral also suggested the Tools and Libraries wiki.

更新。丹尼尔·索夫拉尔也推荐了工具和图书馆维基。