Presentation is loading. Please wait.

Presentation is loading. Please wait.

Improved results for a memory allocation problem Rob van Stee University of Karlsruhe Germany Leah Epstein University of Haifa Israel WADS 2007 WAOA 2007.

Similar presentations


Presentation on theme: "Improved results for a memory allocation problem Rob van Stee University of Karlsruhe Germany Leah Epstein University of Haifa Israel WADS 2007 WAOA 2007."— Presentation transcript:

1 Improved results for a memory allocation problem Rob van Stee University of Karlsruhe Germany Leah Epstein University of Haifa Israel WADS 2007 WAOA 2007

2 Background Allocate memory to parallel processors Allocate memory to parallel processors Goals: Goals: –Each processor has sufficient memory –Not too much memory is wasted

3 Background Problem: memory requirement may vary over time Problem: memory requirement may vary over time If each processor can access only one memory, this is inefficient If each processor can access only one memory, this is inefficient If all processors share a single memory, there is heavy contention If all processors share a single memory, there is heavy contention

4 Suggested model Chung et al. [SPAA 2004] suggest a new architecture Chung et al. [SPAA 2004] suggest a new architecture Each memory may be accessed by at most two processors Each memory may be accessed by at most two processors This avoids the mentioned problems This avoids the mentioned problems

5 Bin packing They abstract this problem as a bin packing problem They abstract this problem as a bin packing problem Bins = memories Bins = memories Items = memory requirements of processors Items = memory requirements of processors Thus, items may be larger than 1 Thus, items may be larger than 1

6 Bin packing Items may be split and distributed among more than one bin Items may be split and distributed among more than one bin Condition: each bin contains at most two parts of items Condition: each bin contains at most two parts of items Corresponds to: each memory may be accessed by at most two processors Corresponds to: each memory may be accessed by at most two processors We also consider the model where each bin may contain k parts of items We also consider the model where each bin may contain k parts of items

7 Bin packing Processor 1 2 3 4 5 Requirement Bins Assignment 1,2 3,4 2 3,4,5 1

8 Notes There may be many bins which are not full There may be many bins which are not full An item may be split more than once An item may be split more than once No upper bound on how often each item is split No upper bound on how often each item is split

9 Results Chung et al. [SPAA 2004]: Chung et al. [SPAA 2004]: –(k=2) NP-hardness –(k=2) 3/2-approximation Epstein & vS [WADS 2007]: Epstein & vS [WADS 2007]: –(k=2) 7/5-approximation –For general k: Next Fit is (2-1/k)-approximation Next Fit is (2-1/k)-approximation NP-hardness in the strong sense NP-hardness in the strong sense

10 Results Epstein & vS [WAOA 2007]: A polynomial time approximation scheme (PTAS) for every (constant) k A polynomial time approximation scheme (PTAS) for every (constant) k –For every constant  >0, a polynomial time algorithm that uses at most 1+  times the minimal number of bins –at most  OPT additional bins of size 1

11 Results Epstein & vS [WAOA 2007]: A dual approximation scheme for every (constant) k A dual approximation scheme for every (constant) k –For every constant  >0, a polynomial time algorithm that uses bins of size 1+  –Larger bins, but no additional bins

12 Next Fit in this context If current bin contains k parts of items or is fulll, open a new bin If current bin contains k parts of items or is fulll, open a new bin Put as much as possible of the current item in the current bin Put as much as possible of the current item in the current bin Open additional bin(s) if needed (for large items) Open additional bin(s) if needed (for large items)

13 Next Fit: lower bound One item of size Mk-1 One item of size Mk-1 –Next Fit uses Mk-1 bins M (k-1)k very small items M (k-1)k very small items –Next Fit puts k items in one bin, uses M (k-1) bins Mk -1 M (k -1)

14 Next Fit: lower bound Optimal solution needs only Mk bins Optimal solution needs only Mk bins Ratio: (M (2k-1)-1) /Mk 2 – 1/k Ratio: (M (2k-1)-1) /Mk 2 – 1/k Mk -1 M (k -1) Mk

