Author: Chengzhi Hu
This is a parallel sorting using MPI.
You shall install MPI before run this program.
The architecture is described below:
The program first read an unsorted file as input. The unsorted file contains 1 number per line.
By default, MAIN_PROCESS(0 ~ max node #) defined as a macro at the top of the code will do the I/O, and other process(node) will just wait.
Then MAIN_PROCESS will send the equivalent copy of input array to each node via MPI_Scatterv method.
Each node will perform a quick sort in to sort.
After that, merges will be performed. That is, treat the node named with even rank as master node. And treat the node named with odd rank as slave node.
Then merge these node as we perform a bottom up merge sort.
As a final result, MAIN_PROCESS will hold the final sorted array and print them out in a file.
You can just download the main.c and makefile. And in your terminal, enter the directory where your files downloaded. And just use command “make” to run the program.
Notice that, you can modify the makefile such that you can run with different number of nodes, given different input & output files.
By default,
NODE = 2
INPUT = sm.dat
OUTPUT = sm-sol.txt
Attention: you can't give a NODE number that is greater than the actual physical cores you have.