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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:53:13+00:00 2026-05-26T11:53:13+00:00

I am trying write a program, where the process 0 should start the initialization

  • 0

I am trying write a program, where the process 0 should start the initialization of sending messages to a random process other than itself, then the random process selected should receive the message and send to another random process.

This should happen until the requested number of messages to be sent is done, which is given by the user as input.

I see that my program is either sending messages at the max 2, or else, even none, and giving me the following error:

ONE OF THE PROCESSES TERMINATED BADLY: CLEANING UP
APPLICATION TERMINATED WITH THE EXIT STRING: Terminated (signal 15)

The random generation part is not included, which is working fine:

if(rank==0)
{
    rnum=rgenerator(rank,size);
    string++;
    MPI_Send(&string, 50, MPI_INT, rnum, rnum, MPI_COMM_WORLD);
    printf("\n process %d sends message to process %d",rank, rnum);
    
    //MPI_Recv(&flag, 100, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
    
}
    
while(flag!=1)
{
    if(MPI_Recv(&string, 50, MPI_INT, MPI_ANY_SOURCE, rank, MPI_COMM_WORLD, &status)==MPI_SUCCESS)
    {   
        printf("\n process %d receives message from process %d count : %d",rank, status.MPI_SOURCE, string);
        rnum=rgenerator(rank,size);
        printf("\n Random num generated is %d",rnum);
        string=string+1;
        MPI_Send(&string, 50, MPI_INT, rnum, rnum, MPI_COMM_WORLD);
        count++;
        
        printf("\n process %d sends message to process %d", rank, rnum);

        //MPI_Bcast(&count, 40, MPI_INT, rank, MPI_COMM_WORLD);
        if(string==n)
        {
            printf("\n\n Messages reached");
            flag=1;
        }
    }
    else 
        flag=0;
    }
  • 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-26T11:53:14+00:00Added an answer on May 26, 2026 at 11:53 am

    You should make sure that you have the same number of send and receive operations.

    In your code, you have one send operation more than you have receive operations. Therefore, one process will crash.

    To avoid this, you need to send only if your flag is not equal to 1:

    //MPI_Send(&string, 50, MPI_INT, rnum, rnum, MPI_COMM_WORLD);
    count++;
    
    printf("\n process %d sends message to process %d", rank, rnum);
    
    //MPI_Bcast(&count, 40, MPI_INT, rank, MPI_COMM_WORLD);
    if(string==n)
    {
       printf("\n\n Messages reached");
       flag=1;
    }
    
    if(flag!=1)
    {//make sure that you need to send one message.
        MPI_Send(&string, 50, MPI_INT, rnum, rnum, MPI_COMM_WORLD);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program to process the BSD-style process accounting file under
I'm trying to write a program that uses sockets to connect with other instances
i am trying to write a program that close explorer then runs another program.
I'm trying to write a professional program to accept and process input via a
Two (related?) questions here. I was trying to write a program to start an
I am trying to write a c++ program that creates a child process, runs
I'm trying to write a program in C (on Linux) that loops until the
I'm trying to write a program that reads text from external file (string string
I am trying to write a program that allows a binary to be run,
I'm trying to write a program in Python and I'm told to run an

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.