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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:16:07+00:00 2026-05-26T09:16:07+00:00

I am trying to implement Tournament barrier using MPI. Here, is the code I

  • 0

I am trying to implement Tournament barrier using MPI. Here, is the code I have written. I am writing only the arrival phase and wake up phase

//Arrival phase
while(1)
{
    if((!strcmp(round[my_id][round_num].role,"winner"))||(!strcmp(round[my_id][round_num].role,"champion")))
    {
       printf("%d is the winner of round %d\n",my_id,round_num);
       MPI_Recv(&reach_msg, sizeof(reach_msg), MPI_BYTE, round[my_id][round_num].opponent, tag, MPI_COMM_WORLD, &status);
       printf("%d received: %s\n",my_id,reach_msg);
    }

    else if(!strcmp(round[my_id][round_num].role,"loser"))
    {
       printf("%d is the loser of round %d\n",my_id,round_num);
       sprintf(reach_msg,"%d arrived at the barrier",my_id);
       MPI_Send(reach_msg,strlen(reach_msg+1),MPI_BYTE,round[my_id][round_num].opponent,tag,MPI_COMM_WORLD);
       MPI_Recv(wakeup_msg,sizeof(wakeup_msg),MPI_BYTE,round[my_id][round_num].opponent,tag,MPI_COMM_WORLD,&status);
       printf("%d received: %s\n",my_id,wakeup_msg);
    }

if(round_num==num_rounds)
       break;
    else
       round_num++;
}

printf("%d is out of arrival tree\n",my_id);

//wakeup tree
      while(1)
     {
       printf("%d prints: round num is: %d\n",my_id,round_num);
       if(round_num==0)
            break;
       sprintf(wakeup_msg,"wakeup msg from %d of %d",my_id,P);

       if((!strcmp(round[my_id][round_num].role,"winner"))||(!strcmp(round[my_id][round_num].role,"champion")))
       MPI_Send(wakeup_msg,strlen(wakeup_msg+1),MPI_BYTE,round[my_id][round_num].opponent,tag,MPI_COMM_WORLD);
       round_num--;
      }

    MPI_Finalize();
    return 0;
   }

I dont understand why race conditions occur. I believe the MPI_Send and MPI_Recv are blocking functions. But, sometimes it doesn’t behave that way

EDIT: Here is a sample output where race condition happens. As you can see, 0 received message(“1 arrived at the barrier”) from 1 even before 1 sent the message.

0 is the winner of round 1

0 received: 1 arrived at the barrie

0 is the winner of round 2

1 is the loser of round 1

1 sending reach msg

2 is the winner of round 1

2 received: 3 arrived at the barrie

2 is the loser of round 2

2 sending reach msg

3 is the loser of round 1

3 sending reach msg

0 received: 2 arrived at the barrie

0 sending wakeup msg

0 sending wakeup msg

1 received: wakeup msg from 0 with tag at round 1

2 received: wakeup msg from 0 with tag at round 2

2 sending wakeup msg

3 received: wakeup msg from 2 with tag at round 1

  • 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-26T09:16:08+00:00Added an answer on May 26, 2026 at 9:16 am

    For debugging mpi programs, print statements are generally not a very good solution. As the print statments need to be send to the console from different nodes over the network and are cached before.

    To debug it you should let each processor write to an own output file. Or let only one processor print statements, where you disable caching by either using std::cerr or somehow disable the caching of printf.

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

Sidebar

Related Questions

I am trying implement the Data transformation using Reflection 1 example in my code.
Im trying to implement pagination using multiple searching criteria. Supposed I Have student table.
trying to implement a dialog-box style behaviour using a separate div section with all
I'm trying implement a bracket in my program (using C#/.NET MVC) and I am
Trying to implement the excellent jQuery bidirectional infite scroll as explained here: http://www.bennadel.com/blog/1803-Creating-A-Bidirectional-Infinite-Scroll-Page-With-jQuery-And-ColdFusion.htm For
im trying to implement simple secured client server communiction using WCF. when im launching
SetFocus I'm trying implement the above Se Focus code in a Class Library that
Trying to implement what I thought was a simple concept. I have a user
Trying to implement this gallery on my website. http://coffeescripter.com/code/ad-gallery/ It is noted in the
iam trying to implement an Searchmachine into my site. Iam using Zend_Search_Lucene for this.

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.