Click here to load reader

Παράλληλος Προγραμματισμός

Embed Size (px)

DESCRIPTION

Παράλληλος Προγραμματισμός. Κώστας Διαμαντάρας Τμήμα Πληροφορικής ΤΕΙ Θεσσαλονίκης 2011. Ο νόμος του Amdahl - υπενθύμιση. Κάθε αλγόριθμος έχει ένα ποσοστό s που δεν παραλληλίζεται ( σειριακό τμήμα του αλγορίθμου) - PowerPoint PPT Presentation

Citation preview

-

2011 , / . 4 (task) = = (process) = / . 5 ; ( , I/O, , ) hardware / . 6 (atomic exchange) (fetch-and-increment) (test-and-set)Atomic Exchange / . 7 R X () RXFecth and Increment / . 8 R, XR = XX = X+1RXX+1 Test and Set / . 9 R, XR = Xif (R==0) X = 1RX1R==0 / . 10 C =

, C = C+1, C = C+2 load R5,Cload R2,Cadd R5,1add R2,1store C,R5store C,R2 - / . 11 S:S = 1 : , S = 0 : , lock(S) ( P(S)):while (S==1) { wait; }S=1; unlock(S) ( V(S)):S=0; (spin lock) / . 12 atomic exchange (aexch)

mov R1,#1;R1 = 1 = wait: aexch R1,S; R1 S bneqz R1,wait; S0 ; ; (goto wait) ....; / . 13 atomic exchange (aexch)

mov R1,#0;R1 = 0 = aexch R1,S; R1 S....; load-linked store-conditional / . 14load-linked: load link-register loadlink-register: bus store-conditional: store link-register == 0 store ( ) (. NaN, Inf, ) ll-sc / . 15 ld R4,#1;R4 = 1try: mov R3,R4; R4 R3 ll R2,S;load-linked sc R3,S;store-conditional beqz R3,try; store ( R3=0) mov R4,R2; ; S R4 / . 16 N-1 loops () / . 17lock(S_count);/* count */if (count==0) release=0;/* release *//* release = 0 -> *//* release = 1 -> OK */count = count +1;/* */unlock(S_count);/* o count */if (count==total) {/* */count=0;/* */release=1;/* */}else spin(release);/* release=1 */ / . 18 loopArelease1Areleaseiteration kiteration k+100100deadlock00 / . 19 releaseiteration k: release=0: stop, release=1: goiteration k+1: release=1:stop, release=0:goArelease1Areleaseiteration klocal_sense=10011110iteration k+1local_sense=00. . . . . () / . 20local_sense = 1-local_sense;/*local_sense = */lock(S_count);/* count */if (count==0) {/* release */release=1-local_sense;/* release = local_sense -> */}/* release = 1-local_sense -> */count = count+1;/* */unlock(S_count);/* o count */if (count==total) {/* */count=0;/* */release=local_sense;/* */}else spin(release==local_sense);/* */ / . 21 fork-join parbegin-parend monitor fork join / . 22fork Label : Labeljoin n : n Fork-join / . 23P1P2P3P4P6P5P7P8 :P1,P2,P3,...= = = Fork-join (2) / . 24fork L2;fork L6;goto L3;fork L4;fork L6;goto L5;goto L5;fork L6;goto L8;goto L8;fork L7;goto L5;goto L8;L1: P1;L2: P2;L3: P3;L4: P4;L5: join c5; P5;L6: join c6; P6;L7: P7;L8: join c8; P8;END.c5=3; c6=3; c8=3;P1P2P3P4P6P5P7P8 parbegin parend / . 25parbegin-parend : begin-end loop parend : parbegin-parend / . 26P1P2P3P4P5P1;parbegin P2; || P3; || P4;parendP5; / . 27: / . 28 : compile-time : run-time / . 29 : compile-time: : lock , unlock / . 30: , . S1, S2, S3, : S1, S2 P(S1), P(S2) V(S1) (2) / . 31 1 2 3 4...P(Sa)...P(Sb)...P(Sc).........V(Sa)...V(Sb)V(Sc)...P(Sb)...P(Sd)...P(Se)......V(Se)......V(Sd)...V(Sb)......P(Sc)...P(Se).........V(Se).........V(Sc)............P(Se)...P(Sf)...P(Sa)......V(Sf)V(Sa)...V(Se)......: / . 32SaSbScSdSeSf1122344 = / . 33SaSbScSdSeSf1122344 4...P(Sa)P(Se)...P(Sf)...P(Sa)......V(Sf)V(Sa)...V(Se)... / . 34 . , , ( ) . / . 35 : :