XML

kent logo

CO527 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

Keyword reference for assess4-1516

2015

Question 62 (2015):

Submission reference: IN5062

It seems if I run the online tests for one version of the code, I get the following results: (better score but cannot run requests-big.txt)

    Test 1: okay: ... (a bit better than SSTF, within 2 percent)
    Test 2: okay: ... (better than SSTF, by more than 2 percent)
    Test 3: okay: ... (a bit better than SSTF, within 2 percent)
    Test 4: failed at run-time
    Test 5: failed at run-time

For a different version (worse score on requests.txt but can run requests-big.txt):

Test 1: okay: ... (worse than SSTF, by more than 2 percent, same or better than FIFO)
Test 2: okay: ... (worse than SSTF, by more than 2 percent, same or better than FIFO)
Test 3: okay: ... (worse than SSTF, by more than 2 percent, same or better than FIFO)
Test 4: okay: ... (worse than SSTF, by more than 2 percent, same or better than FIFO)
Test 5: failed at run-time

Which one would you advise sticking with? If either?

Answer 62:

Probably the one you think is most correct. In terms of failed tests and other results, they're probably both somewhere between 30% and 50%, so likely I'll be looking at the code to see where the problem lies.

Keywords: assess4-1516


Question 61 (2015):

Submission reference: IN5061

In regards to Question 60 (2015), I had made those changes after I sent the question and it made no difference. I've been stuck on this for 3 hours and I don't know what to do.

    java.lang.NullPointerException
        at DiskSim.disk_readblock(DiskSim.java:821)
        at DSched.readcomplete(DSched.java:118)

I reintroduced the readqueue_size and added readqueue_num which acts like the header. I have no tails. Does this clear any of this up?

Answer 61:

It'll still be the same kind of problem. It's at this point that you need to start debugging your code: add print statements so you can see what's going into the request-queue and what's being dispatched to the disk, and also what's being looked at during the search. Some aspect of this will (should) point you in the right direction to where the problem lies (it's obviously not in the backtrace from the null-pointer exception).

Keywords: assess4-1516


Question 60 (2015):

Submission reference: IN5060

    [snip code]
    for (int i=0; i<readqueue.length; i++) {
        ...  stuff
    }

I'm trying to find the lowest block that I will use in my c-scan and for some reason this gives me a -1 and I don't think this is correct. Also I get:

    java.lang.NullPointerException
        at DiskSim.disk_readblock(DiskSim.java:821)
        at DSched.readcomplete(DSched.java:116)
        ...

I saw your earlier answer (Question 51 (2015)) about it but could there be any other cause as I have inspected my work thoroughly and nothing seems out of bounds. I even tried the -1 on a lot of things just for testing sakes and it didn't make a difference.

Answer 60:

The main problem is that you're searching through invalid requests. The length of the request-queue is fixed: at MAXREQUESTS. How many actual valid requests there are varies; specifically it's the readqueue_size variable that was in the original code. So although the array index is not out-of-bounds, it is looking at invalid requests.

Keywords: assess4-1516

Referrers: Question 61 (2015)


Question 59 (2015):

Submission reference: IN5059

I've only managed to pass the first two tests with a bubble-sort and C-scan attempt. I couldn't manage the SSTF and the bubble sort is, according to the test-rig, faster than my c-scan.

Bubble sort:

    Test 1: okay: ... (a bit better than SSTF, within 2 percent)
    Test 2: okay: ... (worse than SSTF, by more than 2 percent, same or better than FIFO)
    Test 3: failed at run-time
    Test 4: failed at run-time
    Test 5: failed at run-time

C-scan:

    Test 1: okay: ... (worse than SSTF, by more than 2 percent, same or better than FIFO)
    Test 2: okay: ... (worse than SSTF, by more than 2 percent, same or better than FIFO)
    Test 3: failed with logic errors
    Test 4: failed with logic errors
    Test 5: failed with logic errors

Which should I submit if I can't improve the c-scan before the deadline? And does the reason for test failure matter?

Answer 59:

The bubble sort is not a typical disk-scheduling algorithm in my experience. It might form part of one, but as other answers here suggest, sorting is not actually necessary: it might simplify some aspects, but at the cost of just moving complexities elsewhere. Real (actual OS) implementations might actually want to use proper sorting algorithms; because the simulator framework doesn't measure wall-clock time, run-time efficiency isn't a big issue. I'd suggest submitting the C-scan version, on the grounds that I know what that should probably be doing.

The fact three of the five tests fail is a big problem: it means there's something wrong with your code, both versions of it. The first lot are probably caused by the program throwing exceptions (test it on your own machine first, probably with the larger request file). The second lot are problems involving incorrect blocks being returned to the high-level (typically). Again, test locally.

Keywords: assess4-1516


Question 58 (2015):

Submission reference: IN5058

In reference to Question 52 (2015), I looked at the question you'd linked, my algorithm performs much better than the last version. Is it even worth using it and referencing the code? I understand how it works and how it affects the original algorithm but I'd rather not use it if I'd get into trouble for it.

Answer 58:

