Git Product home page Git Product logo

cuboids-shearsort-mpi's Introduction

Cuboids-Shearsort-MPI

An implementation of the Shearsort algorithm for parallel sorting an array. This implementation is using another parallel sorting algorithm which is Odd-Even sort.

In this implementation, a bench of cuboids is read from an input file into an array, which contain each cuboid's id, width, height, and depth. The cuboids are being sorted by the volume of each, or by the width if the volume is equals.

Each process gets a cuboid by MPI_Scatter and returns its value in the end of the algorithm with MPI_Gather.

Shearsort Iterations

This algorithm sorting an array of nXn values with nXn processes after iterations, each iteration is complexity, (in this case ) so the final complexity time is .

Initial

The processes are cartesian ordered by MPI_Cart_create.

| 14 |  1 | 13 |  8 |  
|  4 | 11 |  6 |  7 |  
| 12 |  9 | 10 |  5 |  
|  3 |  2 |  0 | 15 |

Even Iterations

In even iteration, each row of the matrix is sorted in ascending order if it is an even row, or in descending order if it is an odd row.

|  1 |  8 | 13 | 14 |    ->
| 11 |  7 |  6 |  4 |    <-
|  5 |  9 | 10 | 12 |    ->
| 15 |  3 |  2 |  0 |    <-

Odd Iterations

In odd iteration, each column of the matrix is sorted in ascending order regardless if it is an even or odd column.

   ^    ^    ^    ^
|  1 |  3 |  2 |  0 |
|  5 |  7 |  6 |  4 |
| 11 |  8 | 10 | 12 |
| 15 |  9 | 13 | 14 |

End of Iterations

At the end of the iterations, the matrix will be as below.

|  0 |  1 |  2 |  3 |
|  7 |  6 |  5 |  4 |
|  8 |  9 | 10 | 11 |
| 15 | 14 | 13 | 12 |

All that left is to collect the values by a snake shape.

|  0 |  1 |  2 |  3 |   >
|  7 |  6 |  5 |  4 |   <
|  8 |  9 | 10 | 11 |   > 
| 15 | 14 | 13 | 12 |   <

Odd-Even Sort Iterations

This algorithm sorting an array of n values with n processes after n iterations. Complexity time .

Initial

The initial array will be as below.

Rank:   |  0 |  1 |  2 |  3 |

Value:  |  3 |  2 |  0 |  1 |     <-  the actual array

Even Iterations

In even iterations, an even-ranked process is communicating with his right odd-ranked neighbor. In ascending order, the even-ranked process will save the smaller value, while the odd-ranked process will save the greater one.

    >-<       >-<
|  3 |  2 |  0 |  1 |

So after the iteration, the array will look like below:

|  2 |  3 |  0 |  1 |

Odd Iterations

In odd iterations, an odd-ranked process will communicate with his right even-ranked process. The odd-ranked process will save the smaller value while the even-ranked process will save the greater one.

         >-<
|  2 |  3 |  0 |  1 |

So after the iteration, the array will look like below:

|  2 |  0 |  3 |  1 |

End of Iterations

At the end of the iterations, the array will be as below.

|  0 |  1 |  2 |  3 |

cuboids-shearsort-mpi's People

Contributors

guykabiri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.