Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:03:37+00:00 2026-06-03T06:03:37+00:00

I have been looking into scala and AKKA for managing an obviously parallelisable algorithm.

  • 0

I have been looking into scala and AKKA for managing an obviously parallelisable algorithm.
I have some knowledge of functional programming and mostly do Java, so my FP might not be the best yet.

The algorithm I am working with is pretty simple, there is a top computation:

  def computeFull(...): FullObject

This computation calls sub computations and then sum it up (to simplify):

  def computePartial(...): Int

and computeFull does something like this (again simplifying):

 val partials = for(x <- 1 to 10
     y <- 1 to 10) yield computePartial(x, y)
 partials.foldLeft(0)(_ + _)

So, it’s very close to the AKKA example, doing the PI computation. I have many computeFull to call and many computePartial within each of them. So I can wrap all of this in AKKA actors, or to simplify in Futures, calling each computeFull and each computePartial in separate threads. I then can use the fold, zip and map functions of http://doc.akka.io/docs/akka/snapshot/scala/futures.html to combile the futures.

However, this implies that computeFull and computePartial will have to return Futures wrapping the actual results. They thus become dependent on AKKA and assuming that things are run in parallel. In fact, I also have to implicitly pass down the execution contexts within my functions.

I think that this is weird and that the algorithm “shouldn’t” know the details of how it is parallelised, or if it is.

After reading about Futures in scala (and not the AKKA one) and looking into Code Continuation. It seems like the Responder monad that is provided by scala (http://www.scala-lang.org/api/current/scala/Responder.html) seems like the right way to abstract how the function calls are run.
I have this vague intuition that computeFull and computePartial could return Responders instead of futures and that when the monad in executed, it decides how the code embedded within the Responder gets executed (if it spawns a new actor or if it is executed on the same thread).

However, I am not really sure how to get to this result. Any suggestions? Do you think I am on the right way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:03:39+00:00Added an answer on June 3, 2026 at 6:03 am

    If you don’t want to be dependent on Akka (but note that Akka-style futures will be moved and included with Scala 2.10) and your computation is a simple fold on a collection you can simply use Scala’s parallel collections:

    val partials = for { x <- (1 to 10).par
      y <- 1 to 10
    } yield computePartial(x, y)
    // blocks until everything is computed
    partials.foldLeft(0)(_ + _)
    

    Of course, this will block until partials is ready, so it may not be a appropriate situation when you really need futures.

    With Scala 2.10 style futures you can make that completely asynchronous without your algorithms ever noticing it:

    def computePartial(x: Int, y: Int) = {
      Thread.sleep((1000 * math.random).toInt)
      println (x + ", " + y)
      x * y
    }
    
    import scala.concurrent.future
    import scala.concurrent.Future
    val partials: IndexedSeq[Future[Int]] = for {
      x <- 1 to 10
      y <- 1 to 10
    } yield future(computePartial(x, y))
    
    val futureResult: Future[Int] = Future.sequence(partials).map(_.fold(0)(_ + _))
    
    def useResult(result: Int) = println(s"The sum is $result")
    
    // now I want to use the result of my computation
    futureResult map { result => // called when ready
      useResult(result)
    }
    // still no blocking
    println("This is probably printed before the sum is calculated.")
    

    So, computePartial does not need to know anything about how it is being executed. (It should not have any side-effects though, even though for the purpose of this example, a println side-effect was included.)

    A possible computeFull method should manage the algorithm and as such know about Futures or parallelism. After all this is part of the algorithm.

    (As for the Responder: Scala’s old futures use it so I don’t know where this is going. – And isn’t an execution context exactly the means of configuration you are looking for?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking into the php fputcsv function, and have heard some comments
I have been looking into game development recently and my first programming language is
I have been looking into some options for creating a slide out bar for
I have been looking into this for some hours now and can't figure it
I have been looking into refactoring some old code into a new WCF service,
I have been looking into some existing code of the company I am with
I am using Rails 3.0.9. (With ruby 1.9.3) I have been looking into some
I have been looking into benchmarking lately, I have always been interested in logging
I have been looking into IKVMing Apache's FOP project to use with our .NET
I have been looking into the Castle project and specifically Windsor. I have been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.