多核課程設計 氣泡排序的序列和並行版本比較

2021-10-10 03:03:38 字數 1763 閱讀 8123

程式**:

//序列氣泡排序

#include

#include

using

namespace std;

const

int num =

10000

;//排序10000個數

void

bubblesort

(int

* array,

int size)}}

//輸出排序後的陣列

for(

int i =

0; i < size; i++)}

intmain()

int m_size =

sizeof

(arr1)

/sizeof

(arr1[0]

);start =

clock()

;bubblesort

(arr1, m_size)

;//呼叫氣泡排序

finish =

clock()

; utime =

(double

)(finish - start)

/ clocks_per_sec;

cout <<

"序列氣泡排序用時:"

<< utime << endl;

system

("pause");

return0;

}

//並行氣泡排序

#include

#include

using

namespace std;

const

int num =

10000

;void

parallel_bubblesort

(int

*array,

int len)}}

else}}

}}void

printarr

(int

* array,

int len)

}int

main()

int m_len =

sizeof

(arr1)

/sizeof

(arr1[0]

);start =

clock()

;parallel_bubblesort

(arr1, m_len)

;printarr

(arr1, m_len)

; finish =

clock()

; utime =

(double

)(finish - start)

/ clocks_per_sec;

cout <<

"並行氣泡排序用時:"

<< utime << endl;

system

("pause");

return0;

}

這是對10個隨機數進行氣泡排序的執行時間

實驗結論:

通過對序列化冒泡和並行化奇偶氣泡排序的對比來看,並行化程式並不能很明顯的提高氣泡排序的效能。其中的原因有兩點:

1.並行化的開銷(執行緒的建立、執行緒間的切換)。

2.氣泡排序的本身(氣泡排序的時間複雜度為o(n²),並不適合進行大資料量的排序)。

python opencv的簡單課程設計

從網上找了很多關於處理的資料,整合了下,就有了這個簡單的課程設計。直接附上 author linjiaxiaozhu import cv2 from matplotlib import pyplot as plt import numpy as np from math import path in...

大一的課程設計

include include include include define max 20 define infinity 9999 typedef struct arcell bianchang max max typedef struct node point typedef struct gr...

資料結構各種內部排序課程設計

datalist.h include include const int defaultsize 100 templateclass datalist templateclass element t getkey void setkey const t x element operator elem...