next up previous contents
Next: Stored Tree Up: Program Design Previous: Program Design

Base 3 Counter

This algorithm calculates the cost for every possible combination of the tasks by fact that a combination can be represented as a base 3 number. For an n digit number there are tex2html_wrap_inline174 different digit arrangements or combinations. The Base 3 Counter algorithm counts from 0 to tex2html_wrap_inline174 where n is the number of tasks to order. For each count the number is converted to base 3 and the time cost of running for that order is calculated from the table of costs. If the calculated cost is less than the current lowest cost then the current number and its cost are stored as the new lowest. Below is a short pseudo-code of the algorithm:

 for  tex2html_wrap_inline180  to  tex2html_wrap_inline174  do

tex2html_wrap_inline184 calccost(i)

if time < lowest then

tex2html_wrap_inline190

tex2html_wrap_inline192

 calccost(i)

tex2html_wrap_inline196 tobase3(i)

for tex2html_wrap_inline200 downto 0 do

tex2html_wrap_inline204

tex2html_wrap_inline206 max(time)

The calccost function uses a two dimensional array taskweight that contains the time taken by each task on each processor. time is an array [0..2] that the intermediate sum of time on each processor is stored for use in max. max is a simple function that returns the largest of the three values sent to it which is the running time of ith ordering. The number lowestset stores which ith ordering is the smallest so far, and can be used to show what ordering was obtained as smallest.



Jamie Marconi
Thu May 23 20:07:44 PDT 1996