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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:36:51+00:00 2026-06-01T13:36:51+00:00

I’m trying to write an MPI version of a program that runs an odd/even

  • 0

I’m trying to write an MPI version of a program that runs an odd/even compare-split operation on n randomly generated elements.

Process 0 should generated the elements and send nlocal of them to the other processes, (keeping the first nlocal for itself). From here, process 0 should print out it’s results after running the CompareSplit algorithm. Then, receive the results from the other processes run of the algorithm. Finally, print out the results that it has just received.

I have a large chunk of this already done, but I’m getting a deadlock that I can’t seem to fix. I would greatly appreciate any hints that people could give me.

Here is my code http://pastie.org/3742474

Right now I’m pretty sure that the deadlock is coming from the Send/Recv at lines 134 and 151. I’ve tried changing the Send to use “tag” instead of myrank for the tag parameter..but when I did that I just keep getting a “MPI_ERR_TAG: invalid tag” for some reason.

Obviously I would also run the algorithm within the processors > 0 but I took that part out for now, until I figure out what is going wrong.

Any help is appreciated.

EDIT: I’ve written a smaller test case, that doesn’t contain any CompareSplit operations, but is still deadlocking. http://pastie.org/3744691

I fixed the above test case by changing the tag at line 83 from “myrank” to “tag”.
Well the test case works, but when the actual algorithm is added in like in my program it deadlocks..

So, I think I’ve narrowed the deadlock down to this chunk of code. It looks to be the Sendrecv under the else.

for (i = 1; i <= npes; i++) {
    if (i % 2 == 1) // odd phase
      MPI_Sendrecv(elmnts, nlocal, MPI_INT, oddrank, 1, relmnts,
                           nlocal, MPI_INT, oddrank, 1, MPI_COMM_WORLD, &status);
    else
      MPI_Sendrecv(elmnts, nlocal, MPI_INT, evenrank, 1, relmnts,
                           nlocal, MPI_INT, evenrank, 1, MPI_COMM_WORLD, &status);

    CompareSplit(nlocal, elmnts, relmnts, wspace,
                 myrank < status.MPI_SOURCE);
}
  • 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-01T13:36:52+00:00Added an answer on June 1, 2026 at 1:36 pm

    The tag error was because tags have to be positive integers in the range from 1 to some implementation-dependant maximum which is guaranteed to be at least 32k.

    The deadlock is pretty easy to understand; look at what the non-rank zero processes are doing:

      else {
        // The rest of the processes
        // Receive nlocal randomly generated elements from process 0
        MPI_Recv(elmnts, nlocal, MPI_INT, 0, tag, comm, &status);
    
        qsort(elmnts, nlocal, sizeof(int), IncOrder); // does it matter where we sort at?
    
        // Send results back to process 0
        MPI_Send(elmnts, nlocal, MPI_INT, 0, myrank, comm);
      }
    

    So they’re doing one receive, and one send back. But processor 0 is doing much more than this; it sends everyone their data, then executes a bunch of send-receives to process 1 (evenrank) and MPI_NULL_PROC (oddrank). But the send-receives to evenrank are noops, and the the send-recieves to process 1 will never be answered because process 1 isn’t doing the same thing.

    I think you need to move that part of the algorithm outside of the if (rank == 0) test.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.