I don't think the code nor the understanding of how to iterate around a circular queue, nor how such a thing works, can be claimed really. It's elementary algorithm stuff (or at least it should be), but it would always be sensible to reference where you got the idea/background from if in doubt (no-one has gotten into trouble for actually referencing properly as far as I'm aware!). But for the purposes of this assessment, the objective is to perform well in a disk-scheduling simulation — how you go about it I'm less bothered about (unless I have to look at the code).

Keywords: referencing , assess4-1516


Question 57 (2015):

Submission reference: IN5057

How do I get a block's track number?

Answer 57:

As explained in the comments in the file (!) you call DiskSim.block_to_track (..)". Read and understand the code, don't just hack away at it blindly!

Keywords: assess4-1516


Question 56 (2015):

Submission reference: IN5056

Hi there, I've been trying to implement C-scan but I can't seem to get any improvements on the score compared to SSTF and FIFO.

    [snip code]

Answer 56:

This is not the right place to ask these questions: I am not a debugger :-).

Glancing at the code, the scan() method looks broken, in the sense that it's not doing the right thing. Another issue is where/how you use currentTrack.

Keywords: assess4-1516


Question 55 (2015):

Submission reference: IN5055

Hi, I'm getting this error:

    DSched.java:140: error: '.class' expected
        swap(ReadReq[],readqueue_tail,nxt);

I don't know why when my code seems right?:

    [snip code]

Answer 55:

One problem, though you haven't encountered it yet probably, is related to something in Question 53 (2015), in the mixing of circular-queue and zero-indexed (stack-based) code. However, the code you're feeding to the test-rig really doesn't compile. As suggested, make sure it at least compiles and runs on your own machine before feeding it to the test-rig. The issue is in the way you're trying to call "swap". The first parameter of "ReadReq[]" is nonsense unfortunately — that is a type not an expression. The parameter you probably want is the request-queue array itself, not its type.

Keywords: assess4-1516


Question 54 (2015):

Submission reference: IN5053

I believe my logic is completely wrong here? Can you point me in the right direction? I see a lot of code online using Math.abs(). What is the reason for this?

    public void readcomplete (int blk, BRequest req)
    {
        int[] anArray;
        anArray = new int[readstack_size];
		
        for(int i = 0; i < readstack_size ; i++)
        {
            ...  code reading "anArray[i]"
            ...  code dispatching a request
        }
    }

Answer 54:

Yes, there's something wrong here. The most obvious problem is that you're creating a new array, "anArray" then are blindly reading from it: its contents will be undefined (zero I guess). There's no need to have a separate array however: it's a matter of searching through the request queue looking for the most appropriate one. See Question 37 (2015). The other issue is that the code which dispatches a new request is actually inside the for() loop, thus it will be called for each request, and things will very quickly go badly wrong. The fact this isn't obvious is probably because of the horrible layout — indentation is used so you can see the structure of your code (and mandatory in some languages like Python, occam). Hint: embrace good code layout, it will save you a lot of grief in the long-run :-).

Keywords: assess4-1516


Question 53 (2015):

Submission reference: IN5054

Hi, with regards to Question 38 (2015) and Question 48 (2015), I still can't get the swapping right. I have spent hours just looking at it and I feel like it's just simple stuff I'm not seeing or that I have missed?

        ...  inside readcomplete():
        if (readqueue_size > 0) {
            nxtblk (blk);
            ...  dispatch request at readqueue_tail, increment tail&wrap, reduce size
        }


    public int nxtblk (int blk)
    {
        int n = SOME_LARGE_VALUE;
        ...  some code

        for (int i = 0; i < readqueue.length; i++){
            ...  some more code
            ...  something involving "(blk - readqueue[i].blk)", maybe set "n"
        }
        return n;
        swap (blk, n);
    }

    public void swap (ReadReq a[], int blk, int nearest)
    {
        ReadReq readreq = a[blk];
        a[blk] = a[nearest];
        a[nearest] = readreq;
    }

Answer 53:

There are a few things wrong with the code, that I've tried to pick out above. However, the code that implements "swap" is not one of them, which looks okay to me (although the parameters are strangely named, given what the method does — parameters should be named in the context of the method/function to which they belong [just two arbitrary array indices], not in the context of where/how that method/function is called).