15 Next Fit: upper bound Block = set of full bins, followed by a bin with k items Block = set of full bins, followed by a bin with k items Each bin >1 in a block was opened because the previous one was full Each bin >1 in a block was opened because the previous one was full

16 Weights Weight of item with size s =  s  /k Weight of item with size s =  s  /k There are at least  s  parts of item with size s in any packing There are at least  s  parts of item with size s in any packing OPT is at least the total weight of all the items OPT is at least the total weight of all the items

17 Next Fit: upper bound Consider last bin in a block (not the last block) Consider last bin in a block (not the last block) Has k items, so at least k -1 items of weight 1/k (these items are not split!) Has k items, so at least k -1 items of weight 1/k (these items are not split!) Block has 1 bin, then k such items Block has 1 bin, then k such items Else, consider all items in block except the k -1 last items Else, consider all items in block except the k -1 last items

18 Next Fit: upper bound S = all items in block except the k -1 last items S = all items in block except the k -1 last items How many items are in S ? Unknown! How many items are in S ? Unknown! What is the minimal weight of S ? What is the minimal weight of S ? Weight =, minimized for single item Weight =, minimized for single item

19 Next Fit: upper bound S = all items in block except the k -1 last items S = all items in block except the k -1 last items For block of size b, total size of items in S is strictly more than b -1 For block of size b, total size of items in S is strictly more than b -1 Total weight is then at least b /k Total weight is then at least b /k Weight in block at least b /k +(k -1)/k Weight in block at least b /k +(k -1)/k Note: also true for block of size 1 Note: also true for block of size 1

20 The last block Only one bin: weight at least 1/k (has at least one item) Only one bin: weight at least 1/k (has at least one item) b >1 bins: weight at least b /k b >1 bins: weight at least b /k Let size of block i be b i, then Next Fit uses bins Let size of block i be b i, then Next Fit uses bins We know that OPT is at least the total weight We know that OPT is at least the total weight

21 Next Fit: upper bound Let m be the amount of blocks Let m be the amount of blocks Also, OPT > NF – m (in each block, at most one bin is not completely full) Also, OPT > NF – m (in each block, at most one bin is not completely full)

22 Next Fit: upper bound Combining this we find

23 23 This talk We only discuss the algorithms for k=2 We only discuss the algorithms for k=2 General properties General properties PTAS PTAS Dual PTAS Dual PTAS

24 Representation of solutions A solution can be seen as a graph A solution can be seen as a graph Vertices = items Vertices = items An edge between two items = An edge between two items = Parts of these two items share a bin Parts of these two items share a bin – A loop means that a bin contains just one part of an item We can assume a forest (with loops) We can assume a forest (with loops) –Cycles can be easily removed without changing the cost (Chung et al.,2004).

25 Example Items:

26 Graph

27 Removal of cycle

28 Additional properties There exists an optimal packing forest where all items of size in (0,1/2] are leaves or singletons There exists an optimal packing forest where all items of size in (0,1/2] are leaves or singletons If the forest representation is minimal (no tree can be split) then a packing is implied from the tree If the forest representation is minimal (no tree can be split) then a packing is implied from the tree –Can be done iteratively –Singletons are packed into separate bins –A leaf is packed with a maximum amount of its neighbor, and removed from the forest

29 (Different) example 1.5 0.4 0.2 1 0.9 0.2 0.3

30 Packing process 0.8 0.4 0.6 1 0.9 0.3 0.1 0.2

31 PTAS for k=2 We would like to use standard methods such as We would like to use standard methods such as –Linear grouping and rounding –Enumeration of patterns But But –Patterns are trees –Items sizes are not bounded from above

32 New tricks Optimal packing is adapted in order to make it possible to imitate it Optimal packing is adapted in order to make it possible to imitate it Trees are “truncated” Trees are “truncated” –Partitioned into smaller trees Large items are truncated Large items are truncated –Partitioned into several items that are still large, but bounded The last two adaptations increase the number of bins by a factor of 1+  The last two adaptations increase the number of bins by a factor of 1+ 

