hw2.docxHomework #2
Please complete the homework problems on the following page using a separate piece of paper. Note that this is an individual assignment and all work must be your own. Be sure to show your work when appropriate. This assignment is due in lab
1. [3] Remove 5 from the following AVL tree; draw the results:
2. [3] Insert the value "8" into the following AVL tree; draw the result:
3. Given the following AVL tree:
A. [3] Add 45 to the tree.
B. [3] Ignoring all previous tasks, add values 9 and 8 to the tree.
C. [3] Ignoring all previous tasks, remove values 10 and 30 from the tree.
D. [3] Ignoring all previous tasks, remove 80 and 100 from the tree.
4. Binary Heaps (i.e. Priority Queues) Starting with an empty binary min heap, show the following. Be sure to clearly label each diagram.
A. [3] The final state of the heap, in tree form, after adding in the values: 5, 4, 3, 6, 7, 8, 10, 2, 9, 1
B. [3] The state of the heap, in tree form, after two Dequeue() operations
C. [2] The final, array-based version of the heap
0
1
2
3
4
5
6
7
8
9
results.csvJob NameStarting TickEnding TickDurationJ2220J11109J44128J66148J1010144J99178J881911J772013J552520J333734
PA4.docxProgramming Assignment #4
Your organization has purchased a new parallel computer (or "cluster") which has several processors. Your task is to design and implement a simple shortest-job-first scheduler that allows multiple users to access the cluster at the same time, as per the following specification:
The scheduler performs all required functions at regular intervals, often called "ticks." During each tick, the scheduler must take into consideration several pieces of information:
1. Are there jobs in our input file that contains a list of jobs to be run? If so, add that job to our list of current jobs. Note that our jobs file contains one job per line in the following format: "<JOB_NAME> <CPUS_REQUIRED> <DURATION>". Only one job may be added to the jobs queue during any given tick. If a job has a name of "NULL," skip that job for the current tick (i.e. no jobs will be added during this tick). If a job requires more CPUs than the cluster contains, you should output an error and terminate execution of the program.
2. Are there jobs in the jobs queue? If so, find the job with the shortest duration. Are there enough CPU resources for this job to run? If so, begin execution (i.e. add to the active jobs queue). If, after adding the previous job, are there enough resources to run the next job in the queuejob? If so, go back to the beginning of step #2. Stop adding to the list of active jobs when there are not enough CPU resources available for the job to execute. Try again in the future.
3. For each executing job (note that there may be multiple concurrent jobs), perform one tick's worth of work. After, check to see if the job is done executing. If complete, remove from the active jobs queue and allocate the job's CPU resources back into.
Science 7 - LAND and SEA BREEZE and its Characteristics
hw2.docxHomework #2Please complete the homework problems on th.docx
1. hw2.docxHomework #2
Please complete the homework problems on the following page
using a separate piece of paper. Note that this is an individual
assignment and all work must be your own. Be sure to show
your work when appropriate. This assignment is due in lab
1. [3] Remove 5 from the following AVL tree; draw the results:
2. [3] Insert the value "8" into the following AVL tree; draw the
result:
3. Given the following AVL tree:
A. [3] Add 45 to the tree.
B. [3] Ignoring all previous tasks, add values 9 and 8 to the
tree.
C. [3] Ignoring all previous tasks, remove values 10 and 30
from the tree.
D. [3] Ignoring all previous tasks, remove 80 and 100 from the
tree.
4. Binary Heaps (i.e. Priority Queues) Starting with an empty
binary min heap, show the following. Be sure to clearly label
each diagram.
A. [3] The final state of the heap, in tree form, after adding in
the values: 5, 4, 3, 6, 7, 8, 10, 2, 9, 1
B. [3] The state of the heap, in tree form, after two Dequeue()
operations
2. C. [2] The final, array-based version of the heap
0
1
2
3
4
5
6
7
8
9
results.csvJob NameStarting TickEnding
TickDurationJ2220J11109J44128J66148J1010144J99178J88191
1J772013J552520J333734
PA4.docxProgramming Assignment #4
Your organization has purchased a new parallel computer (or
"cluster") which has several processors. Your task is to design
and implement a simple shortest-job-first scheduler that allows
multiple users to access the cluster at the same time, as per the
3. following specification:
The scheduler performs all required functions at regular
intervals, often called "ticks." During each tick, the scheduler
must take into consideration several pieces of information:
1. Are there jobs in our input file that contains a list of jobs to
be run? If so, add that job to our list of current jobs. Note that
our jobs file contains one job per line in the following format:
"<JOB_NAME> <CPUS_REQUIRED> <DURATION>". Only
one job may be added to the jobs queue during any given tick.
If a job has a name of "NULL," skip that job for the current tick
(i.e. no jobs will be added during this tick). If a job requires
more CPUs than the cluster contains, you should output an error
and terminate execution of the program.
2. Are there jobs in the jobs queue? If so, find the job with the
shortest duration. Are there enough CPU resources for this job
to run? If so, begin execution (i.e. add to the active jobs
queue). If, after adding the previous job, are there enough
resources to run the next job in the queuejob? If so, go back to
the beginning of step #2. Stop adding to the list of active jobs
when there are not enough CPU resources available for the job
to execute. Try again in the future.
3. For each executing job (note that there may be multiple
concurrent jobs), perform one tick's worth of work. After,
check to see if the job is done executing. If complete, remove
from the active jobs queue and allocate the job's CPU resources
back into the resource pool. Note that it is possible for a job
with a duration of 1 to be scheduled, executed, and completed
during the same tick.
Upon completion, your program should produce a CSV file
called "result.csv" that documents the point at which each job
enters the jobs queue, finishes its execution, and the difference
between these two values.
Sample Jobs File
Below is a sample jobs file that you can use for testing:
4. 12
J1 8 10
J2 2 1
J3 12 12
J4 10 2
J5 5 8
J6 4 2
J7 4 6
J8 2 5
J9 4 3
J10 6 2
Sample Output
Included with this document is the file "output.txt" that contains
the output of my program running the sample jobs list with a
CPU count of 12 (as specified in the first line of the input file).
Also included is the generated CSV file.
Header Comment, and Formatting
1. Be sure to modify the file header comment at the top of your
script to indicate your name, student ID, completion time, and
the names of any individuals that you collaborated with on the
assignment.
2. Remember to follow the basic coding style guide. A basic
list of rules is included with this document.
Deliverables
You must upload your program and reflection as a ZIP file
through Canvas. Remember that your submission must either
contain a CodeBlocks or Visual Studio project file!Reflection
Essay
In addition to the programming tasks listed above, your
submission must include an essay that reflects on your
experiences with this homework. This essay must be at least
350 words long. Note that the focus of this paper should be on
5. your reflection, not on structure (e.g. introductory paragraph,
conclusion, etc.). The essay is graded on content (i.e. it shows
deep though) rather than syntax (e.g. spelling) and structure.
Below are some prompts that can be used to get you thinking.
Feel free to use these or to make up your own.
· Describe a particular struggle that you overcame when
working on this programming assignment.
· Conversely, describe an issue with your assignment that you
were unable to resolve.
· Provide advice to a future student on how he or she might
succeed on this assignment.
1. Describe the most fun aspect of the assignment.
1. Describe the most challenging aspect of the assignment.
1. Describe the most difficult aspect of the assignment to
understand.
1. Provide any suggestions for improving the assignment in the
future.
Grading
Your grade will be determined as follows:
· [10] Your program uses a priority queue to model the
scheduler.
· Your program uses good Object Oriented Programming
principles. As evidence of this, your program uses classes to
represent:
· [5] A given job
· [5] A CPU within the cluster
· [5] The cluster of CPUs itself
· [10] Your reflection essay satisfies the requirements as
specified earlier in this document.
· [5] Your code is well documented and generally easy to read.
· [60] Does the code compile and run successfully on my test
cases? Does the generated CSV file appear to be correct?
output.txt
6. *** Tick: 1 ***
Processing jobs file...
The next job in the list is: J1.
Adding job to jobs queue...
Processing jobs queue...
Current number of scheduled jobs: 1.
Adding highest priority job:
J1 8 10
Jobs queue is empty.
Running active jobs...
*** Tick: 2 ***
Processing jobs file...
7. The next job in the list is: J2.
Adding job to jobs queue...
Processing jobs queue...
Current number of scheduled jobs: 1.
Adding highest priority job:
J2 2 1
Jobs queue is empty.
Running active jobs...
Job "J2" is complete. Freeing up resources.
*** Tick: 3 ***
Processing jobs file...
The next job in the list is: J3.
Adding job to jobs queue...
8. Processing jobs queue...
Current number of scheduled jobs: 1.
Not enough free CPUs (requested: 12, actual: 4). Waiting for
resources...
Running active jobs...
*** Tick: 4 ***
Processing jobs file...
The next job in the list is: J4.
Adding job to jobs queue...
Processing jobs queue...
Current number of scheduled jobs: 2.
Not enough free CPUs (requested: 10, actual: 4). Waiting for
resources...
Running active jobs...
9. *** Tick: 5 ***
Processing jobs file...
The next job in the list is: J5.
Adding job to jobs queue...
Processing jobs queue...
Current number of scheduled jobs: 3.
Not enough free CPUs (requested: 10, actual: 4). Waiting for
resources...
Running active jobs...
*** Tick: 6 ***
Processing jobs file...
The next job in the list is: J6.
Adding job to jobs queue...
10. Processing jobs queue...
Current number of scheduled jobs: 4.
Not enough free CPUs (requested: 10, actual: 4). Waiting for
resources...
Running active jobs...
*** Tick: 7 ***
Processing jobs file...
The next job in the list is: J7.
Adding job to jobs queue...
Processing jobs queue...
Current number of scheduled jobs: 5.
Not enough free CPUs (requested: 10, actual: 4). Waiting for
resources...
11. Running active jobs...
*** Tick: 8 ***
Processing jobs file...
The next job in the list is: J8.
Adding job to jobs queue...
Processing jobs queue...
Current number of scheduled jobs: 6.
Not enough free CPUs (requested: 10, actual: 4). Waiting for
resources...
Running active jobs...
*** Tick: 9 ***
Processing jobs file...
12. The next job in the list is: J9.
Adding job to jobs queue...
Processing jobs queue...
Current number of scheduled jobs: 7.
Not enough free CPUs (requested: 10, actual: 4). Waiting for
resources...
Running active jobs...
*** Tick: 10 ***
Processing jobs file...
The next job in the list is: J10.
Adding job to jobs queue...
Processing jobs queue...
Current number of scheduled jobs: 8.
Not enough free CPUs (requested: 10, actual: 4). Waiting for
13. resources...
Running active jobs...
Job "J1" is complete. Freeing up resources.
*** Tick: 11 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 8.
Adding highest priority job:
J4 10 2
Not enough free CPUs (requested: 4, actual: 2). Waiting for
resources...
Running active jobs...
14. *** Tick: 12 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 7.
Not enough free CPUs (requested: 4, actual: 2). Waiting for
resources...
Running active jobs...
Job "J4" is complete. Freeing up resources.
*** Tick: 13 ***
Processing jobs file...
There are no more jobs in the jobs file.
15. Processing jobs queue...
Current number of scheduled jobs: 7.
Adding highest priority job:
J6 4 2
Adding highest priority job:
J10 6 2
Not enough free CPUs (requested: 4, actual: 2). Waiting for
resources...
Running active jobs...
*** Tick: 14 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 5.
Not enough free CPUs (requested: 4, actual: 2). Waiting for
16. resources...
Running active jobs...
Job "J6" is complete. Freeing up resources.
Job "J10" is complete. Freeing up resources.
*** Tick: 15 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 5.
Adding highest priority job:
J9 4 3
Adding highest priority job:
J8 2 5
Adding highest priority job:
17. J7 4 6
Not enough free CPUs (requested: 5, actual: 2). Waiting for
resources...
Running active jobs...
*** Tick: 16 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 2.
Not enough free CPUs (requested: 5, actual: 2). Waiting for
resources...
Running active jobs...
18. *** Tick: 17 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 2.
Not enough free CPUs (requested: 5, actual: 2). Waiting for
resources...
Running active jobs...
Job "J9" is complete. Freeing up resources.
*** Tick: 18 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 2.
19. Adding highest priority job:
J5 5 8
Not enough free CPUs (requested: 12, actual: 1). Waiting for
resources...
Running active jobs...
*** Tick: 19 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 1.
Not enough free CPUs (requested: 12, actual: 1). Waiting for
resources...
Running active jobs...
Job "J8" is complete. Freeing up resources.
20. *** Tick: 20 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 1.
Not enough free CPUs (requested: 12, actual: 3). Waiting for
resources...
Running active jobs...
Job "J7" is complete. Freeing up resources.
*** Tick: 21 ***
Processing jobs file...
There are no more jobs in the jobs file.
21. Processing jobs queue...
Current number of scheduled jobs: 1.
Not enough free CPUs (requested: 12, actual: 7). Waiting for
resources...
Running active jobs...
*** Tick: 22 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 1.
Not enough free CPUs (requested: 12, actual: 7). Waiting for
resources...
Running active jobs...
22. *** Tick: 23 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 1.
Not enough free CPUs (requested: 12, actual: 7). Waiting for
resources...
Running active jobs...
*** Tick: 24 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
23. Current number of scheduled jobs: 1.
Not enough free CPUs (requested: 12, actual: 7). Waiting for
resources...
Running active jobs...
*** Tick: 25 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 1.
Not enough free CPUs (requested: 12, actual: 7). Waiting for
resources...
Running active jobs...
Job "J5" is complete. Freeing up resources.
24. *** Tick: 26 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 1.
Adding highest priority job:
J3 12 12
Jobs queue is empty.
Running active jobs...
*** Tick: 27 ***
Processing jobs file...
There are no more jobs in the jobs file.
25. Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
Running active jobs...
*** Tick: 28 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
Running active jobs...
26. *** Tick: 29 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
Running active jobs...
*** Tick: 30 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
27. Running active jobs...
*** Tick: 31 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
Running active jobs...
*** Tick: 32 ***
Processing jobs file...
There are no more jobs in the jobs file.
28. Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
Running active jobs...
*** Tick: 33 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
Running active jobs...
29. *** Tick: 34 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
Running active jobs...
*** Tick: 35 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 0.
30. Jobs queue is empty.
Running active jobs...
*** Tick: 36 ***
Processing jobs file...
There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
Running active jobs...
*** Tick: 37 ***
Processing jobs file...
31. There are no more jobs in the jobs file.
Processing jobs queue...
Current number of scheduled jobs: 0.
Jobs queue is empty.
Running active jobs...
Job "J3" is complete. Freeing up resources.
jobs.txt
12
J1 8 10
J2 2 1
J3 12 12
J4 10 2
J5 5 8
J6 4 2
J7 4 6