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 7052255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:21:42+00:00 2026-05-28T03:21:42+00:00

I thought about splitting up recursion into smaller recursive sizes, then wondered if it

  • 0

I thought about splitting up recursion into smaller recursive sizes, then wondered if it is of any actual practical use, also considering parallelism.

To make clear what I mean, a small example(merge sort):

Instead of doing:

...
merge_sort(b, m);
merge_sort(m, e);
merge(b, m, e);  
...

doing something like this:

...
merge_sort_quad(b, m1);
merge_sort_quad(m1 + 1, m2);
merge_sort_quad(m2 + 1, m3);
merge_sort_quad(m3 + 1, e);
merge_quad(b, m1, m2, m3, e);
...

Cosidering a parallel example, I don’t see a basic difference in both approchaes, as they will probably result in the same:

void foo (..) {
    ...
    //using tbb::prallel_invoke() to call functions in parallel
    tbb::parallel_invoke(foo(..), foo(..)); 
    ...
}

void foo_parallel (..) {
    ...
    tbb::parallel_invoke(foo(..), foo(..), foo(..), foo(..));
    ...
}

I hope you guys can explain me if this is totally useless and bad or if it is algorithm dependent and might be of some practical use. I doubt it, as it looks a bit like manual loop unrolling.

  • 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-05-28T03:21:42+00:00Added an answer on May 28, 2026 at 3:21 am

    You are correct, and indeed this is done with merge-sort. There’s a few different ideas together in your question, and some have further implications, so let’s divide them out. I’ll go over a few things I think you’re quite possibly clearer on than I am, because it’ll make for a more coherent answer for anyone else reading it.

    First recursion. There’s logical recursion where we break a problem down into repeated versions of itself until they reach some point where they are trivial (classically, factorial by multiplying the current number by the factorial of one less until we reach 1), and there’s functional recursion where we model this by having a function call itself.

    Logical recursion is a problem-solving technique for people. Functional recursion is a programming technique that reflects it. However, functional recursion can cost more than the iterative equivalent. Hence we often either have our compilers turn them into the iterative equivalent, have tail-call optimisation which pretty much does that too (by removing most or all of the cost of recursive calls) or when that fails, convert to iterative versions ourselves.

    Now, in the particular sort of recursion we have with a merge-sort we increase the number of simpler tasks as we break the problem down. That is rather than n! becoming the single task of n × (n - 1)!, merge-sort becomes two tasks of merging two halfs of the sequence to merge, followed by the task of merging the results.

    You’ve made the correct jump to concluding that this can lead to a parallel approach. There’s some further features to this that makes it interesting. If we broke it down to 4 merges like you have done, and gave each merge to a different core, then each core will be dealing with memory that will be close together and load into caches together (the way that data being close together can help us) but it’s relatively unlikely that one thread will write to data in the same cache-line that another thread is interested in and force it to suffer from the cache being invalidated (“false sharing” the way that data being close together can hurt us).

    The sort being likely to be bound only on CPU and memory, there probably won’t be much to gain after 1 thread per core or at most 1 thread per virtual processor if hyperthreaded.

    Therefore splitting into separate function calls benefits performance up to the number of virtual processors. The example in your question would be the idea on a four-processor machine. After that, it’s unlikely that one thread would be able to help much by work-stealing from another when it came to an end, so from that point on you’re probably better taking an iterative approach (whether hand-coded as such or turned into such by the compiler). Taking a functionally recursive approach beyond the point where we have a function per processor begins to hurt us again. However, it’s always possible that we mis-calculate how many cores we actually have to use (because other processes are using them too) so it can be worth going a bit further than function-per-core and allowing those that finish first to take the left-overs.

    There’s quite a bit of stuff on paralleling merge-sorts in the literature, and some frameworks and libraries have merge-sort implementations that make use of it.

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

Sidebar

Related Questions

I thought about the following question about computer's architecture. Suppose I do in Python
I thought about migrating subversion a lot and I have several questions still open.
I have never thought about until recently, but I'm not sure why we call
For a new Java web project I thought about using: Eclipse as IDE Mercurial
I was wondering what people thought about the decision to support Entity Framework over
In short, when you have planned or have thought about an idea to create
Before answering, it is not as easy question as you might have thought about
We have some performance problems with one of our applications. I thought about using
i'm trying to get computer's state in my LAN... thought about using QTcpSocket but
I let users embed videos from Youtube, Google, Vimeo etc. I thought about the

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.