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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:44:59+00:00 2026-05-26T14:44:59+00:00

I had a problem with a program that uses MPI and I have just

  • 0

I had a problem with a program that uses MPI and I have just fixed it, however, I don’t seem to understand what was wrong in the first place. I’m quite green with programming relates stuff, so please be forgiving.

The program is:

#include <iostream>
#include <cstdlib>
#include <mpi.h>

#define RNumber     3

using namespace std;

int main() {
    /*Initiliaze MPI*/
    int     my_rank;    //My process rank
    int         comm_sz;    //Number of processes
    MPI_Comm    GathComm;   //Communicator for MPI_Gather
    MPI_Init(NULL, NULL);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);

    /*Initialize an array for results*/
    long rawT[RNumber];
    long * Times = NULL;        //Results from threads
    if (my_rank == 0) Times = (long*) malloc(comm_sz*RNumber*sizeof(long));

    /*Fill rawT with results at threads*/
    for (int i = 0; i < RNumber; i++) {
        rawT[i] = i;
    }


    if (my_rank == 0) {
        /*Main thread recieves data from other threads*/
        MPI_Gather(rawT, RNumber, MPI_LONG, Times, RNumber, MPI_LONG, 0, GathComm);

    }
    else {
        /*Other threads send calculation results to main thread*/
        MPI_Gather(rawT, RNumber, MPI_LONG, Times, RNumber, MPI_LONG, 0, GathComm);
    }

    /*Finalize MPI*/
    MPI_Finalize();
    return 0;
};

On execution the program returns the following message:

Fatal error in PMPI_Gather: Invalid communicator, error stack:
PMPI_Gather(863): MPI_Gather(sbuf=0xbf824b70, scount=3, MPI_LONG,
rbuf=0x98c55d8, rcount=3, MPI_LONG, root=0, comm=0xe61030) failed
PMPI_Gather(757): Invalid communicator Fatal error in PMPI_Gather:
Invalid communicator, error stack: PMPI_Gather(863):
MPI_Gather(sbuf=0xbf938960, scount=3, MPI_LONG, rbuf=(nil), rcount=3,
MPI_LONG, root=0, comm=0xa6e030) failed PMPI_Gather(757): Invalid
communicator

After I remove GathComm altogether and substitute it with MPI_COMM_WORLD default communicator everything works fine.

Could anyone be so kind to explain what was I doing wrong and how did this adjustment made everything work?

  • 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-26T14:44:59+00:00Added an answer on May 26, 2026 at 2:44 pm

    That’s because GathComm has not been assigned a valid communicator. “MPI_Comm GathComm;” only declares the variable to hold a communicator but doesn’t create one.

    You can use the default communicator (MPI_COMM_WORLD) if you simply want to include all procs in the operation.

    Custom communicators are useful when you want to organised your procs in separate groups or when using virtual communication topologies.

    To find out more, check out this article which describes Groups, Communicator and Topologies.

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

Sidebar

Related Questions

I have a program that uses java.util.TimeZone to produce the GMT offsets for various
One of the analytics that I had to have on my program was How
I have a major problem that happened to me. I am writing a program
I had a problem that was partially solved. To explain it quickly : I
Im currently developing a program that uses a scrollable/zoomable image as the main user
Background I have a Spring batch program that reads a file (example file I
I have written a COM object that in turn uses a thrid party ActiveX
I have a program that load data from a file using std::ifstream and store
I have a c# program that access a java program by tcp. In my
I have found other examples of people having this problem but have had no

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.