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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:55:01+00:00 2026-06-16T00:55:01+00:00

I can’t seem to figure out how to send data between nodes instead of

  • 0

I can’t seem to figure out how to send data between nodes instead of sending it to the root node and then sending it to all other nodes.

If I have N nodes each with an array created like so, where SIZE is the total number of nodes, and for the moment assume it’s a preprocessor constant (when possible, avoid malloc like the plague). Also, it goes without saying that rank is the current node’s rank.

int dummy [SIZE][5];
int i, n;

for (n = 0; n < SIZE; n++){
  for (i = 0; i <5; i++){
    if ( n == rank ){
      dummy [ n ][ i ] = 123;

This gives each node a nearly empty array of dimensions SIZE * 5, with only one row of the numbers 123. Now I want to take all these individual arrays and ‘merge’ them. The only thing I can think of is the below, but I am certain this will lead to a deadlock, even if I do bother checking to see if I source node does not equal target node:

for ( i = 0; i < SIZE; i++ ){
  for ( j = 0; j < SIZE; j++ ){
     MPI_Send ( &dummy [ i ], 5, MPI_INT, j, 123, MPI_COMM_WORLD );
  }
}

for ( i = 0; i < SIZE; i++ ){
  for ( j = 0; j < SIZE; j++ ){
     MPI_Recv ( &dummy [ j ], 5, MPI_INT, i, 123, MPI_COMM_WORLD );
  }
}

Can someone kindly provide me with some pseudocode as to how to tackle this problem. Cheers

  • 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-16T00:55:03+00:00Added an answer on June 16, 2026 at 12:55 am

    This is a “gather” operation, and there’s an MPI collective, MPI_Gather(), which implements it if you want to gather all of the data on to one processor, and MPI_Allgather() gathers the data to all processors.

    In this case, we want to do an ‘in-place’ gather – gathering into the same array we’re sending from. So this will work:

    #include <stdio.h>
    #include <stdlib.h>
    #include <mpi.h>
    
    #define SIZE 5
    
    int main(int argc, char **argv) {
    
        int size, rank;
        MPI_Init(&argc, &argv);
        MPI_Comm_size(MPI_COMM_WORLD, &size);
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    
        if (size != SIZE) {
            if (rank == 0) {
                fprintf(stderr,"Must run with %d ranks\n", SIZE);
            }
            MPI_Finalize();
            exit(1);
        }
    
        int dummy [SIZE][5];
    
        for (int i = 0; i <5; i++){
              dummy [ rank ][ i ] = 100 * rank;
        }
    
        MPI_Allgather(MPI_IN_PLACE, 5, MPI_INT,
                      dummy, 5, MPI_INT,
                      MPI_COMM_WORLD);
    
        if (rank == SIZE-1) {
            printf("Rank %d has dummy:\n", rank);
            for (int i=0; i<size; i++) {
                for (int j=0; j<5; j++) {
                    printf("%3d ", dummy[i][j]);
                }
                printf("\n");
            }
        }
    
        MPI_Finalize();
        return 0;
    }
    

    Running gives:

    $ mpicc -o allgather allgather.c -std=c99
    $ mpirun -np 5 ./allgather
    Rank 4 has dummy:
      0   0   0   0   0 
    100 100 100 100 100 
    200 200 200 200 200 
    300 300 300 300 300 
    400 400 400 400 400 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I authenticate with just Google account username and password instead of using OAuth?
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can someone give me a clear, concise definition of the difference between a programming
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can find why i get this error can someone help? package Android.data; public class
Can anyone help me trying to find out why this doesn't work. The brushes
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
can I get the value of a variable declared in a procedure then use
Can anyone let me know how can we change the value of kendo combobox
Can I order my users in the database, so I don't have to say

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.