Menu

Number of blocks in the sort

2011-06-17
2013-04-25
  • Jasbir Dhaliwal

    Jasbir Dhaliwal - 2011-06-17

    Hi there,

    I am confused with this "You need to keep a constant number of blocks in internal memory, at least 3 IIRC. If your file fits entirely into memory less blocks may suffice (just need enough blocks to keep the whole file). "

    I am a newbie in this. Reading the tutorial, it says that the default block size is "2*1024*1024" = 2MB. What I understand by this is that assuming your file is 10MB, the number of blocks should be 10/2 which gives you 5. However, if the size of your file is 9MB, you wouldn't get a constant block 9/2=4.5.

    Please let me know if I have confused things.

    Regards,
    Jasbir

     
  • Jasbir Dhaliwal

    Jasbir Dhaliwal - 2011-06-17

    Actually, what I mean is that for 9/2=4.5, I need to put the block size of 5MB.

     
  • Andreas Beckmann

    Sorry, i was not very precise.

    Your input (usually a vector) to sort() is organized in blocks of size B (a template parameter of the vector defaulting to 2 MB) and partial blocks at begin/end are "rounded up" to full blocks.
    If you give memory M to the sorter, it can store M/B (rounded down) blocks in internal memory. If input conists of not more than M/B blocks, a single pass is sufficient for sorting and only the necessary amount of memory to store the full input will be used.
    In case you need more than one pass (at least for some inputs - thats why you started to use an external sorter in the beginning), you need at least 3 blocks in internal memory to make progress. Having more memory available is usually a good idea - you don't want to do more than two sorting passes.

    Andreas

     
  • Nobody/Anonymous

    Thanks very much.

     

Log in to post a comment.