LAB 1 - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

LAB 1

Description:

Java Intro...Arrays. This may help with Banker algorithm (proj ... java Counter sheep cattle goats. In what order do they print? When did TreeSet get sorted? ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 32
Provided by: rh2
Category:
Tags: lab | java

less

Transcript and Presenter's Notes

Title: LAB 1


1
LAB 1
  • Java Intro (Morning)
  • Projects 1-4 (Afternoon)

2
Java Intro...Primitives
  • write a program that counts to ten
  • public static void main(String as)
  • lock it in, because thats where it all starts.
  • at most one per class...so how many programs
    can we have?
  • truth in advertising...class X X.java
  • primitives (only eight!) wraparounds
  • byte, short, int, long (only use int)
  • float, double (only use double)
  • boolean, char (unicode)
  • Steve style
  • p / sop
  • Hungarian notation

3
PrimitivesSummary
Primitive
Range
Bytes
byte short int long boolean char float double
-27 27-1 -215 215-1 -231
231-1 -263 263-1 false, true
0 216-1 /- 3.40282347E38 /-1.79769
313486231570E308
-128 to 127 -32768... /- 2 billion 18
zeroes... Unicode
4
Java Intro...Arrays
  • This may help with Banker algorithm (proj 3)
  • Exact (change) program
  • totally static...no OO constructs.
  • Though array instance is technically an object
    (new)
  • 2D array of int, aai
  • Array of boolean, abFinished
  • But why do we need separate arrays for boolean
    and int?
  • But do we need abFinished? could we have
    implemented differently?

5
Java Intro....Objects
  • static v. non-static
  • Memory for statics is assigned during class load
    (once)
  • Memory for instance variables assigned during
    each new
  • Write Counter.java
  • static blocks to indicate class load
  • Counter itself has a String sName as well as int
    iCount
  • How much memory?
  • zero, one, twenty instances
  • Steve style
  • toString() using notation.
  • iSerials iSerial

6
Java Intro...Javadoc
  • API doc
  • three frames packages, classes, and main
    window.
  • tree view for inheritance
  • Standout classes (what packages?)
  • Object, String, StringBuffer, Integer
  • SortedSet, SortedMap, Vector
  • is there a common ancestor?
  • Iterator, Comparable
  • Socket, File, Thread
  • JPanel, JFrame, JPanel, JButton, JTextArea
  • Tooldoc
  • javac, java, javadoc, jdb
  • Bookmark it!

7
Collections...Vector SortedSet
  • Revise Counter
  • Make it implement Comparable
  • Sort by string name, then by counter
  • store all instances using two collections
  • static SortedSet
  • static Vector
  • Play with arrays and Random
  • java Counter sheep cattle goats
  • In what order do they print? When did TreeSet
    get sorted?
  • Change constructor to add twice to each
    collection
  • whats the effect on Vector?
  • whats the effect on SortedSet?
  • Vector can have null doesnt require Comparable.

8
Collections...SortedMap
  • Run BunchaInts
  • Difference from SortedSet
  • put(key,val) get(key) v. add(key)
  • Keys must be Comparable/unique
  • values need not be Comparable
  • Indeed, may be null / redundant.
  • Integer Count wrapper class.
  • primitive int can serve as Object reference!
  • Time Permitting
  • What if main() had used SortedSet vice Vector?
  • Modify main() for command line args convert
    Strings to ints.
  • Its all about managing complexity, efficiently.

9
Now for Projects 1-4....
  • Scripts
  • env.bat
  • g.bat
  • exp.bat
  • scripts.bat
  • run.bat
  • run each program

10
Getting Around....Scripts
  • Four unrelated mini-projects
  • 1st three are 10 each
  • last is 5 (as are remaining three Lab2
    projects)
  • Structure
  • OPSYS/devel/opsys.
  • Package alias Name Project / Concept
  • opsys.bb gob bounded buffer 1. Producer/Consumer
  • opsys.sched.cpu gosc Simulator 2. ST (CPU)
    Scheduler
  • opsys.deadlock god banker algorithm 3. Deadlock
    avoidance
  • opsys.fea gof Finite Element Analysis 4.
    Threads

11
1. Bounded Buffer
  • Purpose
  • Give you a feel for busy waiting
  • See tradeoffs in design efficiency v. memory

12
BB...Walkthrough
  • scripts edit run.bat
  • gob
  • javac .java
  • Code walkthrough
  • Note Default States are
  • Widget.BYTES -1
  • SharedVariables.BSIZE 128
  • Monitor.SLEEP_MILLIS 1000

13
BB...What to Do (1)
  • Vary Shared.BSIZE 2, 4, 8, ....512
  • Collect/plot the following
  • widgets produced as f(BSIZE)
  • busy waits as f(BSIZE)
  • Explain graphs in plain English
  • Set buffer size to 1...what happens? why?
  • How are results affected by running two instances
    of test concurrently (in different windows?)
  • Reset BSIZE to default

14
BB...What to Do (2)
  • Vary Widget.BYTES 1, 0... 1Meg (break it)
  • plot widgets produced as f(SIZE)
  • plot waits as f(SIZE)
  • plot TaskManager mem usage as f(SIZE)
  • Explain each graph in plain English
  • Add the following code to Consumer
  • static Vector v new Vector()
  • Modify doSomethingWith() with v.add(w). How does
    this affect TaskManager mem usage?
  • Restore to defaults.

15
BB...What to Do (3)
  • Vary Monitor.SLEEP_MILLIS
  • 1000, 100, 10, 1
  • plot widgets produced as f(SLEEP_MILLIS)
  • Speculate on any trends.

16
BB...What To Do (4)
  • Change run.bat to invoke BB3 vice BB1.
  • This uses Semaphore construct.
  • No more lBusyWaits
  • Introduce Semaphore.java
  • Redo items on (1)
  • Compare all results with Project BB1. Which
    project was more productive? Why?
  • No need to play with Widget.BYTES and
    Monitor.SLEEP_MILLIS

17
2. Simulator...CPU Scheduler
  • scripts edit run.bat
  • gosc
  • javac .java
  • run
  • each SimSet does a bunch of SimTrends
  • each line in SimTrend is a Sim (or avg)
  • each trend yields different outputs that can be
    plotted and discussed. E.g. Avg Wait Time.

18
Doing a set with the following st sched
opsys.sched.STSchedSteve2 pager
opsys.sched.PagerDummy varying CPUs in use C P
SLP B Qu FRs work time cpu thrpt turn
await pf 1 16 100 4 16 64 5120 5347
0.958 2.992 3027 1310 0 2 16 100 4 16 64
5120 3842 0.666 4.164 1829 106 0 4 16
100 4 16 64 5120 3821 0.335 4.187 1748
22 0 8 16 100 4 16 64 5120 3821 0.167
4.187 1746 20 0 varying
quantum ... varying processes ... varying sleep
between submit ... varying burstiness ... varying
frames on system ... OVERALL RESULTS st sched
opsys.sched.STSchedSteve2 pager
opsys.sched.PagerDummy C P SLP B Qu FRs
work time cpu thrpt turn await pf 1 17 133
4 20 72 5589 6089 0.822 2.938 2966 1265
0
Sim Trend...
SimSet
19
Simulator...SimSets and Trends
  • each SimSet combines a set of algorithms
  • e.g. one short term scheduler, with one pager,
    with one disk scheduling algorithm.
  • your main point of interface for getting results.
  • each SimSet does a bunch of SimTrends
  • each line in SimTrend is a Sim (or avg)
  • each trend yields varies some input, such that
    critical outputs (like await) change and can be
    plotted / discussed.

20
Simulator...Inputs
  • C of CPUs
  • P of Processes
  • SLP Sleep time between submission of processes
    (Long Term Scheduler)
  • B Burstiness (higher is burstier)
  • Qu Quantum duration
  • FRs of frames in system

21
Simulator...Nice to Haves
  • work total CPU clock cycles used for useful
    work.
  • time total CPU time required to run whole
    simulation.
  • pf page faults (lab 2 issue...ignore)

22
Simulator...Outputs
  • cpu utilization work/time
  • thrpt processes completed per unit time
  • turn avg turnaround time for all procs
  • await avg wait time for all procs

23
Simulator...Nominal Sim
  • Very first Sim line is repeated in each trend
  • CPUs 1
  • Processes 16
  • SLP 100
  • B 4 (every 4th proc CPU bound)
  • Qu 16
  • FRs 64
  • This will be useful when comparing one SimSet to
    another...more useful than avg.

24
Simulator... TODO (1)
  • copy STSchedFIFO as
  • STSchedLRU
  • STSchedIdeal
  • for SimTrends which vary C, P, SLP, B
  • pick the one output which varies most
  • plot it as a function of chaning input for each
    of the three STSched algorithms
  • explain the trends in the graphs
  • ALSO explain how the other three outputs change

25
Simulator... TODO (2)
  • for the nominal sim, extract into a table the
    four outputs for each of three algorithms
  • Which algorithm performed best? Why?
  • turn in source code

26
3. Bankers Algorithm
  • Purpose
  • Implement the algorithm on p. 259
  • I give you
  • a test harness (Extreme Programming pitch...)
  • your Arrays Collections introductions
  • a framework with an empty safety algorithm
  • Your job is to fill in the safety algorithm such
    that all test cases work, as well as any ones you
    or I might add to the set

27
Banker...Walkthrough
  • scripts edit run.bat
  • god
  • javac .java
  • Code walkthrough

28
Banker...What to Do
  • Provide an implementation of Banker interface
  • You may modify BankerImpl if you want
  • Do have to throw new UnsafeException(safety
    algorithm) when appropriate.
  • Make a main() which invokes BankerTest
  • ensure both test cases work
  • Hand in source code print of output

29
4. Threads...FEA
  • scripts edit run.bat
  • gof
  • javac .java
  • find . TODO .java
  • code review
  • Vary LIMIT and MILLIS as follows
  • LIMIT 10, 1, 0.1, 0.01
  • MILLIS 100, 10, 1
  • collect Iters and Final Temp for each

30
FEM...(1)
  • Hand in completed Plate.java ElementThread.java
  • For MILLIS100, LIMIT10, provide snapshot of
    last temp printout before System.exit()
  • Two graphs
  • Iterations as f(LIMIT)
  • three lines MILLIS 100, 10, 1
  • Final temp as f(LIMIT)
  • three lines MILLIS 100, 10, 1

31
FEM...Todo (2)
  • Producer / Consumer had a clear delineation of
    what variables were shared among threads. Are
    there any variables being shared in this FEA
    example? If so, explain which variables are
    shared, how, and by which other threads.
  • Producer / Consumer wasted a slot in a buffer in
    order to ensure mutual exclusion. Why isn't
    there any such locking mechanism in this example?
    Is that dangerous? Does it mean we get bad
    answers?
  • What's the relationship between LIMIT and
    iterations?
  • And again, between Limit and final temperature?
  • Can you say that a particular table of data
    (MILLIS100, 10, or 1) was better behaved than
    the others? If so, speculate on why
Write a Comment
User Comments (0)
About PowerShow.com