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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:58:22+00:00 2026-06-13T13:58:22+00:00

I developed this simple function to perform the sum of n number in parallel

  • 0

I developed this simple function to perform the sum of n number in parallel environment with mpi, using the strategy in which each processor calculates its partial sum and then at pairwise distinct the processor communicate between them the amounts calculated , creating a binary tree. Of course, this strategy can be applied if the numbers of processor is multiple of 2^n.

Parameters: menum = id processor, nproc = total numbers of processor , sum = partial sum

  void Second_Strategy( int menum ,int nproc,int sum, MPI_Status status)
  {
    int a,b,p,i,sumtmp;
    double t_tot, t1, t2, diff;

    p=log(nproc)/log(2);
    t1 = MPI_Wtime();

    for(i=1;i<=p;i++)
    {
       b=pow(2,i-1);
       a=pow(2,i);
       if ( (menum % a) ==0) 
       {
          MPI_Recv(&sumtmp,1,MPI_INT,(menum+b),i,MPI_COMM_WORLD,&status);
          sum=sum+sumtmp;

        }else{
               if ( ( menum % b) ==0){MPI_Send(&sum,1,MPI_INT,(menum-b),i,MPI_COMM_WORLD); }

            }
      }
        t2 = MPI_Wtime();
        diff = t2-t1;
        MPI_Reduce(&diff, &t_tot, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);

        if(menum==0) 
        {

          printf("The sum is : %d \n ",sum);
          printf("Time  : %f seconds\n", t_tot);

        }      

 }

In this case the process P0 will the result of the sum. But in the case in which the user is to select the processor that will have the sum introducing a parameter “choice”. How to do? I have problem with the creation of the binary tree for the exchange of data between processes.

  • 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-13T13:58:23+00:00Added an answer on June 13, 2026 at 1:58 pm

    The most straightforward solution would be to create a new communicator in which the process chosen by the user receives rank 0. Then simply use that communicator instead of MPI_COMM_WORLD in your tree-building algorithm.

    I am assuming of course that you’re doing this for an exercise in parallel communications rather than the purpose of summing numbers, since obtaining a sum can be easily done with MPI_Reduce().

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

Sidebar

Related Questions

I have developed a simple library in Ruby and need to use this in
I developed one simple app, like subtraction, addition. In this app I use three
CSS3 allows developers to implement simple graphics without using images. For example this envelope
I'm trying to develop a simple kernel using TASM, using this code: ; beroset.asm
This should be simple, but I am having problems. Using the eBay .Net library,
I just developed a very simple ActiveX control(using the VS.NET wizard, not even change
I´m using an different box for title atrib in elements. I´ve developed a simple
I am using jQuery UI (1.8.16) extensively in my application. I've developed a simple
I've developed a simple website using facebook connect, and it has been working fine
I developed a simple javascript injection which works very well. Can anybody tell me

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.