Upload
horace-parrish
View
214
Download
1
Embed Size (px)
Citation preview
Improved results for a Improved results for a memory allocation memory allocation problemproblem
Rob van SteeUniversity of KarlsruheGermany
Leah EpsteinLeah EpsteinUniversity of HaifaUniversity of Haifa
IsraelIsrael
WADS 2007WAOA 2007
BackgroundBackground
Allocate memory to parallel Allocate memory to parallel processorsprocessors
Goals:Goals:– Each processor has sufficient Each processor has sufficient
memorymemory– Not too much memory is wastedNot too much memory is wasted
BackgroundBackground
ProblemProblem: memory requirement : memory requirement may vary over timemay vary over time
If each processor can access only If each processor can access only one memoryone memory, this is inefficient, this is inefficient
If If allall processors share a single processors share a single memory, there is heavy memory, there is heavy contentioncontention
Suggested modelSuggested model
Chung et al. [SPAA 2004] suggest Chung et al. [SPAA 2004] suggest a new architecturea new architecture
Each memory may be accessed Each memory may be accessed by at most by at most twotwo processors processors
This avoids the mentioned This avoids the mentioned problemsproblems
Bin packingBin packing
They abstract this problem as a They abstract this problem as a bin packing problembin packing problem
Bins = memoriesBins = memories Items = memory requirements of Items = memory requirements of
processorsprocessors Thus, items may be larger than 1Thus, items may be larger than 1
Bin packingBin packing
Items may be split and distributed Items may be split and distributed among more than one binamong more than one bin
Condition: each bin contains at most Condition: each bin contains at most twotwo parts of items parts of items
Corresponds to: each memory may be Corresponds to: each memory may be accessed by at most two processorsaccessed by at most two processors
We also consider the model where We also consider the model where each bin may contain each bin may contain kk parts of items parts of items
NotesNotes
There may be many bins which There may be many bins which are not fullare not full
An item may be split more than An item may be split more than onceonce
No upper bound on how often No upper bound on how often each item is spliteach item is split
ResultsResults
Chung et al. [SPAA 2004]:Chung et al. [SPAA 2004]: – (k=2) NP-hardness(k=2) NP-hardness– (k=2) 3/2-approximation(k=2) 3/2-approximation
Epstein & vS [WADS 2007]:Epstein & vS [WADS 2007]: – (k=2) 7/5-approximation(k=2) 7/5-approximation– For general k:For general k:
Next Fit is (2-1/k)-approximationNext Fit is (2-1/k)-approximation NP-hardness in the strong senseNP-hardness in the strong sense
ResultsResults
Epstein & vS [WAOA 2007]:Epstein & vS [WAOA 2007]: A polynomial time approximation A polynomial time approximation
scheme (PTAS) for every (constant) scheme (PTAS) for every (constant) kk– For every constant For every constant >0, a polynomial >0, a polynomial
time algorithm that uses at most 1+ time algorithm that uses at most 1+ times the minimal number of bins times the minimal number of bins
– at most at most OPT additional bins of size 1OPT additional bins of size 1
ResultsResults
Epstein & vS [WAOA 2007]:Epstein & vS [WAOA 2007]: A dual approximation scheme for A dual approximation scheme for
every (constant) kevery (constant) k– For every constant For every constant >0, a polynomial >0, a polynomial
time algorithm that uses time algorithm that uses bins of size bins of size 1+ 1+
– Larger bins, but no additional binsLarger bins, but no additional bins
Next Fit Next Fit in this contextin this context
If current bin contains If current bin contains kk parts of parts of items items oror is fulll is fulll, open a new bin, open a new bin
Put as much as possible of the Put as much as possible of the current item in the current bincurrent item in the current bin
Open additional bin(s) if needed Open additional bin(s) if needed (for large items)(for large items)
Next Fit: lower boundNext Fit: lower bound
One item of size One item of size Mk-Mk-11– Next Fit uses Next Fit uses Mk-Mk-11 bins bins
M M ((k-k-1)1)kk very small items very small items– Next Fit puts Next Fit puts kk items in one bin, items in one bin,
uses uses M M ((k-k-1)1) bins bins
Mk -1 M (k -1)
Next Fit: lower boundNext Fit: lower bound
Optimal solution needs only Optimal solution needs only MkMk bins bins Ratio: (Ratio: (MM (2 (2kk-1)-1) /-1)-1) /MkMk 2 – 1/2 – 1/kk
Mk -1 M (k -1)
Mk
Next Fit: upper boundNext Fit: upper bound
BlockBlock = set of full bins, followed = set of full bins, followed by a bin with k itemsby a bin with k items
Each bin >1 in a block was Each bin >1 in a block was opened because the previous one opened because the previous one was fullwas full
WeightsWeights
WeightWeight of item with size s = of item with size s = ss/k/k There are at least There are at least ss parts of item parts of item
with size s in any packingwith size s in any packing
OPT is at least the OPT is at least the total weight of total weight of all the itemsall the items
1 ii
i i
sOPT s
k k
Next Fit: upper boundNext Fit: upper bound
Consider last bin in a block (Consider last bin in a block (not not the last blockthe last block))
Has Has kk items, so at least items, so at least k k -1-1 items items of weight of weight 1/1/kk (these items are not (these items are not split!)split!)
Block has 1 bin, then Block has 1 bin, then kk such items such items Else, consider all items in block Else, consider all items in block
except except the the k k -1 last items-1 last items
Next Fit: upper boundNext Fit: upper bound
SS = all items in block except = all items in block except the the k k -1 last items-1 last items
How many items are in How many items are in S S ? ? Unknown!Unknown!
What is the minimal What is the minimal weight weight of of S S ?? Weight = , minimized for Weight = , minimized for
singlesingle item item
is
k
Next Fit: upper boundNext Fit: upper bound
SS = all items in block except = all items in block except the the k k --1 last items 1 last items
For block of size For block of size bb, total size of , total size of items in S is strictly more than items in S is strictly more than b b -1-1
Total weight is then at least Total weight is then at least b b //kk Weight in block at least Weight in block at least bb / /k k +(+(k k --
1)/1)/kk Note: also true for block of size 1Note: also true for block of size 1
The last blockThe last block
Only one bin: weight at least 1/Only one bin: weight at least 1/kk (has at least one item)(has at least one item)
b b >1 bins: weight at least >1 bins: weight at least bb / /kk Let size of block Let size of block ii be be bbi i , then Next , then Next
Fit uses binsFit uses bins We know that OPT is at least the We know that OPT is at least the
total weighttotal weight
ib
Next Fit: upper boundNext Fit: upper bound
Let m be the Let m be the amount of blocksamount of blocks
Also, OPT > NF – Also, OPT > NF – m m (in each block, (in each block, at most one bin is at most one bin is not completely not completely fullfull))
k
kmNFk
kkbwOPT
i
m
ii
)1)(1(
)1()1(1
Next Fit: upper boundNext Fit: upper bound
Combining this we findCombining this we find
k
km
k
km
k
k
kNFOPT
k
kk
km
k
kNFOPT
k
kmNFOPT
1)1(
1)1(
1112
1)1(
111
1,)1)(1(
mNFOPTk
kmNFOPT
2323
This talkThis talk
We only discuss the algorithms We only discuss the algorithms for k=2for k=2
General propertiesGeneral properties PTASPTAS Dual PTASDual PTAS
Representation of Representation of solutionssolutions A solution can be seen as a graphA solution can be seen as a graph Vertices = itemsVertices = items An edge between two items = An edge between two items = Parts of these two items share a binParts of these two items share a bin
– A loop means that a bin contains just A loop means that a bin contains just one part of an itemone part of an item
We can assume a forest (with loops)We can assume a forest (with loops)– Cycles can be easily removed without Cycles can be easily removed without
changing the cost (Chung et al.,2004).changing the cost (Chung et al.,2004).
Additional propertiesAdditional properties
There exists an optimal packing forest There exists an optimal packing forest where all items of size in (0,1/2] are where all items of size in (0,1/2] are leaves or singletonsleaves or singletons
If the forest representation is minimal If the forest representation is minimal (no tree can be split) then a packing is (no tree can be split) then a packing is implied from the treeimplied from the tree– Can be done iterativelyCan be done iteratively– Singletons are packed into separate binsSingletons are packed into separate bins– A leaf is packed with a maximum amount of A leaf is packed with a maximum amount of
its neighbor, and removed from the forestits neighbor, and removed from the forest
PTAS for k=2PTAS for k=2
We would like to use standard We would like to use standard methods such asmethods such as– Linear grouping and roundingLinear grouping and rounding– Enumeration of patternsEnumeration of patterns
ButBut– Patterns are treesPatterns are trees– Items sizes are not bounded from Items sizes are not bounded from
aboveabove
New tricksNew tricks Optimal packing is adapted in order Optimal packing is adapted in order
to make it possible to imitate itto make it possible to imitate it Trees are “truncated” Trees are “truncated”
– Partitioned into smaller treesPartitioned into smaller trees Large items are truncatedLarge items are truncated
– Partitioned into several items that are Partitioned into several items that are still large, but boundedstill large, but bounded
The last two adaptations increase The last two adaptations increase the number of bins by a factor of 1+the number of bins by a factor of 1+
Trying all treesTrying all trees
Type of a tree is (j,E)Type of a tree is (j,E)– j is number of edgesj is number of edges– E is set of j-1 edges (so that it is a tree)E is set of j-1 edges (so that it is a tree)
Pattern = type plus vector of length jPattern = type plus vector of length j– Element i in the vector indicates Element i in the vector indicates groupgroup
of node iof node i ConstantConstant number of patterns number of patterns Only question: how many of each?Only question: how many of each?
Dual PTAS for k=2 Dual PTAS for k=2 (briefly)(briefly)
We use an integer parameter K, We use an integer parameter K, based on based on ..
Items can be rounded down to a Items can be rounded down to a sizes of the form i/Ksizes of the form i/K
We round some non-zero sizes We round some non-zero sizes into zero!into zero!
By scaling, we get items of By scaling, we get items of integer sizesinteger sizes, and a bin size , and a bin size KK
CuttingCutting
There is no reason to cut items at There is no reason to cut items at non-integer point non-integer point
For each item size (at most K), we For each item size (at most K), we define cutting patternsdefine cutting patterns
We “guess” how to cut the input We “guess” how to cut the input items items – Using enumerationUsing enumeration
Finding a solutionFinding a solution
We use a layered graph to find an We use a layered graph to find an optimal packing for each optionoptimal packing for each option– If the cutting was applied, the problem If the cutting was applied, the problem
becomes much easierbecomes much easier– However, we did not cut items larger than However, we did not cut items larger than
the bin sizethe bin size– We cut a piece off each one of them, but We cut a piece off each one of them, but
do not decide on all cutting pointsdo not decide on all cutting points The best (smallest number of bins) The best (smallest number of bins)
option is chosenoption is chosen Increasing items back to original sizes Increasing items back to original sizes
increases bins slightlyincreases bins slightly
Open problemsOpen problems
PTAS, dual PTAS for non-constant PTAS, dual PTAS for non-constant kk
(FPTAS or dual FPTAS are most (FPTAS or dual FPTAS are most likely impossible since the likely impossible since the problem is strongly NP-hard for problem is strongly NP-hard for every constant value of k)every constant value of k)
Generalize 7/5-approximation for Generalize 7/5-approximation for larger larger kk
7/5-approximation7/5-approximation
We show an approximation We show an approximation algorithm for k=2 (at most two algorithm for k=2 (at most two parts of items per bin allowed)parts of items per bin allowed)
First it sorts the itemsFirst it sorts the items Then it packs them, starting with Then it packs them, starting with
the most difficult ones: size the most difficult ones: size between ½ and 1between ½ and 1
We use We use Next FitNext Fit as a subroutine as a subroutine
Step 1: SortingStep 1: Sorting
Items of size at most ½ are Items of size at most ½ are smallsmall– Sort them in order of Sort them in order of increasingincreasing size size
Items larger than 1 are Items larger than 1 are largelarge– Sort them in order of Sort them in order of decreasingdecreasing size size
Other items are Other items are medium-sizedmedium-sized– Sort them in order of Sort them in order of decreasingdecreasing size size– We pack these items firstWe pack these items first
Step 2: medium-sized Step 2: medium-sized itemsitems Pack Pack medium-sizedmedium-sized items items
one by one:one by one:– If current item fits in one If current item fits in one
bin with the smallest bin with the smallest unpacked small item, pack unpacked small item, pack them togetherthem together
– Else, pack current item Else, pack current item together with two together with two largestlargest unpacked small items in unpacked small items in two binstwo bins
Step 3: all small items Step 3: all small items are packedare packed We do this until we run out of We do this until we run out of
either the medium-sized or the either the medium-sized or the small itemssmall items
If all small items are packed, use If all small items are packed, use Next Fit on rest, start with Next Fit on rest, start with medium-sized itemsmedium-sized items
Step 4: some small Step 4: some small items remainitems remain Pack each small item in Pack each small item in its own its own
binbin Pack large items into these bins Pack large items into these bins
using Next Fitusing Next Fit Still use ordering from before:Still use ordering from before:
– Largest large items firstLargest large items first– Smallest small items firstSmallest small items first
Step 5: small items leftStep 5: small items left
We have now run out of either the We have now run out of either the large or the small itemslarge or the small items
If bins with small items remain, If bins with small items remain, repackrepack these items two per bin these items two per bin
Step 6: large items leftStep 6: large items left
Pack remaining large items using Pack remaining large items using Next FitNext Fit
Upper boundUpper bound
We use the same weight definition We use the same weight definition as before: weight of item with size as before: weight of item with size s iss is
We know that OPT is at least the We know that OPT is at least the total weighttotal weight
How much weight do we pack in a How much weight do we pack in a bin? bin?
2i is s
k
Amount of weight Amount of weight packedpacked
Step 2:Step 2: Pack medium-sized items one by one:Pack medium-sized items one by one:
– If current item fits in one bin with the If current item fits in one bin with the smallest unpacked small item, pack smallest unpacked small item, pack them together. them together. Weight ½+½ = Weight ½+½ = 11
– Else, pack current item together with Else, pack current item together with two largest unpacked small items in two two largest unpacked small items in two bins. bins. Three items of weight ½ in two Three items of weight ½ in two bins: bins: ¾¾
Amount of weight Amount of weight packedpacked
Step 3:Step 3: If all small items are packed, use Next If all small items are packed, use Next
Fit on rest, start with medium-sized Fit on rest, start with medium-sized itemsitems
We assume We assume manymany small items small items existexist
Then, this step Then, this step does not occurdoes not occur
Amount of weight Amount of weight packedpacked
Step 4:Step 4: Pack each small item in Pack each small item in its own binits own bin Pack large items into these bins using Pack large items into these bins using
Next FitNext Fit Still use ordering from before:Still use ordering from before:
– Largest large items firstLargest large items first– Smallest small items firstSmallest small items first
Amount of weight Amount of weight packedpacked Consider a large item which is Consider a large item which is
packed into packed into gg bins bins It is packed together with It is packed together with gg small small
items (total weight items (total weight g g /2)/2) The large item has size strictly The large item has size strictly
more than (more than (g g -1)/2, so weight at -1)/2, so weight at least least g g /4/4
Average weight per bin = Average weight per bin = 3/43/4
Amount of weight Amount of weight packedpacked
Step 5:Step 5: We have now run out of either the We have now run out of either the
large or the small itemslarge or the small items If bins with small items remain, If bins with small items remain,
repack these items two per binrepack these items two per bin
Weight: ½ + ½ = Weight: ½ + ½ = 11
Packed weight: Packed weight: summarysummary Step 2: ½+½=1, or 3 times ½ in Step 2: ½+½=1, or 3 times ½ in
two bins, average ¾two bins, average ¾ Step 4: average ¾Step 4: average ¾ Step 5: ½+½=1Step 5: ½+½=1
Gives upper bound of 4/3! (Since Gives upper bound of 4/3! (Since OPT is at least total weight) OPT is at least total weight)
However…However…
There may be only one small item There may be only one small item left at the end of Step 5left at the end of Step 5– „„If bins with small items remain, If bins with small items remain,
repack these items repack these items two per bintwo per bin““ We may run out of small items in We may run out of small items in
Step 2, so that Step 3 is executedStep 2, so that Step 3 is executed We may run out of small items in We may run out of small items in
Step 4, so that Step 6 is executedStep 4, so that Step 6 is executed
Upper boundUpper bound
It turns out that these cases are It turns out that these cases are the most difficultthe most difficult
Proof is a number of pagesProof is a number of pages Eventually we find an upper Eventually we find an upper
bound of bound of 7/57/5 in all cases in all cases
Open questionsOpen questions
Improve this approximation ratioImprove this approximation ratio– We can give a PTAS, but this is much We can give a PTAS, but this is much
less efficient already for epsilon = 2/5less efficient already for epsilon = 2/5 Generalize this algorithm for larger kGeneralize this algorithm for larger k
– We have the upper bound of Next Fit, We have the upper bound of Next Fit, which is 2-1/k, and a PTASwhich is 2-1/k, and a PTAS
– Can we improve on Next Fit efficiently?Can we improve on Next Fit efficiently?