omnifarious

# C++ Parallel Sort

• R/O
• SSH

## コミット

#### よく使われているワード(クリックで追加)

A simple parallel sort as a demonstration of how easy (and fast) this is in C++

### コミットメタ情報

リビジョン e36b2c2fcb589cbaaeee6febc7da353123e41753 (tree) 2018-12-13 03:20:17 Eric Hopper Eric Hopper

### ログメッセージ

Initial versions of a C sort vs. a C++ sort.

### 差分

diff -r 000000000000 -r e36b2c2fcb58 csort.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/csort.c Wed Dec 12 10:20:17 2018 -0800
 @@ -0,0 +1,36 @@ 1 +#include 2 +#include 3 +#include 4 + 5 +const uint32_t total_size = 1ULL << 31; 6 + 7 +int compare_ints(void const *a, void const *b) 8 +{ 9 + const uint32_t ta = *((uint32_t *)a); 10 + const uint32_t tb = *((uint32_t *)b); 11 + return (ta > tb) ? 1 : ((ta == tb) ? 0 : -1); 12 +} 13 + 14 +uint32_t get_urandom() 15 +{ 16 + FILE *urandom = fopen("/dev/urandom", "rb"); 17 + char buf[4]; 18 + fread(buf, 1U, 4, urandom); 19 + fclose(urandom); 20 + return ((uint32_t)(buf[0]) << 24) | 21 + ((uint32_t)(buf[1]) << 16) | 22 + ((uint32_t)(buf[2]) << 8) | 23 + (uint32_t)(buf[3]); 24 +} 25 + 26 +int main() 27 +{ 28 + uint32_t * const huge_array = calloc(total_size, sizeof(uint32_t)); 29 + uint32_t seed = get_urandom(); 30 + seed = (seed * 48271) % 2147483647ULL; 31 + for (uint32_t i = 0; i < total_size; ++i) { 32 + huge_array[i] = seed; 33 + seed = (seed * 48271) % 2147483647ULL; 34 + } 35 + qsort(huge_array, total_size, sizeof(huge_array[0]), compare_ints); 36 +}
diff -r 000000000000 -r e36b2c2fcb58 mysort.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mysort.cpp Wed Dec 12 10:20:17 2018 -0800