33 Trying all trees Type of a tree is (j,E) Type of a tree is (j,E) –j is number of edges –E is set of j-1 edges (so that it is a tree) Pattern = type plus vector of length j Pattern = type plus vector of length j –Element i in the vector indicates group of node i Constant number of patterns Constant number of patterns Only question: how many of each? Only question: how many of each?

34 Dual PTAS for k=2 (briefly) We use an integer parameter K, based on . We use an integer parameter K, based on . Items can be rounded down to a sizes of the form i/K Items can be rounded down to a sizes of the form i/K We round some non-zero sizes into zero! We round some non-zero sizes into zero! By scaling, we get items of integer sizes, and a bin size K By scaling, we get items of integer sizes, and a bin size K

35 Cutting There is no reason to cut items at non-integer point There is no reason to cut items at non-integer point For each item size (at most K), we define cutting patterns For each item size (at most K), we define cutting patterns We “guess” how to cut the input items We “guess” how to cut the input items –Using enumeration

36 Finding a solution We use a layered graph to find an optimal packing for each option We use a layered graph to find an optimal packing for each option –If the cutting was applied, the problem becomes much easier –However, we did not cut items larger than the bin size –We cut a piece off each one of them, but do not decide on all cutting points The best (smallest number of bins) option is chosen The best (smallest number of bins) option is chosen Increasing items back to original sizes increases bins slightly Increasing items back to original sizes increases bins slightly

37 Open problems PTAS, dual PTAS for non-constant k PTAS, dual PTAS for non-constant k (FPTAS or dual FPTAS are most likely impossible since the problem is strongly NP-hard for every constant value of k) (FPTAS or dual FPTAS are most likely impossible since the problem is strongly NP-hard for every constant value of k) Generalize 7/5-approximation for larger k Generalize 7/5-approximation for larger k

38 7/5-approximation We show an approximation algorithm for k=2 (at most two parts of items per bin allowed) We show an approximation algorithm for k=2 (at most two parts of items per bin allowed) First it sorts the items First it sorts the items Then it packs them, starting with the most difficult ones: size between ½ and 1 Then it packs them, starting with the most difficult ones: size between ½ and 1 We use Next Fit as a subroutine We use Next Fit as a subroutine

39 Step 1: Sorting Items of size at most ½ are small Items of size at most ½ are small –Sort them in order of increasing size Items larger than 1 are large Items larger than 1 are large –Sort them in order of decreasing size Other items are medium-sized Other items are medium-sized –Sort them in order of decreasing size –We pack these items first

40 Step 2: medium-sized items Pack medium-sized items one by one: Pack medium-sized items one by one: –If current item fits in one bin with the smallest unpacked small item, pack them together –Else, pack current item together with two largest unpacked small items in two bins

41 Step 3: all small items are packed We do this until we run out of either the medium-sized or the small items We do this until we run out of either the medium-sized or the small items If all small items are packed, use Next Fit on rest, start with medium-sized items If all small items are packed, use Next Fit on rest, start with medium-sized items

42 Step 4: some small items remain Pack each small item in its own bin Pack each small item in its own bin Pack large items into these bins using Next Fit Pack large items into these bins using Next Fit Still use ordering from before: Still use ordering from before: –Largest large items first –Smallest small items first

43 Step 5: small items left We have now run out of either the large or the small items We have now run out of either the large or the small items If bins with small items remain, repack these items two per bin If bins with small items remain, repack these items two per bin

44 Step 6: large items left Pack remaining large items using Next Fit Pack remaining large items using Next Fit

45 Lower bound for this algorithm 4N small items of size 2/N 4N small items of size 2/N 2N medium-sized items of size 1-1/N 2N medium-sized items of size 1-1/N 3N medium-sized items of size 1-2/N 3N medium-sized items of size 1-2/N Algorithm starts with largest medium- sized items Algorithm starts with largest medium- sized items

46 Lower bound for this algorithm Step 2: pack medium-sized items one by one: –If current item fits in one bin with the smallest unpacked small item, pack them together –Else, pack current item together with two largest unpacked small items in two bins

