{"id":18564858,"url":"https://github.com/marcoplaitano/counting-sort-cuda","last_synced_at":"2026-05-14T01:40:50.664Z","repository":{"id":177293399,"uuid":"456462253","full_name":"marcoplaitano/counting-sort-cuda","owner":"marcoplaitano","description":"Parallelized version of Counting Sort using CUDA","archived":false,"fork":false,"pushed_at":"2022-02-07T10:42:00.000Z","size":27,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-15T18:47:30.043Z","etag":null,"topics":["counting-sort","cuda","cuda-kernels","cuda-programming","gpu","gpu-programming","sort","sorting","sorting-algorithms"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcoplaitano.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-07T10:41:20.000Z","updated_at":"2023-12-21T16:31:42.000Z","dependencies_parsed_at":"2023-07-25T08:31:32.351Z","dependency_job_id":null,"html_url":"https://github.com/marcoplaitano/counting-sort-cuda","commit_stats":null,"previous_names":["marcoplaitano/counting-sort-cuda"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marcoplaitano/counting-sort-cuda","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoplaitano%2Fcounting-sort-cuda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoplaitano%2Fcounting-sort-cuda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoplaitano%2Fcounting-sort-cuda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoplaitano%2Fcounting-sort-cuda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcoplaitano","download_url":"https://codeload.github.com/marcoplaitano/counting-sort-cuda/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoplaitano%2Fcounting-sort-cuda/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260919577,"owners_count":23082793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["counting-sort","cuda","cuda-kernels","cuda-programming","gpu","gpu-programming","sort","sorting","sorting-algorithms"],"created_at":"2024-11-06T22:16:32.411Z","updated_at":"2026-05-14T01:40:45.632Z","avatar_url":"https://github.com/marcoplaitano.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# COUNTING SORT CUDA\n\nThis project presents a version of [Counting Sort] Algorithm that has been\nparallelized by use of the [CUDA] environment on **NVIDIA GPUs**.\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Counting Sort\n\nCounting Sort is an algorithm for sorting a collection of objects according to\ntheir respective keys (small, positive integers).  \nThe assumption made on the input array is that it must be filled either with\nintegers in a range **[min, max]** or any other type of elements which can be\nrepresented each with a unique key in that range.  \nThis algorithm does not compare the elements but rather counts their frequency\nin the array to determine their new position.\n\nBelow, the pseudocode for the algorithm:\n\n```c\n1   initialize array[N]\n    // find min and max in the array\n2   min \u003c- array[0]\n3   max \u003c- array[0]\n4   for i \u003c- 1 to N\n5       if array[i] \u003c min\n6           min \u003c- array[i]\n7       if array[i] \u003e max\n8           max \u003c- array[i]\n9   end for\n    // initialize count array with a size equal to the [min, max] range\n10  range \u003c- max - min + 1\n11  initialize count[range]\n    // count the number of occurrences of each element\n12  for i \u003c- 0 to N\n13      count[array[i] - min] \u003c- count[array[i] - min] + 1\n14  end for\n    // reposition the elements based on their number of occurrences\n15  initialize z \u003c- 0\n16  for i \u003c- min to max\n17      for j \u003c- 0 to count[i - min]\n18          array[z] \u003c- i\n19          z \u003c- z + 1\n20      end for\n21  end for\n```\n\nWorst-case Time Complexity: **O(n + k)**  \nWhere *n* is the number of elements in the array and *k* is the size of the\n**[min, max]** range.\n\nWorst-case Space Complexity: **O(n + k)**.  \nIf the range **[min, max]** is far greater than the number of elements, the\nauxiliary array introduces a considerable amount of wasted space.\n\nAnother trait of this algorithm is its *Stability*: elements sharing the same\nkey will retain their relative positions.\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Performance Evaluation\n\nTo verify and estimate the benefits of parallelization, a [shell cript] can\n[be executed] to run the C program multiple times, with different combinations\nof these parameters:\n\n+ Array size\n+ Block and Grid size\n\nThe shell script calls (if not [told otherwise]) a [Python script] to create\ntables in order to easily compare the execution times of the different versions.\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Usage\n\nIn order to be able to execute the following script, *cd* into the project's\nroot directory and give it executable permissions:\n\n```shell\nchmod +x ./scripts/*.sh\n```\n\n### Generate the data\n\nTo generate the data regarding the execution times evaluation and comparison,\nlaunch the following shell script.  \nTake a look at the [dependencies] required to run the script.\n\n```shell\n./scripts/measures.sh [OPTION]...\n```\n\n#### Options and Parameters for Measures\n\nThe script supports the definition of various options and/or parameters via\ncommand line arguments.\n\n| Argument                       | Description               |\n| :---                           | :----                     |\n| -h, --help                     | Show guide and quit.      |\n| -n **N**, --num-measures **N** | Run every measure **N** times. (default is 20)\\* |\n| -d **DIR**, --dir **DIR**      | Specify output directory. (default is *./output*) |\n| --no-table                     | Do not run the Python script to create the tables. |\n\n\\* *The higher the number, the more precise the mean value is.*\n\nOther parameters, like the block sizes to use or the array size(s), can be\nmodified inside the script [itself].\n\n### Compile source files\n\nTo compile source files without the help of the shell script, use the makefile.\n\nCompile sources to generate parallel version that runs on **NVIDIA** GPUs:\n\n```shell\nmake parallel\n```\n\nOr compile serial version that runs on any CPU:\n\n```shell\nmake serial\n```\n\nIn both cases the executable file produced is *bin/main.out*.\n\nCheck and modify the [makefile] based on the GPU's *Compute Capability* and to\ntoggle the OpenMP linking.\n\n### Clean\n\nTo delete object files and executables:\n\n```shell\nmake clean\n```\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Dependencies\n\nA list of *HW \u0026 SW* requirements to run the program and the scripts:\n\n+ NVIDIA GPU\n+ Bash Shell 4.2+\n+ nvcc 9+\n+ make\n+ OpenMP 4.5+\n+ Python 3.7+\n\n### Python modules\n\nThe following modules are needed to handle CSV files and tables and perform\nsome calculations:\n\n+ scipy\n+ numpy\n+ pandas\n+ prettytable\n\nUse **pip** to install these with the following command:\n\n```shell\npip install *module_name*\n```\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Author\n\nMarco Plaitano\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## License\n\nDistributed under the [GPLv3] license.\n\n\u003c!-- LINKS --\u003e\n\n[Counting Sort]:\nhttps://en.wikipedia.org/wiki/Counting_sort\n\"Wikipedia article\"\n\n[CUDA]:\nhttps://developer.nvidia.com/cuda-toolkit\n\"Main website\"\n\n[shell cript]:\nscripts/measures.sh\n\"Repository file\"\n\n[be executed]:\n#generate-the-data\n\"Anchor to header\"\n\n[told otherwise]:\n#options-and-parameters-for-measures\n\"Anchor to header\"\n\n[Python script]:\nscripts/evaluate.py\n\"Repository file\"\n\n[dependencies]:\n#dependencies\n\"Anchor to header\"\n\n[itself]:\nscripts/measures.sh\n\"Repository file\"\n\n[makefile]:\nmakefile\n\"Repository file\"\n\n[GPLv3]:\nLICENSE\n\"Repository file\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcoplaitano%2Fcounting-sort-cuda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcoplaitano%2Fcounting-sort-cuda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcoplaitano%2Fcounting-sort-cuda/lists"}