Created
May 5, 2015 15:03
-
-
Save wdv4758h/790ff9cd911af45cc4f3 to your computer and use it in GitHub Desktop.
Sleep Sort with OpenMP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// version 1, just print it | |
#include <cstdio> | |
#include <vector> | |
#include <unistd.h> // sleep | |
void sleep_sort(std::vector<unsigned long long> &data) { | |
const auto length = data.size(); | |
#pragma omp parallel num_threads(length) | |
{ | |
#pragma omp for | |
for (unsigned long i = 0; i < length; i++) { | |
sleep(data[i]); | |
printf("%llu\n", data[i]); | |
} | |
} | |
} | |
int main(int argc, char *argv[]) { | |
std::vector<unsigned long long> data(argc-1); | |
#pragma omp parallel for | |
for (int i = 0; i < argc-1; i++) { | |
sscanf(argv[i+1], "%llu", &data[i]); | |
} | |
sleep_sort(data); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment