• R/O
  • SSH

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

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


Commit MetaInfo

Révisioned8c28789540c0e9f712bb34383bf6db22ed694b (tree)
l'heure2018-12-16 15:54:51
AuteurEric Hopper <hopper@omni...>
CommiterEric Hopper

Message de Log

Switched to using raw arrays instead of vectors. <obj size

I didn't need any of the nice things vectors give you, no resizing
or anything. The executable shrank quite significantly, even
though I'm still using a deque.

Change Summary

Modification

diff -r e36b2c2fcb58 -r ed8c28789540 mysort.cpp
--- a/mysort.cpp Wed Dec 12 10:20:17 2018 -0800
+++ b/mysort.cpp Sat Dec 15 22:54:51 2018 -0800
@@ -4,11 +4,12 @@
44 #include <deque>
55 #include <random>
66 #include <utility>
7+#include <memory>
78 #include <cstdint>
89 //#include <fstream>
910
10-using vecsize_t = ::std::vector<::std::uint32_t>::size_type;
11-using veciter_t = ::std::vector<::std::uint32_t>::iterator;
11+using vecsize_t = ::std::uint64_t;
12+using veciter_t = ::std::uint32_t *;
1213
1314 void gen_and_sort_section(const veciter_t &begin, const veciter_t &end, int seed)
1415 {
@@ -58,22 +59,25 @@
5859
5960 int main()
6061 {
61- using ::std::vector;
6262 using ::std::thread;
63+ using ::std::unique_ptr;
64+ using ::std::make_unique;
65+ using ::std::uint32_t;
6366
6467 constexpr auto size = 1ULL << 31;
65- ::std::vector<::std::uint32_t> huge_array(size);
68+ auto huge_array = make_unique<uint32_t[]>(size);
6669 const int cpucount = ::std::max(thread::hardware_concurrency() / 2, 1U);
6770 const int sections = cpucount;
68- vector<decltype(huge_array.begin())> partitions(sections + 1);
71+ const int secmarkers = sections + 1;
72+ auto partitions = make_unique<veciter_t[]>(secmarkers);
6973
70- partitions[0] = huge_array.begin();
71- for (unsigned int i = 1; i < partitions.size(); ++i) {
74+ partitions[0] = &(huge_array[0]);
75+ for (int i = 1; i < secmarkers; ++i) {
7276 auto const prev_part = partitions[i - 1];
73- auto const remaining = partitions.size() - i;
74- partitions[i] = prev_part + (huge_array.end() - prev_part) / remaining;
77+ auto const remaining = secmarkers - i;
78+ partitions[i] = prev_part + (&(huge_array[size]) - prev_part) / remaining;
7579 }
76- if (partitions[partitions.size() - 1] != huge_array.end()) {
80+ if (partitions[secmarkers - 1] != &(huge_array[size])) {
7781 return 1;
7882 }
7983