Question: 1 . Write a C program using MPI to implement parallel odd - even sort for the given total values of elements and cores. Your
Write a C program using MPI to implement parallel oddeven sort for the given total
values of elements and cores.
Your code will support m elements to sort, that is the number of elements to sort is even.
The number of cores p will be chosen such that mp is even. That is each core will have an
even number of elements this ensures that phase requires no interprocess communication
The total number of cores p wont necessarily be even, but you are guaranteed that mp is
even.
Each core will be assigned mp elements. You can either use one large array of size m that
each core will have a copy of or define arrays of size mp for each core.
In phase each core will do a compareexchange on elements that are assigned to it For
example if there are elements per core stored in an array A then core will compare
exchange A and A then A and A and so on for the other cores.
In phase each core will do a compareexchange on the its own elements but also a compare
exchange between the next core. For example if there are elements per core stored in array
A then core will compareexchange A and A then A and A Note that A is
assigned to core in this case. If there are elements in total and cores, then in phase :
core will compareexchange its A with core s A core will compareexchange A
with A in core You need to generalize this for the scenario where there is an even number
of elements and each core has an even number of elements assigned to it
Make sure you start with unsorted arrays.
After m rounds of phase and phase iem phases in total, the elements should be sorted.
After this is complete, have each core send their current values to core in order 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.
Note: if ntasks then make sure tasks per node is fixed at in your script when you
experiment.
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
