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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:28:13+00:00 2026-06-15T22:28:13+00:00

I have a value on local array (named lvotes) for each of the processors

  • 0

I have a value on local array (named lvotes) for each of the processors (assume 3 processors), and first element of each is storing a value, i.e.:

P0 : 4
P1 : 6
p2 : 7

Now, using MPI_Gather, I want gather them all in P0, so It will look like :

P0 : 4, 6, 7

I used gather this way:

MPI_Gather(lvotes, P, MPI_INT, lvotes, 1, MPI_INT, 0, MPI_COMM_WORLD);

But I get problems. It’s my first time coding in MPI. I could use any suggestion.
Thanks

  • 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-15T22:28:14+00:00Added an answer on June 15, 2026 at 10:28 pm

    This is a common issue with people using the gather/scatter collectives for the first time; in both the send and receive counts you specify the count of items to send to or receive from each process. So although it’s true that you’ll be, in total, getting (say) P items, if P is the number of processors, that’s not what you specify to the gather operation; you specify you are sending a count of 1, and receiving a count of 1 (from each process). Like so:

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <mpi.h>
    
    int main ( int argc, char **argv ) {
    
        int rank;
        int size;
    
        int lvotes;
        int *gvotes;
    
        MPI_Init ( &argc, &argv );
        MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
        MPI_Comm_size ( MPI_COMM_WORLD, &size );
    
        if (rank == 0)
            gvotes = malloc(size * sizeof(int) );
    
        /* everyone sets their first lvotes element */
        lvotes = rank+4;
    
        /* Gather to process 0 */
        MPI_Gather(&lvotes, 1, MPI_INT, /* send 1 int from lvotes.. */
                    gvotes, 1, MPI_INT, /* gather 1 int each process into lvotes */
                   0, MPI_COMM_WORLD); /* ... to root process 0 */
    
    
        printf("P%d: %d\n", rank, lvotes);
        if (rank == 0) {
            printf("P%d: Gathered ", rank);
            for (int i=0; i<size; i++)
                printf("%d ", gvotes[i]);
            printf("\n");
        }
    
        if (rank == 0)
            free(gvotes);
    
        MPI_Finalize();
    
        return 0;
    }
    

    Running gives

    $ mpirun -np 3 ./gather
    P1: 5
    P2: 6
    P0: 4
    P0: Gathered 4 5 6 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the value of the epoch time like say 123456789, now I want
I have a funny thing going on with my local dev setup. Using codeigniter
I have an autocomplete field using local JSON data. $( #tags ).autocomplete({ source: get_items,
how can i put my looped value to an array if i have this
i have value in php variable like that $var='2.500000550'; echo $var what i want
I have a question, I have value as below which I set in an
I have a value of Android accelerometer x axis, and on every 0.18 change
I have a value int called score and i want to save this to
I have a value like the following Mon Jun 18 00:00:00 IST 2012 and
I have a value that increases by 1 every 5 views. The MySQL table

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.