47 Lower bound for this algorithm 4N small items of size 2/N 4N small items of size 2/N 2N medium-sized items of size 1-1/N 2N medium-sized items of size 1-1/N 3N medium-sized items of size 1-2/N 3N medium-sized items of size 1-2/N Algorithm creates 4N bins with half an item of size 1-1/N and one small item Algorithm creates 4N bins with half an item of size 1-1/N and one small item Rest is packed using Next Fit Rest is packed using Next Fit 3N(1-2/N) = 3N-6 bins for other items 3N(1-2/N) = 3N-6 bins for other items

48 The optimal solution 3N small items in separate bins 3N small items in separate bins –In these bins, the items of size 1-2/N can be packed N small items split into two bins N small items split into two bins –Here the items of size 1-1/N can be packed Requires 5N bins for all items Requires 5N bins for all items Ratio 7/5 for large N Ratio 7/5 for large N

49 Upper bound We use the same weight definition as before: weight of item with size s is We use the same weight definition as before: weight of item with size s is We know that OPT is at least the total weight We know that OPT is at least the total weight How much weight do we pack in a bin? How much weight do we pack in a bin?

50 Amount of weight packed 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 smallest unpacked small item, pack them together. Weight ½+½ = 1 –Else, pack current item together with two largest unpacked small items in two bins. Three items of weight ½ in two bins: ¾

51 Amount of weight packed Step 3: If all small items are packed, use Next Fit on rest, start with medium-sized items If all small items are packed, use Next Fit on rest, start with medium-sized items We assume many small items exist We assume many small items exist Then, this step does not occur Then, this step does not occur

52 Amount of weight packed Step 4: Pack each small item in its own bin Pack each small item in its own bin Pack large items into these bins using Next Fit Pack large items into these bins using Next Fit Still use ordering from before: Still use ordering from before: –Largest large items first –Smallest small items first

53 Amount of weight packed Consider a large item which is packed into g bins Consider a large item which is packed into g bins It is packed together with g small items (total weight g /2) It is packed together with g small items (total weight g /2) The large item has size strictly more than (g -1)/2, so weight at least g /4 The large item has size strictly more than (g -1)/2, so weight at least g /4 Average weight per bin = 3/4 Average weight per bin = 3/4

54 Amount of weight packed Step 5: We have now run out of either the large or the small items We have now run out of either the large or the small items If bins with small items remain, repack these items two per bin If bins with small items remain, repack these items two per bin Weight: ½ + ½ = 1 Weight: ½ + ½ = 1

55 Packed weight: summary Step 2: ½+½=1, or 3 times ½ in two bins, average ¾ Step 2: ½+½=1, or 3 times ½ in two bins, average ¾ Step 4: average ¾ Step 4: average ¾ Step 5: ½+½=1 Step 5: ½+½=1 Gives upper bound of 4/3! (Since OPT is at least total weight)

56 However… There may be only one small item left at the end of Step 5 There may be only one small item left at the end of Step 5 –„If bins with small items remain, repack these items two per bin“ We may run out of small items in Step 2, so that Step 3 is executed We may run out of small items in Step 2, so that Step 3 is executed We may run out of small items in Step 4, so that Step 6 is executed We may run out of small items in Step 4, so that Step 6 is executed

57 Upper bound It turns out that these cases are the most difficult It turns out that these cases are the most difficult Proof is a number of pages Proof is a number of pages Eventually we find an upper bound of 7/5 in all cases Eventually we find an upper bound of 7/5 in all cases

58 Open questions Improve this approximation ratio Improve this approximation ratio –We can give a PTAS, but this is much less efficient already for epsilon = 2/5 Generalize this algorithm for larger k Generalize this algorithm for larger k –We have the upper bound of Next Fit, which is 2-1/k, and a PTAS –Can we improve on Next Fit efficiently?

59 Thank you!


Download ppt "Improved results for a memory allocation problem Rob van Stee University of Karlsruhe Germany Leah Epstein University of Haifa Israel WADS 2007 WAOA 2007."

Similar presentations


Ads by Google