Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[In C++] Theoretically, the disk seek time is proportional to the square root of

ID: 3723195 • Letter: #

Question

[In C++]

Theoretically, the disk seek time is proportional to the square root of the distance the /O head travels from its current position to some destination position: TntTxo. A more accurate seek time model is the following exponential model t c(x-1) lsrsr Quantum Atlas III parameters: xmax-8057 cyl, C-9. I GB, N-7200 rpm, x*= 1686, t-I,5455ms, c-0.3197 ms, r-0.3868 1-r All operating systems provide optimizing algorithms that minimize the movement of the I/O mechanism. The simplest such algorithm is the shortest seek time first (SSTF) where the I/O mechanism always serves the request that is closest to the current position of the I/O head. If we have only one request in the disk queue then there is no chance to optimize the movement of the mechanism and the mechanism moves in a way that makes the average distance equal to the 1/3 of the maximum distance. However, if the disk queue contains n>1 service requests, then it is possible to optimize (i.e. to minimize movements of the TO mechanism). The optimization algorithm is activated before each seek operation. This means that in the case of high load disk performance is better than in the case of low load. In other words, disk is a load-dependent server In this homework we want to study the average seek time for Quantum Atlas III as a function of the disk queue length. This is a strictly decreasing function Sd(Q), where Q is the number of jobs in the disk queue. Write a simulator program for computing Sd(Q) as follows 1. Make and array dq of Q components that represents the disk queue 2. Initialize dq with Q uniformly distributed random numbers that represent cylinders where the I/O head has to move Generate an initial position of the I/O mechanism as a random value X. In each simulation step move the head to the closest position. After the head moves to the position dq[k] the new position will be X-dq[k], and the component dq[k] has to be replaced by a new random value. Compute the seek distance and the seek time Compute the average seek distance and the average seek time for at least 10000 disk accesses Plot the average seek distance and the average seek time for Q-1,2,...,20 3. 4. 5. 6.

Explanation / Answer

#include<iostream>
#include<stdlib.h>
using namespace std;

// Class sstfScheduling definition
class sstfScheduling
{
// Data member to store data
int position[100];
int pos, queueSize;
// Prototype of private member function
int findShortDistance(int);
public:
// Prototype of public member function
void accept();
void totalHeadMovement();
};// End of class

// Function to accept data
void sstfScheduling::accept()
{
// Accepts data
cout<<"Enter the current position of head ";
cin>>pos;
cout<<"Enter the size of queue : ";
cin>>queueSize;
cout<<"Enter the request for tracks : ";
// Loops till queue size and accepts the movement positions
for(int c = 0; c < queueSize; c++)
cin>>position[c];
}// End of function

// Function to search shortest path and returns the index position
int sstfScheduling::findShortDistance(int number)
{
int minimum = 99999, index, pos;
// Loops till queue size
for(int c = 0; c < queueSize; c++)
{
// Checks if the value is not -1
if(position[c] != -1)
{
// Subtracts the array c index position data from the number and stores its absolute value
pos = abs(number - position[c]);
// Checks if the current minimum is greater than the position
if(minimum > pos)
{
// Update the minimum with position value
minimum = pos;
// Store the index position
index = c;
}// End of inner if condition
}// End of outer if condition
}// End of for loop
// Returns the index position
return index;
}// End of function

// Function to calculate total head movement
void sstfScheduling::totalHeadMovement()
{
int number = pos, movement = 0, index;
// Loops till queue size
for(int c = 0; c < queueSize; c++)
{
// Calls the function to find shortest movement and stores its index position
index = findShortDistance(number);
// Adds the absolute value of the movement
movement += abs(number - position[index]);
// Stores the position value at index position in number
number = position[index];
// Sets the position index position to -1 for traversed
position[index] = -1;
}// End of for loop
// Displays the head movement
cout<<"Total head movements : "<<movement;

cout<<" Average head movements: "<<(movement / queueSize);
}// End of function

// main function definition
int main()
{
// Creates an object of the class sstfScheduling
sstfScheduling ss;
// Calls the function to accept data
ss.accept();
// Calls the function to display total head movement
ss.totalHeadMovement();
return 0;
}// End of function

Sample Output:

Enter the current position of head 50
Enter the size of queue : 6
Enter the request for tracks : 12
88
45
23
78
8
Total head movements : 122

Average head movements: 20

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote