Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

1

7860

Bitonic Sort
. (
) recBitonicSort bitonicMerge.
, ,
.
thread
thread
pthread_join() thread
. parallelBMerge:
pthread_create(&thread,&attr,parallelBMerge,&newThData1);
parallelBMerge(&newThData2);
pthread_join(thread,NULL);
parallelBSort:
pthread_create(&thread,&attr,parallelBSort,&newThData1);
parallelBSort(&newThData2);
pthread_join(thread,NULL);
bitonicMerge
threads. , ,
thread
data races .
bitonicMerge
:
bitonicMerge(lo, k, dir);
bitonicMerge(lo+k, k, dir);
, bitonicMerge bitonicMerge(lo, cnt, dir); recBitonicSort
data sets fork-join
.

threads.

threads .
N=2^24 P=4 threads. S24
sort N=2^24. , M23
Merge N=2^23 ... S22 qsort()
stdlib c. :

if (cnt<=N/P){
if (dir==1){
qsort(a+lo,cnt,sizeof(int),compareAsc);
}
else {
qsort(a+lo,cnt,sizeof(int),compareDesc);
}
}
else {
Merge:
if (cnt<=N/P){
bitonicMerge(lo,cnt,dir);
}
else {


4 P=4 threads.
4 threads
4 , threads 4.
P=8,16,32,...
. ,


data races .

, N=2^24 P=4 threads. SX
( =24 23 22)
. S21
qsort() =2^21 qsort(21).
/2 compare ( /2c)
:
int k=cnt/2;
int i;
for (i=lo;i<lo+k;i++)
compare(i,i+k,dir);
M22 Merge =2^22.
,
.
, 4 :
4=qsort(22)+22c+M22+23c+22c+M22 = qsort(22)+2M(22)+24c
threads
P=8 8
.
8=qsort(21)+21c+M21+22c+21c+M21+23c+22c+21c+M21=
=qsort(21)+3M21+24c+22c+21c
:
4-8=qsort(22)-qsort(21)+M21-21c
(22)=21c+2M(21). M(21) :
(21)=20c+2*19c+4*18c+8*17c+... =20*20c=10*21c :
4-8=qsort(22)-qsort(21)+9*21c
diades 21c=0.007 9*21c
0,063 . , ,
qsort() ( 0.665
diades) =2^24
22 21,
.
, 4
threads 8 threads 8 0,665+0,063=0,728 .
diades P=4 t4=1.722s P=8 t8=1.032s,
t4-t8=0.69s . threads
.
, 16 P=16
threads.

P=4 threads 1,104s. ,, diades


16 P=8 threads.
,
threads
.
threads
threads.
pthreads diades
PthreadTimeDiades.txt.

=[2^16 2^24] P=[2 4 8 256]
qsort .

,
1,5 =2^16 5,5
=2^24.
(overhead)
pthreads. P=2^3=8 threads

threads. 256 threads,,
qsort.
, '
OpenMP ( thread
spawn )
. OpenMP :

2 threads
qsort N, 1,8 1,2
.
OmpTimeDiades.txt.

test().

You might also like