C++ parallel merge sortParallel Merge SortMerge Sort in C++Merge Sort algorithmParallel Merge Sort in ScalaRun-aware merge sortSlow merge sortParallel merge sort in JavaMultithreaded bottom up merge sortC++ Merge Sort ImplementationC++: Merge Sort Implementation

OP Amp not amplifying audio signal

What's the meaning of "Sollensaussagen"?

Send out email when Apex Queueable fails and test it

Do creatures with a speed 0ft., fly 30ft. (hover) ever touch the ground?

Could the museum Saturn V's be refitted for one more flight?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

Pact of Blade Warlock with Dancing Blade

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

How exploitable/balanced is this homebrew spell: Spell Permanency?

Bullying boss launched a smear campaign and made me unemployable

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

How to show a landlord what we have in savings?

Why was the shrink from 8″ made only to 5.25″ and not smaller (4″ or less)

Knowledge-based authentication using Domain-driven Design in C#

Why are UK visa biometrics appointments suspended at USCIS Application Support Centers?

Processor speed limited at 0.4 Ghz

How do conventional missiles fly?

Mathematica command that allows it to read my intentions

What is the most common color to indicate the input-field is disabled?

Machine learning testing data

Getting extremely large arrows with tikzcd

What does the same-ish mean?

How to stretch the corners of this image so that it looks like a perfect rectangle?



C++ parallel merge sort


Parallel Merge SortMerge Sort in C++Merge Sort algorithmParallel Merge Sort in ScalaRun-aware merge sortSlow merge sortParallel merge sort in JavaMultithreaded bottom up merge sortC++ Merge Sort ImplementationC++: Merge Sort Implementation













2












$begingroup$


I'm a first year computer engineering student who's learning about algorithms and data structures. I've implemented a parallel merge sort algorithm in C++ and would like constructive criticism. This was done in Visual Studio on Windows.



Some thoughts:



  • portability isn't a concern I have atm.


  • merge_sort isn't using tail recursion, which I would like it to do



function merge:



template<typename T>
void merge(T sequence[], int size)

T* sorted = new T[size];
int middle = size / 2;

int index_left = 0;
int index_right = middle;
int index_sequence = 0;

while (index_left < middle && index_right < size)

if (sequence[index_left] < sequence[index_right])
sorted[index_sequence++] = sequence[index_left++];
else
sorted[index_sequence++] = sequence[index_right++];


while (index_left < middle)
sorted[index_sequence++] = sequence[index_left++];

while (index_right < size)
sorted[index_sequence++] = sequence[index_right++];

for (int i = 0; i < size; i++)
sequence[i] = sorted[i];

delete[] sorted;




function merge_sort:



template<typename T, int min_size_to_thread = 10000>
void merge_sort(T sequence[], int size)

if (size > 1)

int middle = size / 2;
if (size > min_size_to_thread)

std::thread left(merge_sort<T, min_size_to_thread>, &sequence[0], middle);
std::thread right(merge_sort<T, min_size_to_thread>, &sequence[middle], size - middle);
left.join();
right.join();

else

merge_sort<T, min_size_to_thread>(&sequence[0], middle);
merge_sort<T, min_size_to_thread>(&sequence[middle], size - middle);

merge<T>(sequence, size);







For those who are interested: I Did some performance testing on a i5-2530M 2.50Ghz (2 cores).

The sequence to merge sort is int[100000]



test










share|improve this question









New contributor




user644361 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    Is std::thread right redundant?
    $endgroup$
    – user644361
    1 hour ago










  • $begingroup$
    I've tested: merge_sort runs faster without threading right, so it's better to only thread left and let right run in the main thread.
    $endgroup$
    – user644361
    1 hour ago















2












$begingroup$


I'm a first year computer engineering student who's learning about algorithms and data structures. I've implemented a parallel merge sort algorithm in C++ and would like constructive criticism. This was done in Visual Studio on Windows.



Some thoughts:



  • portability isn't a concern I have atm.


  • merge_sort isn't using tail recursion, which I would like it to do



function merge:



template<typename T>
void merge(T sequence[], int size)

T* sorted = new T[size];
int middle = size / 2;

int index_left = 0;
int index_right = middle;
int index_sequence = 0;

while (index_left < middle && index_right < size)

if (sequence[index_left] < sequence[index_right])
sorted[index_sequence++] = sequence[index_left++];
else
sorted[index_sequence++] = sequence[index_right++];


while (index_left < middle)
sorted[index_sequence++] = sequence[index_left++];

while (index_right < size)
sorted[index_sequence++] = sequence[index_right++];

for (int i = 0; i < size; i++)
sequence[i] = sorted[i];

delete[] sorted;




function merge_sort:



template<typename T, int min_size_to_thread = 10000>
void merge_sort(T sequence[], int size)

if (size > 1)

int middle = size / 2;
if (size > min_size_to_thread)

std::thread left(merge_sort<T, min_size_to_thread>, &sequence[0], middle);
std::thread right(merge_sort<T, min_size_to_thread>, &sequence[middle], size - middle);
left.join();
right.join();

else

merge_sort<T, min_size_to_thread>(&sequence[0], middle);
merge_sort<T, min_size_to_thread>(&sequence[middle], size - middle);

merge<T>(sequence, size);







For those who are interested: I Did some performance testing on a i5-2530M 2.50Ghz (2 cores).

The sequence to merge sort is int[100000]



test










share|improve this question









New contributor




