Merge sorting integers using the OpenMP library for paralleization. Pthreads nor C/C++ atomics are used to manage/synchronize threads. This program sorts a (specified) .txt file of unique integers and outputs the sorted list to a different (specified) .txt file. The input .txt file will be an unsorted data structure [Standard Template Library (STL) vector].
- Mergesort - divides into two halfs, then merges sorted halfs
Utilizing OpenMP with MergeSort has proven to be easier to implement, though skeptical in a sense of what's really going on outside of the documentation. There was also no documentation for utilizing a while loop in a parallel manner, so ended up using a single thread to accomplish those. Overall, though it was easier to implement OpenMP than pthreads, it's was worth the extra time before to see how everything was being setup within the code itself.
Testing:
- Compare OpenMP MergeSort against a sorted array (using sort()) to ensure array was properly sorted.
- Comparing execution time on OpenMP MergeSort against the traditional MergeSort (single threaded).
main.cpp- primary C++ file for program executionMakefile- create executable objects; C++14arg_parser.h- error handling and parsing for program's input optionsREADME.pdf- write-up for project
randomNumberGen.cpp- creates a text file with a specified number of random numbers from [ 1 - number size ]. Default number is 10,000 unless specified when ran (as second argument).pthread_add.h- threading if compiling on macOS (will still run as normal for linux systems)
Note: If zipped, first unzip file before proceeding.
- From root directory, run
makefrom the terminal. This will generate a program called mysort - Additionally, if wanting to create a text file (source.txt) of randomly generated numbers (repeatable), run
make numGenfrom the terminal. Then,./numGen <amount of numbers to generate>. If a second argument isn't passed in (./numGen), the program will generate a 10,000 random numbers (between 1 and 30,000) by default. - Next, follow execution syntax below for parallel algoritm sorting.
Make cleanwill remove all file generated bymake, to includemake numGen.
mysort [--name]
OR
mysort [source.txt] [-o out.txt]
mysort --name: prints name to console.source.txt: unsorted txt file of numbers, with each number on a new line-o out.txt: sorted txt file of numebrs, in which the program outputs/writes to
- Additional outputs: time of execution in nanoseconds and seconds
- None noted