   1 :program QuickSortParalelo;
                                           0 :PROGRAM 25 88 36 606
   2 :const MaxN = 8;
   3 :type VectInt = array [1..MaxN] of INTEGER;
   4 :VAR
   5 :    n           : INTEGER; { n£mero de elementos del array }
   6 :    S           : VectInt; { Array a ordenar }
   7 :    sum         : VectInt; { Array de paso para almacenar PrefixSum }
   8 :    mark        : VectInt;
   9 :
  10 :procedure input;
                                           5 :PROCEDURE 1 3
  11 :VAR i : INTEGER;
  12 :BEGIN
  13 :  write('number of elements (2,4 o 8)');
                                           8 :CONSTANT 1651340654
                                          10 :CONSTANT 1864397413
                                          12 :CONSTANT 1818566758
                                          14 :CONSTANT 1852140901
                                          16 :CONSTANT 673215348
                                          18 :CONSTANT 540290098
                                          20 :CONSTANT 691544175
                                          22 :WRITESTR 7 28
  14 :  readln(n);
                                          25 :GLOBALVAR 3
                                          27 :READINT
  15 :  writeln('write  ', n, ' elements INTEGERs');
                                          28 :CONSTANT 1953067639
                                          30 :CONSTANT 1948262501
                                          32 :WRITESTR 2 7
                                          35 :GLOBALVALUE 3
                                          37 :WRITEINT
                                          38 :CONSTANT 1701602592
                                          40 :CONSTANT 1953391981
                                          42 :CONSTANT 1313415283
                                          44 :CONSTANT 1162298708
                                          46 :CONSTANT 1162310482
                                          48 :WRITESTR 5 18
                                          51 :CONSTANT 2573
                                          53 :WRITESTR 1 2
  16 :  i:=1;
                                          56 :LOCALVAR 3
                                          58 :CONSTANT 1
                                          60 :SIMPLEASSIGN
  17 :  while i<=n DO
                                          61 :LOCALVALUE 3
                                          63 :GLOBALVALUE 3
                                          65 :NOTGREATER 1
  18 :    BEGIN
                                          67 :DO 22
  19 :      readln(S[i]);
                                          69 :GLOBALVAR 4
                                          71 :LOCALVALUE 3
                                          73 :INDEX 1 8 1 19
                                          78 :READINT
  20 :      i:=i+1;
                                          79 :LOCALVAR 3
                                          81 :LOCALVALUE 3
                                          83 :CONSTANT 1
                                          85 :ADD
                                          86 :SIMPLEASSIGN
  21 :    END;
                                          87 :GOTO -26
  22 :END; { input }
                                          89 :ENDPROC 0
  23 :
  24 :
  25 :procedure outputsum;
                                          91 :PROCEDURE 1 3
  26 :VAR i : INTEGER;
  27 :BEGIN
  28 :  writeln('array sum');
                                          94 :CONSTANT 1634890337
                                          96 :CONSTANT 1970479225
                                          98 :CONSTANT 1970479213
                                         100 :WRITESTR 3 9
                                         103 :CONSTANT 2573
                                         105 :WRITESTR 1 2
  29 :  i := 1;
                                         108 :LOCALVAR 3
                                         110 :CONSTANT 1
                                         112 :SIMPLEASSIGN
  30 :  while i <= n DO
                                         113 :LOCALVALUE 3
                                         115 :GLOBALVALUE 3
                                         117 :NOTGREATER 1
  31 :    BEGIN
                                         119 :DO 28
  32 :      write( sum[i], ' ');
                                         121 :GLOBALVAR 12
                                         123 :LOCALVALUE 3
                                         125 :INDEX 1 8 1 32
                                         130 :SIMPLEVALUE
                                         131 :WRITEINT
                                         132 :CONSTANT 1120796704
                                         134 :WRITESTR 1 1
  33 :      i:=i+1;
                                         137 :LOCALVAR 3
                                         139 :LOCALVALUE 3
                                         141 :CONSTANT 1
                                         143 :ADD
                                         144 :SIMPLEASSIGN
  34 :    END;
                                         145 :GOTO -32
  35 :  writeln;
                                         147 :CONSTANT 2573
                                         149 :WRITESTR 1 2
  36 :END; { outputTabla }
                                         152 :ENDPROC 0
  37 :
  38 :
  39 :procedure outputA;
                                         154 :PROCEDURE 1 3
  40 :VAR i : INTEGER;
  41 :BEGIN
  42 :  writeln('array A');
                                         157 :CONSTANT 1634890337
                                         159 :CONSTANT 1631658105
                                         161 :WRITESTR 2 7
                                         164 :CONSTANT 2573
                                         166 :WRITESTR 1 2
  43 :  i:=1;
                                         169 :LOCALVAR 3
                                         171 :CONSTANT 1
                                         173 :SIMPLEASSIGN
  44 :  while i <= n DO
                                         174 :LOCALVALUE 3
                                         176 :GLOBALVALUE 3
                                         178 :NOTGREATER 1
  45 :    BEGIN
                                         180 :DO 28
  46 :      write( S[i], ' ');
                                         182 :GLOBALVAR 4
                                         184 :LOCALVALUE 3
                                         186 :INDEX 1 8 1 46
                                         191 :SIMPLEVALUE
                                         192 :WRITEINT
                                         193 :CONSTANT 1120796704
                                         195 :WRITESTR 1 1
  47 :      i:=i+1;
                                         198 :LOCALVAR 3
                                         200 :LOCALVALUE 3
                                         202 :CONSTANT 1
                                         204 :ADD
                                         205 :SIMPLEASSIGN
  48 :    END;
                                         206 :GOTO -32
  49 :  writeln;
                                         208 :CONSTANT 2573
                                         210 :WRITESTR 1 2
  50 :END; { outputA }
                                         213 :ENDPROC 0
  51 :
  52 :TASK PrefixSum( left, right : INTEGER);
                                         215 :PROCEDURE 1 3
  53 :VAR mid:INTEGER;
  54 :BEGIN
  55 :  IF right > left THEN BEGIN
                                         218 :LOCALVALUE -1
                                         220 :LOCALVALUE -2
                                         222 :GREATER 1
                                         224 :PUSHPATTERN
                                         225 :COPYTOPS
                                         226 :GOIFZERO 86
  56 :    mid := (right+left) div 2;
                                         228 :LOCALVAR 3
                                         230 :LOCALVALUE -1
                                         232 :LOCALVALUE -2
                                         234 :ADD
                                         235 :CONSTANT 2
                                         237 :DIVIDE
                                         238 :SIMPLEASSIGN
  57 :    PARALLEL DO
                                         239 :PUSHPATTERN
  58 :      PrefixSum(left,mid) || PrefixSum(mid+1,right);
                                         240 :CONSTANT 0
                                         242 :CONSTANT 1
                                         244 :NESTEDPATTERN 25
                                         246 :PUSHPATTERN
                                         247 :PUSHPATTERN
                                         248 :SINGLECONTROL 0
                                         250 :LOCALVALUE -2
                                         252 :LOCALVALUE 3
                                         254 :POPPATTERN
                                         255 :PUSHPATTERN
                                         256 :SINGLECONTROL 1
                                         258 :LOCALVALUE 3
                                         260 :CONSTANT 1
                                         262 :ADD
                                         263 :LOCALVALUE -1
                                         265 :POPPATTERN
                                         266 :POPPATTERN
                                         267 :GLOBALCALL -52
                                         269 :OLDPATTERN
  59 :    PARALLEL mid+1..right DO
                                         270 :PUSHPATTERN
                                         271 :LOCALVALUE 3
                                         273 :CONSTANT 1
                                         275 :ADD
                                         276 :LOCALVALUE -1
                                         278 :NESTEDPATTERN 33
  60 :      sum[name] := sum[name] + sum[mid]
                                         280 :GLOBALVAR 12
                                         282 :PUSHNAME 60
                                         284 :INDEX 1 8 1 60
                                         289 :GLOBALVAR 12
                                         291 :PUSHNAME 60
                                         293 :INDEX 1 8 1 60
                                         298 :SIMPLEVALUE
                                         299 :GLOBALVAR 12
                                         301 :LOCALVALUE 3
                                         303 :INDEX 1 8 1 60
  61 :  END;
                                         308 :SIMPLEVALUE
                                         309 :ADD
                                         310 :SIMPLEASSIGN
                                         311 :OLDPATTERN
                                         312 :POPPATTERN
  62 :END;
                                         313 :ENDPROC 2
  63 :
  64 :
  65 :TASK Partition(left, right : INTEGER; VAR pivotPos: INTEGER);
                                         315 :PROCEDURE 2 3
  66 :VAR pivot, St : INTEGER;
  67 :BEGIN
  68 :  pivot := S[left];
                                         318 :LOCALVAR 3
                                         320 :GLOBALVAR 4
                                         322 :LOCALVALUE -3
                                         324 :INDEX 1 8 1 68
                                         329 :SIMPLEVALUE
                                         330 :SIMPLEASSIGN
  69 :  PARALLEL left..right DO BEGIN
                                         331 :PUSHPATTERN
                                         332 :LOCALVALUE -3
                                         334 :LOCALVALUE -2
                                         336 :NESTEDPATTERN 48
  70 :    IF S[name] > pivot THEN sum[name] := 1
                                         338 :GLOBALVAR 4
                                         340 :PUSHNAME 70
                                         342 :INDEX 1 8 1 70
                                         347 :SIMPLEVALUE
                                         348 :LOCALVALUE 3
                                         350 :GREATER 1
                                         352 :PUSHPATTERN
                                         353 :COPYTOPS
                                         354 :GOIFZERO 14
                                         356 :GLOBALVAR 12
                                         358 :PUSHNAME 70
                                         360 :INDEX 1 8 1 70
  71 :    ELSE sum[name] := 0;
                                         365 :CONSTANT 1
                                         367 :SIMPLEASSIGN
                                         368 :COMPLEMENT
                                         369 :GOIFZERO 14
                                         371 :GLOBALVAR 12
                                         373 :PUSHNAME 71
                                         375 :INDEX 1 8 1 71
                                         380 :CONSTANT 0
                                         382 :SIMPLEASSIGN
                                         383 :POPPATTERN
  72 :  END;
                                         384 :OLDPATTERN
  73 :  PrefixSum(left,right);
                                         385 :LOCALVALUE -3
                                         387 :LOCALVALUE -2
                                         389 :GLOBALCALL -174
  74 :  St := sum[right];
                                         391 :LOCALVAR 4
                                         393 :GLOBALVAR 12
                                         395 :LOCALVALUE -2
                                         397 :INDEX 1 8 1 74
                                         402 :SIMPLEVALUE
                                         403 :SIMPLEASSIGN
  75 :  pivotPos := right-St;
                                         404 :VARPARAM 0 -1
                                         407 :LOCALVALUE -2
                                         409 :LOCALVALUE 4
                                         411 :SUBTRACT
                                         412 :SIMPLEASSIGN
  76 :  PARALLEL (left+1)..right DO
                                         413 :PUSHPATTERN
                                         414 :LOCALVALUE -3
                                         416 :CONSTANT 1
                                         418 :ADD
                                         419 :LOCALVALUE -2
                                         421 :NESTEDPATTERN 110
  77 :    VAR pos : INTEGER;
  78 :    BEGIN
                                         423 :NEWBLOCK 1
  79 :      IF S[name] > pivot THEN
                                         425 :VARIABLE 2 4
                                         428 :PUSHNAME 79
                                         430 :INDEX 1 8 1 79
                                         435 :SIMPLEVALUE
                                         436 :GLOBALVALUE 3
                                         438 :GREATER 1
  80 :        pos := right - St + sum[name]
                                         440 :PUSHPATTERN
                                         441 :COPYTOPS
                                         442 :GOIFZERO 22
                                         444 :LOCALVAR 3
                                         446 :GLOBALVALUE -2
                                         448 :GLOBALVALUE 4
                                         450 :SUBTRACT
                                         451 :VARIABLE 2 12
                                         454 :PUSHNAME 80
                                         456 :INDEX 1 8 1 80
  81 :      ELSE
                                         461 :SIMPLEVALUE
                                         462 :ADD
                                         463 :SIMPLEASSIGN
                                         464 :COMPLEMENT
                                         465 :GOIFZERO 42
  82 :      IF S[name] <= pivot THEN
                                         467 :VARIABLE 2 4
                                         470 :PUSHNAME 82
                                         472 :INDEX 1 8 1 82
                                         477 :SIMPLEVALUE
                                         478 :GLOBALVALUE 3
                                         480 :NOTGREATER 1
  83 :        pos := name - sum[name] -1;
                                         482 :PUSHPATTERN
                                         483 :COPYTOPS
                                         484 :GOIFZERO 22
                                         486 :LOCALVAR 3
                                         488 :PUSHNAME 83
                                         490 :VARIABLE 2 12
                                         493 :PUSHNAME 83
                                         495 :INDEX 1 8 1 83
                                         500 :SIMPLEVALUE
                                         501 :SUBTRACT
                                         502 :CONSTANT 1
                                         504 :SUBTRACT
                                         505 :SIMPLEASSIGN
                                         506 :POPPATTERN
                                         507 :POPPATTERN
  84 :      S[pos] := S[name];
                                         508 :VARIABLE 2 4
                                         511 :LOCALVALUE 3
                                         513 :INDEX 1 8 1 84
                                         518 :VARIABLE 2 4
                                         521 :PUSHNAME 84
                                         523 :INDEX 1 8 1 84
                                         528 :SIMPLEVALUE
                                         529 :SIMPLEASSIGN
  85 :    END;
                                         530 :ENDBLOCK
                                         531 :OLDPATTERN
  86 :  S[pivotPos] := pivot;
                                         532 :GLOBALVAR 4
                                         534 :VARPARAM 0 -1
                                         537 :SIMPLEVALUE
                                         538 :INDEX 1 8 1 86
                                         543 :LOCALVALUE 3
                                         545 :SIMPLEASSIGN
  87 :END;
                                         546 :ENDPROC 3
  88 :
  89 :
  90 :
  91 :TASK sort( left, right : INTEGER );
                                         548 :PROCEDURE 1 3
  92 :VAR pivotPos : INTEGER;
  93 :BEGIN
  94 :  IF left < right THEN
                                         551 :LOCALVALUE -2
                                         553 :LOCALVALUE -1
                                         555 :LESS 1
  95 :    BEGIN
                                         557 :PUSHPATTERN
                                         558 :COPYTOPS
                                         559 :GOIFZERO 44
  96 :      Partition( left, right, pivotPos);
                                         561 :LOCALVALUE -2
                                         563 :LOCALVALUE -1
                                         565 :LOCALVAR 3
                                         567 :GLOBALCALL -252
  97 :      PARALLEL DO
                                         569 :PUSHPATTERN
  98 :        sort(left, pivotPos-1) || sort(pivotPos+1, right);
                                         570 :CONSTANT 0
                                         572 :CONSTANT 1
                                         574 :NESTEDPATTERN 28
                                         576 :PUSHPATTERN
                                         577 :PUSHPATTERN
                                         578 :SINGLECONTROL 0
                                         580 :LOCALVALUE -2
                                         582 :LOCALVALUE 3
                                         584 :CONSTANT 1
                                         586 :SUBTRACT
                                         587 :POPPATTERN
                                         588 :PUSHPATTERN
                                         589 :SINGLECONTROL 1
                                         591 :LOCALVALUE 3
                                         593 :CONSTANT 1
                                         595 :ADD
                                         596 :LOCALVALUE -1
                                         598 :POPPATTERN
                                         599 :POPPATTERN
                                         600 :GLOBALCALL -52
                                         602 :OLDPATTERN
  99 :    END; { IF left < right }
                                         603 :POPPATTERN
 100 :END; { sort }
                                         604 :ENDPROC 2
 101 :
 102 :BEGIN { main }
 103 :  input;
                                         606 :ACTIVE
                                         607 :PROCCALL 0 -602
                                         610 :ACTIVE
 104 :  sort( 1, n );
                                         611 :PUSHPATTERN
                                         612 :SINGLEPATTERN 0
                                         614 :CONSTANT 1
                                         616 :LOCALVALUE 3
                                         618 :PROCCALL 0 -70
                                         621 :OLDPATTERN
 105 :  outputA;
                                         622 :PROCCALL 0 -468
 106 :END.
 107 :
                                         625 :ENDPROG
