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 oddeven sort.
Use cores ntasks and tasks per node should be in your script each one will hold value.
Each core will have 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 ie the values C C C C C C C
C should be unsorted where Ci indicates the value core with rank i has You can do this by
giving each core the value 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 phases.
Phase : Core and Core communicate use MPI send and receive commands values and if
C C then store C in core and C in core ie exchange values, otherwise do nothing.
Then similarly Core and Core communicate values and if C C then store C in core and
C in core ie exchange values, otherwise do nothing. Then Core and Core communicate
values and if C C then store C in core and C in core ie exchange values, otherwise do
nothing. Finally, Core and Core communicate values and if C C then store C in core
and C in core ie exchange values, otherwise do nothing.
Phase : Core and Core communicate use MPI send and receive commands values and if
C C then store C in core and C in core ie exchange values, otherwise do nothing.
Then similarly Core and Core communicate values and if C C then store C in core and
C in core ie exchange values, otherwise do nothing. Finally, Core and Core communicate
values and if C C then store C in core and C in core ie exchange values, otherwise do
nothing.
Repeat this process times.
After this is complete, have each core send their current value to core and have core print
the values in sorted order see Helloc 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
