Question: Write a C program using MPI to implement parallel odd - even sort. Use 8 cores ( ntasks and tasks per node should be 8

Write a C program using MPI to implement parallel odd-even sort.
Use 8 cores (ntasks and tasks per node should be 8 in your script), each one will hold 1 value.
Each core will have 2 variables for values. The first (A) should store the value the core currently
has, and the second (B) will be the value that it will receive from the neighboring core at each
phase.
Assign each core a value such that they are unsorted i.e. the values C0, C1, C2, C3, C4, C5, C6,
C7 should be unsorted (where Ci indicates the value core with rank i has). You can do this by
giving each core the value 8- rank for example, or use a random number generator. There are
multiple ways to do this, be as creative as you like.
The algorithm begins proceeds by alternating 2 phases.
Phase 1: Core 0 and Core 1 communicate (use MPI send and receive commands) values and if
C0> C1 then store C1 in core 0 and C0 in core 1 i.e. exchange values, otherwise do nothing.
Then similarly Core 2 and Core 3 communicate values and if C2> C3 then store C3 in core 2 and
C2 in core 3 i.e. exchange values, otherwise do nothing. Then Core 4 and Core 5 communicate
values and if C4> C5 then store C5 in core 4 and C4 in core 5 i.e. exchange values, otherwise do
nothing. Finally, Core 6 and Core 7 communicate values and if C6> C7 then store C7 in core 6
and C6 in core 7 i.e. exchange values, otherwise do nothing.
Phase 2: Core 1 and Core 2 communicate (use MPI send and receive commands) values and if
C1> C2 then store C2 in core 1 and C1 in core 2 i.e. exchange values, otherwise do nothing.
Then similarly Core 3 and Core 4 communicate values and if C3> C4 then store C4 in core 3 and
C3 in core 4 i.e. exchange values, otherwise do nothing. Finally, Core 5 and Core 6 communicate
values and if C5> C6 then store C6 in core 5 and C5 in core 6 i.e. exchange values, otherwise do
nothing.
Repeat this process 4 times.
After this is complete, have each core send their current value to core 0, and have core 0 print
the values in sorted order (see Hello2.c example in slides). Use a for loop to receive values from
each core and print as you receive them, this ensures they will be printed in order of rank

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!