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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:22:22+00:00 2026-06-15T06:22:22+00:00

I am attempting to implement the Bitonic-Sort algorithm. Parallel Bitonic Sort Algorithm for processor

  • 0

I am attempting to implement the Bitonic-Sort algorithm.

Parallel Bitonic Sort Algorithm for processor Pk (for k := 0 : : : P  1)
d:= log P /* cube dimension */
sort(local  datak) /* sequential sort */
/* Bitonic Sort follows */
for i:=1 to d do
    window-id = Most Signicant (d-i) bits of Pk
    for j:=(i-1) down to 0 do
        if((window-id is even AND jth bit of Pk = 0) OR 
                   (window-id is odd AND jth bit of Pk = 1))
        then call CompareLow(j)
        else call CompareHigh(j)
        endif
    endfor
endfor

Source: http://www.cs.rutgers.edu/~venugopa/parallel_summer2012/mpi_bitonic.html#expl

Unfortunately the descriptions of CompareHigh and CompareLow are shaky at best.

From my understanding, CompareHigh will take the data from the calling process, and its partner process, merge the two, sorted, and store the upper half in the calling process’ data. CompareLow will do the same, and take the lower half.

I’ve verified that my implementation is selecting the correct partners and calling the correct CompareHigh/Low method during each iteration for each process, but my output is still only partially sorted. I’m assuming that my implementation of CompareHigh/Low is incorrect.

Here is a sample of my current output:

[0] [17 24 30 37]
[1] [ 92 114 147 212]
[2] [ 12  89  92 102]
[3] [172 185 202 248]
[4] [ 30  51 111 148]
[5] [148 149 158 172]
[6] [ 17  24  59 149]
[7] [160 230 247 250]

And here are my CompareHigh, CompareLow, and merge functions:

def CompareHigh(self, j):
    partner = self.getPartner(self.rank, j)
    print "[%d] initiating HIGH with %d" % (self.rank, partner)
    new_data = np.empty(self.data.shape, dtype='i')

    self.comm.Send(self.data, dest = partner, tag=55)
    self.comm.Recv(new_data, source = partner, tag=55)

    assert(self.data.shape == new_data.shape)
    self.data = np.split(self.merge(data, new_data), 2)[1]

def CompareLow(self, j):
    partner = self.getPartner(self.rank, j)
    print "[%d] initiating LOW with %d" % (self.rank, partner)
    new_data = np.empty(self.data.shape, dtype='i')

    self.comm.Recv(new_data, source = partner, tag=55)
    self.comm.Send(self.data, dest = partner, tag=55)

    assert(self.data.shape == new_data.shape)
    self.data = np.split(self.merge(data, new_data), 2)[0]

def merge(self, a, b):
    merged = []
    i = 0
    j = 0
    while i < a.shape[0] and j < b.shape[0]:
        if a[i] < b[j]:
            merged.append(a[i])
            i += 1
        else:
            merged.append(b[j])
            j += 1
    while i < a.shape[0]:
        merged.append(a[i])
        i += 1

    while j < a.shape[0]:
        merged.append(b[j])
        j += 1

    return np.array(merged)


def getPartner(self, rank, j):
    # Partner process is process with j_th bit of rank flipped
    j_mask = 1 << j
    partner = rank ^ j_mask
    return partner

Finally, here the actual algorithm loop:

# Generating map of bit_j for each process.
bit_j = [0 for i in range(d)]
for i in range(d):
    bit_j[i] = (rank >> i) & 1    

bs = BitonicSorter(data)
for i in range(1, d+1):

    window_id = rank >> i
    for j in reversed(range(0, i)):
        if rank == 0: print "[%d] iteration %d, %d" %(rank, i, j) 
        comm.Barrier()
        if (window_id%2 == 0 and bit_j[j] == 0) \
                    or (window_id%2 == 1 and bit_j[j] == 1):
            bs.CompareLow(j)
        else:
            bs.CompareHigh(j)
        if rank == 0: print ""
        comm.Barrier()

if rank != 0:
    comm.Send(bs.data, dest = 0, tag=55)
    comm.Barrier()

else:
    dataset[0] = bs.data
    for i in range(1, size) :
        comm.Recv(dataset[i], source = i, tag=55)
    comm.Barrier()
    for i, datai in enumerate(dataset):
        print "[%d]\t%s" % (i, str(datai))
    dataset = np.array(dataset).reshape(data_size)
  • 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-15T06:22:23+00:00Added an answer on June 15, 2026 at 6:22 am

    Well bugger me:

    self.data = np.split(self.merge(data, new_data), 2)
    

    Were the problematic lines. I’m not sure what variable data was bound to, but that was the problem right there.

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

Sidebar

Related Questions

I am attempting to implement Heap sort in my program to learn more about
Im attempting to implement an RSA encryption algorithm into my iOS app, but when
I'm attempting to implement a curve interesection algorithm known as bezier clipping, which is
I am attempting to implement heap sort using the psuedo code from the book
I'm attempting to implement the Tcl dictionary sort in Perl in order to order
I'm attempting to implement deleting characters in a simple window that utilizes the Curses
I'm attempting to implement BFS in Python, I understand how the algorithm works but
I am attempting to implement a selection sort of an array in NASM that
Attempting to implement a poor man's test of whether a process is still running
I am attempting to implement a form on APEX that allows the user (in

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.