user644361 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    Is std::thread right redundant?
    $endgroup$
    – user644361
    1 hour ago










  • $begingroup$
    I've tested: merge_sort runs faster without threading right, so it's better to only thread left and let right run in the main thread.
    $endgroup$
    – user644361
    1 hour ago













2












2








2





$begingroup$


I'm a first year computer engineering student who's learning about algorithms and data structures. I've implemented a parallel merge sort algorithm in C++ and would like constructive criticism. This was done in Visual Studio on Windows.



Some thoughts:



  • portability isn't a concern I have atm.


  • merge_sort isn't using tail recursion, which I would like it to do



function merge:



template<typename T>
void merge(T sequence[], int size)

T* sorted = new T[size];
int middle = size / 2;

int index_left = 0;
int index_right = middle;
int index_sequence = 0;

while (index_left < middle && index_right < size)

if (sequence[index_left] < sequence[index_right])
sorted[index_sequence++] = sequence[index_left++];
else
sorted[index_sequence++] = sequence[index_right++];


while (index_left < middle)
sorted[index_sequence++] = sequence[index_left++];

while (index_right < size)
sorted[index_sequence++] = sequence[index_right++];

for (int i = 0; i < size; i++)
sequence[i] = sorted[i];

delete[] sorted;




function merge_sort:



template<typename T, int min_size_to_thread = 10000>
void merge_sort(T sequence[], int size)

if (size > 1)

int middle = size / 2;
if (size > min_size_to_thread)

std::thread left(merge_sort<T, min_size_to_thread>, &sequence[0], middle);
std::thread right(merge_sort<T, min_size_to_thread>, &sequence[middle], size - middle);
left.join();
right.join();

else

merge_sort<T, min_size_to_thread>(&sequence[0], middle);
merge_sort<T, min_size_to_thread>(&sequence[middle], size - middle);

merge<T>(sequence, size);







For those who are interested: I Did some performance testing on a i5-2530M 2.50Ghz (2 cores).

The sequence to merge sort is int[100000]



test










share|improve this question









New contributor




user644361 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I'm a first year computer engineering student who's learning about algorithms and data structures. I've implemented a parallel merge sort algorithm in C++ and would like constructive criticism. This was done in Visual Studio on Windows.



Some thoughts:



  • portability isn't a concern I have atm.


  • merge_sort isn't using tail recursion, which I would like it to do



function merge:



template<typename T>
void merge(T sequence[], int size)

T* sorted = new T[size];
int middle = size / 2;

int index_left = 0;
int index_right = middle;
int index_sequence = 0;

while (index_left < middle && index_right < size)

if (sequence[index_left] < sequence[index_right])
sorted[index_sequence++] = sequence[index_left++];
else
sorted[index_sequence++] = sequence[index_right++];


while (index_left < middle)
sorted[index_sequence++] = sequence[index_left++];

while (index_right < size)
sorted[index_sequence++] = sequence[index_right++];

for (int i = 0; i < size; i++)
sequence[i] = sorted[i];

delete[] sorted;




function merge_sort:



template<typename T, int min_size_to_thread = 10000>
void merge_sort(T sequence[], int size)

if (size > 1)

int middle = size / 2;
if (size > min_size_to_thread)

std::thread left(merge_sort<T, min_size_to_thread>, &sequence[0], middle);
std::thread right(merge_sort<T, min_size_to_thread>, &sequence[middle], size - middle);
left.join();
right.join();

else

merge_sort<T, min_size_to_thread>(&sequence[0], middle);
merge_sort<T, min_size_to_thread>(&sequence[middle], size - middle);

merge<T>(sequence, size);







For those who are interested: I Did some performance testing on a i5-2530M 2.50Ghz (2 cores).

The sequence to merge sort is int[100000]



test







c++ beginner multithreading sorting mergesort






share|improve this question









New contributor




user644361 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




user644361 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 3 mins ago









200_success

131k17156422




131k17156422






New contributor




user644361 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









user644361user644361

604




604




New contributor




user644361 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user644361 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user644361 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • $begingroup$
    Is std::thread right redundant?
    $endgroup$
    – user644361
    1 hour ago










  • $begingroup$
    I've tested: merge_sort runs faster without threading right, so it's better to only thread left and let right run in the main thread.
    $endgroup$
    – user644361
    1 hour ago
















  • $begingroup$
    Is std::thread right redundant?
    $endgroup$
    – user644361
    1 hour ago










  • $begingroup$
    I've tested: merge_sort runs faster without threading right, so it's better to only thread left and let right run in the main thread.
    $endgroup$
    – user644361
    1 hour ago















$begingroup$
Is std::thread right redundant?
$endgroup$
– user644361
1 hour ago




$begingroup$
Is std::thread right redundant?
$endgroup$
– user644361
1 hour ago












$begingroup$
I've tested: merge_sort runs faster without threading right, so it's better to only thread left and let right run in the main thread.
$endgroup$
– user644361
1 hour ago




$begingroup$
I've tested: merge_sort runs faster without threading right, so it's better to only thread left and let right run in the main thread.
$endgroup$
– user644361
1 hour ago










0






active

oldest

votes












Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






user644361 is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216746%2fc-parallel-merge-sort%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








user644361 is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















user644361 is a new contributor. Be nice, and check out our Code of Conduct.












user644361 is a new contributor. Be nice, and check out our Code of Conduct.











user644361 is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216746%2fc-parallel-merge-sort%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

格濟夫卡 參考資料 导航菜单51°3′40″N 34°2′21″E / 51.06111°N 34.03917°E / 51.06111; 34.03917ГезівкаПогода в селі 编辑或修订