







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








5-
data_t
array
[n]; result_t
result
tally_t
nodeval'[t
forall(index
in^ (0..t
tally_t
tally; tally
=^ localTally(mySize(array
localize(array
for^ (int stride
stride
<^ t;
stride
if^ (index
*^ stride)
tally
=^ combine
(tally,
nodeval'[index
+^ stride]);
}^ else
nodeval'[index]
=^ tally;
break;} } if^ (index
result
=^ reduceGen
(tally);
data_t
array
[n];^
result_t
result
[n];
tally_t
nodeval'[t
],^ pval'[t
];
forall(index
in^ (0..t
-1))^
{
tally_t
tally
=^ localTally(mySize(array
,^ 0), localize(array
));
for^ (int
stride
=^ 1;
stride
<^ t;
stride
*=^ 2) {
if^ (index
%^ (
*^ stride)
==^ 0)
{
pval'[index+stride]
=^ tally;
/*^ left
total to right child */
tally
=^ combine
(tally,
nodeval'[index
}^ else
{ nodeval'[index]
=^ tally;
break;} } tally_t^ ptally
=^ propagateParentTally(index);
localScanGen(ptally,
mySize(array
,^ 0),
localize(array
),^ localize(result
));
}
tally_t
propagateParentTally(int
index)
{ tally_t
ptally; if^ (index
ptally
=^ init
else/* Parent
supplies
left
total
then
parent
ptally
=^ combine
(pval'[index],
pval'[index]);
/*^ Propagate
total
from
parent
to^ right
children
for^ (int stride
stride
<^ t ;^ stride
if^ (index
*^ stride)
pval'[index+stride]
=^ ptally;
elsebreak;} return^
ptally; }