One problem is how you're using the array: it's partly circular-queue (from tail to head), partly zero indexed up to (size - 1). Use one or the other (I'd suggest getting rid of the circular queue stuff, see Question 52 (2015)).

Another problem is in what you're comparing in "nxtblk": this code compares block numbers, but in the context of disk-scheduling, it should be comparing track numbers, not block numbers. See Question 37 (2015) and Question 34 (2015).

What you set "n" to here, and subsequently return, is essentially a difference in block numbers. Luckily, the code that calls this disregards the return value. You're trying to use "n" for two things I suspect: the smallest difference between the last request and something in the request-queue, and the particular index in the queue where that request is. These are two different things, thus you need two different variables: one to store the smallest distance between the last request and one of the ones in the request-queue; and another to say where in the request-queue that smallest difference comes from (initially an impossibly large value, see Question 46 (2015)).

The last issue, and probably why the swap doesn't appear to work, is that it never gets called; the code in "nxtblk" returns before it's called. But it wouldn't swap the right things anyway unfortunately: it's called with a block number "blk" and a difference in block numbers "n", that it then blindly treats as array indices: this will quickly give you an array-bounds exception. To swap the request at, say, "idx_n" with the last one in a circular-queue, you would do: "swap (readqueue, idx_n, readqueue_tail)"; and a little differently for a zero-indexed queue.

Keywords: assess4-1516

Referrers: Question 55 (2015)


Question 52 (2015):

Submission reference: IN5051

I believe I have implemented SSTF for my assignment, code here:

    ... snip code

    for(int i = readqueue_tail; i < readqueue_head; i++){
        ... code involving "readqueue[i]"
    }

I was wondering if there was any changes I could make to my code to make it more efficient on the online tests. Sorry if I wasn't allowed to paste code on here. I was just wondering why whenever I tried it was always only a bit better than SSTF on 2 of the tests.

Answer 52:

Pasting chunks of code into the anonymous Q+A is less than ideal, as it's always better if the answer is of use to more than 1 person! (usually very specific questions like "what's wrong with my code" are best taken to the lecturer/supervisor in person or via email).

The loop here is broken, in the sense that it doesn't look at all the requests, but isn't broken to the point where it tries to dispatch invalid requests. This is one reason why I suggest not to start with the FIFO code (with its head and tail indices) but start with the LIFO code (that just has a size variable tracking how many things are in the array). For how you can do this correctly with a circular-queue, see Question 28 (2011), but best not to go there if avoidable. The specific situation in your code is that readqueue_head may have wrapped-around the end of the array, and now be less-than or equal to readqueue_tail, so the test "i < readqueue_head" immediately fails, when it ought not to. Only when head > tail will this loop work correctly.

Keywords: assess4-1516

Referrers: Question 53 (2015) , Question 58 (2015)


Question 51 (2015):

Submission reference: IN5052

I am getting this error:

    java.lang.NullPointerException
        at DiskSim.disk_readblock(DiskSim.java:821)
        at DSched.readcomplete(DSched.java:113)
        at DiskSim.readready_dispatch(DiskSim.java:921)
        at DiskSim.do_sim(DiskSim.java:1159)
        at DiskSim.main(DiskSim.java:1307)

this gets highlighted in the DiskSim class: "req.time_read = timenow;". I'm not sure what the cause is, the line of code in DSched is:

    DiskSim.disk_readblock (readqueue[readqueue_size].blk, readqueue[readqueue_size].req);

Answer 51:

This error is almost certainly caused by "readqueue[readqueue_size].req" being NULL. In turn, that probably means that readqueue_size is an invalid item in the request queue. Given the way this normally works, that would be the case. I.e. if readqueue_size is 5, say, then the valid requests would be from readqueue[0] to readqueue[4] inclusive. And readqueue[5] is invalid. Thus, the correct way to refer to the last valid request if organised this way is with readqueue[readqueue_size - 1].

Keywords: assess4-1516

Referrers: Question 60 (2015)


Question 50 (2015):

Submission reference: IN5050

I've based my C-Scan implementation off the LIFO code, and it appears to be working well. However I have to make multiple jumps to high extreme values. I think this is happening because, not all the data has been put into the stack yet, is this a fair assumption or should it find a way to wait for all the data?

Answer 50:

That's probably expected. It will depend, of course, on the request file fed to the program. You can look at the two provided, or (even better!) create your own to test this hypothesis. As for waiting for requests, that's a hard one in the sense that it's usually impossible to tell what the best strategy will be: deal with the request(s) you already have, with a possibly large overhead in moving the read/write heads, or wait in the hope some closer requests come in. Of course, by the time you've waited, and no new requests have arrived, it would have been better to have made the other choice. But such is the unpredictable nature (non-determinacy) of this sort of thing. Whilst it's somewhat outside the scope of the assessment, a real OS might employ some form of heuristic, based on past behaviour or how many requests are outstanding. In the context of the assessment, however, don't try and wait — if you have a request to service, service it. I don't think enough of the simulator framework is exposed (in public methods/etc.) to support it.

Keywords: assess4-1516 , disk-scheduling


Question 49 (2015):

Submission reference: IN5049

I have implemented the temporary storage method you described in Question 42 (2015) and have got my code for SSTF working to the point where there is only one logical error, which is always on read queue 0. I assume that this is something to do with the first block being sent having no previous block to compare to but am unsure how to fix that or if it is even a correct assumption. hopefully you can shed some light:

highlevel_didread(): read queue 0 already done at time 1095 (block 2048)
finished at time 3367 with 1 pending queues
disk spent 31 idle, 2864 seeking to track, 472 reading 97 blocks
*** had 1 logical errors!

Answer 49:

That assumption seems reasonable. In the general case, if the request-queue is empty and new request comes in, readcomplete() will be called with an invalid block number and null request to indicate this. That might be the cause of the error, or it could be something else — if the request-queue got corrupted, that error could be an outcome. Basically you're calling highlevel_didread() with something that it never asked for, or asked for and got previously, so the problem could be in the other half where it's deciding what to dispatch to the disk next, and is dispatching something it should not be (i.e. an old/invalid request).

Keywords: assess4-1516


Question 48 (2015):

Submission reference: IN5048

I asked Question 38 (2015) and since then have done some improvement to my code but am still getting errors so am still completely off track with trying to swap at the tail:

    public void readcomplete (int blk, BRequest req)

        ... some code

        nxtblk(blk);	

        int temp = blk;
        blk = int nearest.nxtblk;
        nearest.nxtblk = temp;

Elsewhere in the code:

		
    for (int i = 0; i < readqueue.length; i++) {

Answer 48:

Regarding swapping, see Question 42 (2015). The type of T here would be ReadReq, since that's the type of the array: thus, you are trying to swap ReadReq objects around inside the array (or references to those objects), not integer block numbers (this will lead to all sorts of inconsistencies).

The other potential problem is that your code seems to be based on the FIFO code, in that it still has head+tail pointers and modulo arithmetic. The loop you have above is therefore probably broken, as it inspects all elements in that array, regardless of whether they're valid or invalid requests. Solution: get rid of all the head/tail stuff and stick with something that's more like the LIFO version (just a counter for how many things in the array are valid).

Keywords: assess4-1516

Referrers: Question 53 (2015)


Question 47 (2015):

Submission reference: IN5046

Does the difficulty of implementing the listed algorithms scale with their efficiency?

Answer 47:

A bit perhaps, but not significantly. From the steady stream of people I've seen today, most of the issues are related to actually writing code, not understanding the particulars of the algorithm. It's probably true that things like the elevator, C-scan, etc. are more complicated to implement than SSTF, but not massively (i.e. elevator/C-scan are SSTF but in one direction only).

Keywords: assess4-1516


Question 46 (2015):

Submission reference: IN5045

I'm using a large integer (int s_diff = 99999999;) inside my SSTF implementation to compare tracks between blocks, thereby finding the nearest block. I was wondering if this might be an issue as the disk scheduler might not be able to use such large integers? If so, is there a way around this?

Answer 46:

My suggestion would be to pick an appropriate value: no distance between any two tracks is going to be more than the number of tracks on the disk, so sensible to use that as an impossibly high starting value (i.e. DiskSim.NTRACKS).

Keywords: assess4-1516

Referrers: Question 53 (2015)


Question 44 (2015):

Submission reference: IN5044

Hiya, I have come across an error that I don't completely understand;

    highlevel_didread() : readqueue 7 already done at time 1099 (block 1),

is here any way you could possibly give a hint as to what's going wrong? Thank you!

Answer 44:

This is a case of something in your code calling highlevel_didread() with something invalid (block 1 in this instance). Various possible causes, but a typical one would be sending a request to the disk that has already been serviced previously; when it comes back into readcomplete(), the code there will probably just hand it upwards (as a completed read-request) but the problem is likely to do with when it got requested from the disk — i.e. your request-queue has gone bad.

Keywords: assess4-1516


Question 43 (2015):

Submission reference: IN5040

    highlevel_didread(): read queue 2 got unexpected block 1048500
    ...

There are more errors but you get the gist. My current system uses a method I have called update. It takes the parameter of the last block used by the system. The idea is that I store my last block in a variable after the first running of the read complete method. The next time the read complete method is ran it would run my update method which would update some global variables.

    [snip code]

Answer 43:

See Question 42 (2015). Might be better to come and see me with your code however and I'll see if I can give you some pointers.

Keywords: assess4-1516


Question 42 (2015):

Submission reference: IN5043

In reference to Question 38 (2015), I am also attempting to implement an SSTF solution however I am unsure if this method of creating a temporary is what you are looking for:

    [snip some stuff]
    temp1 = readqueue[readqueue_tail].blk;
    temp2 = readqueue[readqueue_tail].req;
    readqueue_tail = i;
    readqueue[i].blk = temp1;
    readqueue[i].req = temp2;

Answer 42:

This will almost certainly not work, for various reasons. You have over-complicated this somewhat however: think about what the code is doing, and what the variable values are (e.g. primitive types or object references). For any array whose elements are of type T, you can swap them with a trivial bit of code (this is something that you should be familiar with, as it's pretty fundamental stuff):

    /* swap elements 'i1' and 'i2' of 'a' */
    void swappy (T a[], int i1, int i2)
    {
        T t = a[i1];

        a[i1] = a[i2];
        a[i2] = t;
    }

Note that this doesn't know, nor does it need to know, anything about the structure of type T. It could be an object reference, a primitive type, doesn't matter.

Keywords: assess4-1516

Referrers: Question 43 (2015) , Question 48 (2015) , Question 49 (2015)


Question 41 (2015):

Submission reference: IN5041

Can we use code directly from CO518 terminals i.e. the project with different sort implementations?

Answer 41:

You can use whatever sorting algorithms you like! As long as it's clear where the code came from (if it came from elsewhere, even if your own on another module). But these things may not be wrapped up in classes: you only submit a single file, DSched.java, so any sorting functionality must be contained within the methods there. No inner classes doing sorts please! But given that most sort algorithms can sit in a single method, that shouldn't be an issue. See also Question 39 (2015).

Keywords: assess4-1516


Question 40 (2015):

Submission reference: IN5042

Slight add on to a previous question, i missed out that i have a swap that doesn't seem to do anything. I've been staring at my code for a while now thinking it all makes sense. Is there a reason my swap code doesn't work?

    public void swap (int i, int j) {
	int temp = i;
	i = j;
	j = temp;
    }

Answer 40:

This code successfully swaps the two integer parameters, i and j. It doesn't swap anything else (e.g. stuff inside the request queue). If you look at that method in isolation, how could it? (given it has no references to the request-queue).

What you're trying to swap here are not i and j, but the request-queue (array) entries at the ith and jth indices.

Keywords: assess4-1516


Question 39 (2015):

Submission reference: IN5039

Could you tell me if I'm the right track please, this is what I have so far:

    [snip something that looks like quicksort with bits of the existing DSched code in it]

Answer 39:

Short answer, no :(. It looks like you tried to blend quicksort with the existing code that's already there. This isn't going to work. But unless you're trying to be real-time efficient (which isn't necessary for this assessment) sorting isn't needed. What's required is, more or less, searching through the set of queued requests looking for the best/appropriate.

Keywords: assess4-1516

Referrers: Question 41 (2015)


Question 38 (2015):

Submission reference: IN5038

I'm trying to do the SSTF implementation, but I can't seem to rap my head around swapping a particular request with the tail. Can you point me in the right direction?

    ... in readcomplete() somewhere
    int val = nxtblk (blk);
    readqueue_tail = val;

"nxtblk" is something that returns the next best block number.

Answer 38:

There are two things wrong here. The first is a confusion about what units are involved. As your "nxtblk" returns a particular block number, assigning it to something which is an array index is nonsense unfortunately. If your "nxtblk" returned the index in the read-queue of the next best block, then the assignment to "readqueue_tail" would at least make some sense. But this is the second problem: this is not the way to swap two things in an array. It can't be done in a single operation in Java — you'll need a temporary. What your assignment does is change the value of "readqueue_tail", not change the contents of the array at position "readqueue_tail".

Keywords: assess4-1516

Referrers: Question 42 (2015) , Question 48 (2015) , Question 53 (2015)


Question 37 (2015):

Submission reference: IN5036

Could you please tell me if my thought process is correct for SSTF:

You would have two variables (i and j) and you would compare the tail to the last block read and find to find out the track distance and store it in 'i'. Then you would decrement size and increase the tail and then compare that to the last block read and store it in 'i' then you would compare i and j and process the smallest one.

Answer 37:

Not quite — there are two separate things here, and they should stay separate. One of them is about finding the next best request to dispatch to the disk (where "best" depends on the scheduling algorithm, SSTF or otherwise). The other is about removing that request from the queue and sending it to the low-level disk (with disk_readblock()).

For SSTF (shortest seek-time first), where seek-time mostly involves the time required to move the read/write heads between tracks, the next best request will be the one that is closest to the last block read. Thus, unless your request-queue is sorted, this will involve searching through it. For that you need a few things: the track number of the last block read (i.e. where the read-write heads are now); a loop (and a loop-variable) to iterate through all the requests in the queue, looking at each one in turn; and some variable to tell you which the best (closest) request so far is. Algorithmically this is a bounded linear search (the concept of which should not be unfamiliar). Once you've found the best, you can then request it from the disk (taking some care of how it is removed from the queue, if it was in the middle of the array).

Keywords: assess4-1516

Referrers: Question 53 (2015) , Question 54 (2015)


Question 36 (2015):

Submission reference: IN5035

    drive busy, cannot read block 1 at this time!
    drive busy, cannot read block 2049 at this time!
    ...
    highlevel_didread(): read queue 3 got unexpected block 2457601
    ...

Why does this happen?

Answer 36:

The drive-busy errors probably mean that your code is trying to dispatch a read-request whilst one is already ongoing. Remember that the "readcomplete()" method, where the dispatch happens in the given code, is called when the previously requested block has been read successfully, or when the disk is idle and is ready to accept a new request. But only one new request should be dispatched in response to this. The second kind of error is likely an artefact of the first; this is the high-level code (e.g. an application, or OS file-system) complaining that it got back a block that it hadn't requested (or was otherwise not expecting).

Keywords: assess4-1516


Question 34 (2015):

Submission reference: IN5023

Assuming the following:

    Queue = 95, 180, 34, 119, 11, 123, 62, 64 
    Start = 50

For the C-Look implementation; there is a type of "jump" that doesn't count the head movement.

So, it first goes to 34, 11, then it just "jumps" to 180, then goes down again. I am unsure how to implement this "jump" as it doesn't seem to count towards the time. I thought of maybe since the disk is round, it just overlaps, but I'm not sure how to implement that one.

Answer 34:

You don't say whether the numbers you're referring to are tracks or blocks. That makes a difference. Moving between tracks takes time (depending on the number of tracks). Thus, when looking at scheduling algorithms, track numbers are what you would want to consider first. From that perspective, the "Queue" you have, and some of the text, makes sense — in that some requests are processed from track 34, then track 11, then (since nothing smaller exists in the queue) back to the top at track 180. Code that behaves like this will take the appropriate amount of time in the simulator (unless I made a horrid bug somewhere, but I think it's good!). If the numbers are block numbers, then the logic of the ordering is wrong: the way that blocks on the disk map onto tracks, sectors and heads is essentially unknown (obviously not in this case, since you can look at the code for yourself). The scheduling algorithm itself shouldn't actually care about block numbers, beyond using the various DiskSim functions to get the track, sector or head of where the block physically resides. But when thinking about blocks, rather than tracks, then there is overlap: in that underneath the physical read-write heads of the disk (see diagram in the slides) there will be multiple blocks, all with different block numbers.

Keywords: assess4-1516

Referrers: Question 53 (2015)


Question 33 (2015):

Submission reference: IN5034

Having worked SSTF into the FIFO code successfully, I wanted to take a try at implementing it for LIFO. Problem is, I don't see an easy way to make DiskSim use the LIFO class instead. DiskSim seems to call on the same method names inside LIFO as in DSched so I tried renaming LIFO to DSched but to no avail.

Is there an easier way to do this? Thanks.

Answer 33:

Not really.. Renaming files is about the best you can do in this case: in theory you could have some abstract class for DSched then specialise it through inheritance/overriding, but that's over-engineering and would make the submission / automated-testing more complex than it needs to be. The "DSched-lifo.java" file included would need to be renamed to "DSched.java" to have it compile sensibly (as the class name is the same, i.e. "DSched").

Keywords: assess4-1516


Question 32 (2015):

Submission reference: IN5032

I was just wondering if we can change the blockread method, to change how the queue is read.

Answer 32:

That's fine (changing the blockread method), but this is called for new requests entering the queue, rather than reading requests out of it (which typically happens in readcomplete as a result of finishing the previous read).

Keywords: assess4-1516


Question 31 (2015):

Submission reference: IN5029

I feel like I've got the the point where I'm making very little progress / no progress where more often than not I am just going in circles. For the purpose of the submission should I remove all redundant code for tidiness e.g. my C-Scan attempt(s) or should I leave it in there in case for you to look at?

Answer 31:

Feel free to leave it in there, but make it an obviously commented-out block with some explanation of why it's there. If I do look at the code, some marks might be available depending on how close to a working implementation the commented-out code is.

Keywords: assess4-1516


Question 30 (2015):

Submission reference: IN5025

For the fourth assessment, what kind of grade could I expect to receive with the following results:

'requests.txt' -> score: 684, 0 pending queues
'big-requests.txt' -> score 771, 31 pending queues

For some reason the bigger text file wont read all queues, even though the same code is running and working for the smaller text file. I cant seem to figure this out.

Answer 30:

The fact there are pending queues in the larger test means that something is quite broken :-(. Look hard at your code for the case when the request queue is full (i.e. has MAXREQUESTS things in it). Many problems of this kind stem from trying to use the circular-queue (FIFO) code, and the issue of iterating from the tail to the head (or vice-versa); better to start with the simpler LIFO code. In the FIFO code, 'head' == 'tail' in two scenarios: the queue is empty and the queue is full. If you need to be able to tell the difference, you need another variable (e.g. counting how many things are in the queue, which is what the LIFO code does with its readstack_size variable).

To get an idea of how it fares under assessment, feed it to the automated checker thing (link on Moodle).

Keywords: assess4-1516


Question 29 (2015):

Submission reference: IN5024

Can we remove the comments from DSched, or would you rather they stay there?

Answer 29:

You should leave comments as you deem appropriate. Feel free to remove the folds however (comments involving the triple-braces). Generally any method should have some leading comment (or JavaDoc if you prefer) to say, generally, what it does, what its parameters are and what it returns. Anything subtle or structural should probably also have some comment in the code. Good commenting is good practice generally, but that doesn't mean you have to be excessive nor comment the obvious.

Keywords: assess4-1516


Question 28 (2015):

Submission reference: IN5027

My attempt at C-SCAN is horribly slow compared to my SSTF racking up a score of 2950 for a regular request and 13300 for the bigger request. I've gone over my implementation and to me it seems logical.

[snip code]

Answer 28:

For the benefit of other readers (and the poster) this looks like a piece of code that tries to build on the FIFO implementation, that has within it the circular queue (using the "head" and "tail" indices). The way you're iterating over this is probably broken, in the sense that the "while()" loop searching through the requests will not operate in the right way. See the answer to Question 28 (2011) for some more information. Solution is to skip the whole head/tail FIFO version, and start from the LIFO version (which is much simpler, but performs horribly) — or retrofit those changes onto your code.

Keywords: assess4-1516


Question 27 (2015):

Submission reference: IN5026

I am getting these results back from the auto-tester you put together:

Test 1: okay: ... (worse than SSTF, by more than 2 percent, same or better than FIFO)
Test 2: okay: ... (better than SSTF, by more than 2 percent)
Test 3: okay: ... (worse than SSTF, by more than 2 percent, same or better than FIFO)
Test 4: failed with leftovers
Test 5: failed with leftovers

What kind of a grade could I expect back if this particular DSched solution was submitted? Thanks!

Answer 27:

For tests 1 and 3, say 50% (+/- 10%), for test 2 say 70% (+/- 10%), but 0 for tests 4 and 5. This would give a final mark of 34% (+/- 6%), very approximately. In this category, it's probably one I'd look at the code to see if it was a reasonable attempt (and give it up to 50% potentially). The fact two of five tests fail means the maximum possible would be 60%.

Keywords: assess4-1516


Question 26 (2015):

Submission reference: IN5022

Do tests 4 and 5 in the automated checker use a large data input file like requests-big.txt? My code is failing these tests ("failed at run-time"), and I thought it might be that, but I fixed that bug (when I run the code on my machine with requests-big.txt it works fine, if a bit in-efficient). I was wondering if I'd only fixed the code for a file size that is still quite small compared to the ones in tests 4 and 5?

Answer 26:

I'm not going to reveal too many details about the individual tests, but they are larger than the first three. As strongly suggested in the assessment description, invent your own datasets and try those! (don't rely just on the example I provided you with).

Keywords: assess4-1516


Question 25 (2015):

Submission reference: IN5021

Let's say there's track 100 on head 1, and track 200 on head 2.

If you submitted track 100 to be read, then you would submit track 200 (located in head 2) would this add to the time a lot more than if track 200 was on the same head as track 100?

Answer 25:

There seems to be some terminology confusion here! Heads are the electronic read/write gubbins on the end of the actuator arm that moves laterally across the disk. Thus, for any given track [0 .. N-1] there are heads [0 .. H-1] (assuming H is the number of heads and N is the number of tracks). Thus you have physical locations such as track 1 head 1, track 1 head 2, track 2 head 1, track 2 head 2, etc. (putting sectors aside, which are the locations around the disk). Different tracks are not on different heads. Look at the slides I made for a rough idea of how tracks (aka cylinders), heads and sectors are related.

Keywords: disk-scheduling , assess4-1516


Question 24 (2015):

Submission reference: IN5017

Exception in thread "main" java.lang.NoClassDefFoundError: DiskSim (wrong name: dist/DiskSim)

I am getting this error what does it mean?

Answer 24:

Probably means that you're trying to run the code from the wrong directory. You need to run it from the same directory that all those files are in, not the parent directory (which I guess is where you're trying to run it from based on that error).

Keywords: assess4-1516


Question 22 (2015):

Submission reference: IN5015

Hi Fred, in the disk scheduler are are allowed to remove the requests which have been read from the read-queue, or should these stay there even after being read which would mean the largest size of our read-queue would get smaller each time a set of requests are made?

Also, am I correct that we are aiming for the smallest possible score? What would be considered a good score to get (70% +), I am currently getting around 1300?

Answer 22:

Not sure I understand the first bit entirely: yes, once a request has been serviced, you remove it from the queue — that's what the existing LIFO and FIFO code do (okay, they don't scrub out the entry in the array/queue, but effectively do as it'll be overwritten with fresh requests coming in). But if you didn't do that, the request queue would just get larger and larger, not smaller!

For score comparison, feed it to the automated checker. You'd be aiming for "better than SSTF" or similar wording in all tests for a good score (where good is at least 65%+ probably). But in value terms, yes, you're trying to minimise the score value — as it represents time, the smaller the better.

Keywords: assess4-1516 , disk-scheduling


Question 21 (2015):

Submission reference: IN5014

Hi, someone told me that we cannot use for loops but I thought we could since it isn't an add-on to Java, like ArrayLists etc. are. Are they wrong or am I? Thanks.

Answer 21:

You wouldn't get too far without 'for' loops! (I guess you could do it all with 'while' or recursion though). But plain-old "for (init; cond; iter) { ... }" loops are absolutely fine. What I did not want people to use are 'foreach' loops (nor the high-level 'Iterator' related things that go alongside them).

Keywords: assess4-1516


Question 19 (2015):

Submission reference: IN5011

For the Disk Scheduling assessment, I notice that DiskSim.MAXREQUESTS is capped at 256. Are we allowed to create a read-queue array with a length of more than this?

Say for example: readqueue = new ReadReq[2000];

Is this allowed or do we need to keep that default at readqueue = new ReadReq[DiskSim.MAXREQUESTS];

Answer 19:

You can make it larger, but it's fairly pointless: if you look at the other bits of code, though perhaps non-obvious, you'll see that no more than MAXREQUESTS requests are ever dispatched concurrently.

Keywords: assess4-1516


Question 18 (2015):

Submission reference: IN5010

Hi, are we allowed to implement our own data structure and not stick with the array, i.e. a linked-list or a hash table?

Answer 18:

That's fine, but you must not use any of the Java API stuff. E.g. if you want a linked-list, do it yourself, not with the "LinkedList<Blah>" generics stuff. Similar with a hash-table, though I can't see any advantage of that in this case (and it'd be painful to implement in Java regardless).

Keywords: disk-scheduling , assess4-1516


Question 17 (2015):

Submission reference: IN5009

For the disk scheduling assessment, I'm struggling to work how how to specify the request file on raptor to test my algorithm.

I have tried: "java DiskSim -f requests-big.txt", however this does not work.

Could you please help?

Answer 17:

You'll have to be a bit more descriptive: does not work in what specific way? Feel free to pop along to my [Fred's] office and I'll have a quick look. (silly question maybe, did you run "make" to actually compile the Java sources first?).

Keywords: assess4-1516


Question 16 (2015):

Submission reference: IN5002

Question for C-Look algorithm.

[snip]

Answer 16:

See Question 14 (2015)

Keywords: assess4-1516


Question 15 (2015):

Submission reference: IN5008

Hi, I've seen this error on the anonymous page however I still am not quite sure what is causing this. This error only occurs when I run the request-big.txt, running the smaller one is fine.

I had a thought that maybe the read-queue is limited to a set size and loops around causing my code to read all values from the tail when it resets back to position 0 upto DiskSim.MAXREQUESTS however all the old values in the readqueue may not be getting removed and just being read again?

raptor$ java DiskSim --file requests-big.txt
highlevel_didread(): read queue 34 got unexpected block 6784807
highlevel_didread(): read queue 19 got unexpected block 431139
[snip]

Answer 15:

Yes, something is going wrong when your request queue is full. Essentially this is a bug that you need to understand and fix (debugging!). I'm happy for you to pop along to my office and I can see if I can give you some pointers as to where the error lies (without giving too much away).

Keywords: assess4-1516


Question 14 (2015):

Submission reference: IN5001

Question about the seek time.

A disk arm must first find the right head ,then the right track and then get the right block.

For most disks as the inward heads are typically smaller than the outermost. The current implementation does keep track of head and tracks and sectors however there is no method/function to determine the direction of the arm. E.g. go inward or go outward? Since the most important thing here is timing don't we need a function to determine the direction?

I am referring to the C-Look algorithm so direction function is very important I think.

Answer 14:

Don't overcomplicate things. You don't need a function for this — why not just a variable? (rather, a field/attribute added to the DSched class).

Keywords: assess4-1516

Referrers: Question 16 (2015)


Question 13 (2015):

Submission reference: IN5003

Hi, I've not seen this syntax before, could you explain what the ".blk" does in "readqueue[readqueue_head].blk = blk;" please?

Answer 13:

It's exactly the same as it is elsewhere in Java — accessing a field/attribute/data/method (whatever your preferred nomenclature) in an object. Thus "blk" is just some public field of the relevant object. The way you've been taught would probably be to set this using a mutator, but in this sort of code, that just complicates things unnecessarily (and introduces unwanted overhead). Bear in mind that C would be the more normal language to program this stuff in: I'm only using Java because it's the language you know.

Keywords: assess4-1516


Question 12 (2015):

Submission reference: IN5005

For assessment 4, are we explicitly bound to implementing a pre-existing algorithm (c-scan for example), or are we allowed to invent our own.

Basically is the aim of the assessment to implement something specific, or as long as we improve the efficiency of the provided code we pass?

Answer 12:

The criteria for marking are clearly described in the assessment description. Any algorithm, provided it improves things, will pass. For a decent mark, however, you should be aiming to improve on SSTF at least (as that has some caveats that are explained in the slide-deck, and elsewhere).

Keywords: assess4-1516 , disk-scheduling


Question 11 (2015):

Submission reference: IN4999

Hi, I think I have a working c-look implementation with the following results:

[snip program output]

Is this what would be expected with a c-look algorithm?

Answer 11:

Depends on the dataset and your particular implementation. I'd suggest feeding your code to the automated checker here: https://www.cs.kent.ac.uk/studash/co527.php and see what that says! (should be better than SSTF in most, if not all, cases).

Keywords: assess4-1516


Question 10 (2015):

Submission reference: IN5000

Hi, I've just gone to use the CO527 disk-scheduling online automated test and I'm getting this error:

Sorry, you are not allowed to submit files masquerading as a student.

Answer 10:

Please try it again! (I think I've fixed it, but since I'm not a student, I cannot actually test it as as student).

Keywords: assess4-1516


Question 9 (2015):

Submission reference: IN4998

Can we use java.lang.Integer?

Answer 9:

No. (the obvious question being, why would you need or want to?)

Keywords: assess4-1516


Question 8 (2015):

Submission reference: IN4997

Can we use "Math.abs()" in the disk scheduler assessment?

Answer 8:

Yes, that's fine (but only on the grounds that it's trivial and can be written inline). E.g.:

    int av = Math.abs (v);

Could just as easily (and probably more efficiently) be written:

    int av = (v < 0) ? -v : v;

Keywords: disk-scheduling , assess4-1516

Referrers: Question 45 (2015)


Question 5 (2015):

Submission reference: IN4966

Question about the C-Look algorithm: Where does the read/write head actually start? Is it on a random track and then goes down to the nearest end and jumps and continues, or does it start as a preset position?

Answer 5:

The source code is available, look for yourself! (initially the head will be on track 0).

Keywords: assess4-1516


Question 4 (2015):

Submission reference: IN4957

Looking at the disk scheduling assessment; am I right in thinking that we only just have to edit the readcomplete method of the DSched class (and add others if we need them)?

Answer 4:

There are many possible ways of implementing this — you can probably get away with just editing this method, but I'd recommend changes elsewhere if you're starting from the FIFO version of the code (else you've got all this circular queue stuff in there that's redundant).

Keywords: disk-scheduling , assess4-1516

Valid CSS!

Valid XHTML 1.0!

Maintained by Fred Barnes, last modified Wed May 25 15:07:20 2016