Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science An Introduction and Some Advanced Concepts Too! Prof. Paul Sivilotti Dept. of Computer & Info. Science The Ohio State University

Similar presentations


Presentation on theme: "Computer Science An Introduction and Some Advanced Concepts Too! Prof. Paul Sivilotti Dept. of Computer & Info. Science The Ohio State University"— Presentation transcript:

1 Computer Science An Introduction and Some Advanced Concepts Too! Prof. Paul Sivilotti Dept. of Computer & Info. Science The Ohio State University paolo@cis.ohio-state.edu

2 Computers Are All Around

3 The 1 st Computer Scientist Ada Byron King, Countess of Lovelace 1815-1852

4 Computers and Programs Computer: a device that “computes” Takes inputs, produces output Becoming smaller, faster, cheaper Program: sequence of instructions How to produce the output Must be specific Becoming larger and more complicated!

5 Now We’re Cooking! Computer = chef Program = recipe 1. Preheat oven to 350 o 2. Sift together flour, cocoa, baking powder, salt 3. Melt 1/2c butter and 1lb chocolate 4. Stir 1/2c sugar into chocolate mixture 5. Sir in 3 large eggs 6. Stir in dry ingredients 7. Add chocolate chunks 8. Form into rounded balls (1T each) 9. Bake 10 min

6 Computing Choc. Cookies 2 tbsp cocoa 1 tsp baking pwdr 3 eggs 1 ¼ c flour ¾ tsp salt ½ c butter ½ c sugar 1 lb chocolate 36 chocolate chip cookies Sequence of instructions

7 Software Engineering A software engineer builds programs Design, develop, test, modify, maintain Program requirements? Most important: ingredients and final dish! (Also: time, space) For the same requirements, many solutions Good recipes are correct Good recipes are easy to understand Good recipes are easy to change

8 Module I: Write a Program Robots on a grid Stack of index cards Each is an instruction for robot fwd 1, turn, pick up, … Requirements: Robot initial position Robot goal(s) Other constraints Your task: write a program for the robot! A sequence of cards Robot follows program

9 Now We’re Cooking! Computer = chef Program = recipe 1. Preheat oven to 350 o 2. Sift together flour, cocoa, baking powder, salt 3. Melt 1/2c butter and 1lb chocolate 4. Stir 1/2c sugar into chocolate mixture 5. Sir in 3 large eggs 6. Stir in dry ingredients 7. Add chocolate chunks 8. Form into rounded balls (1T each) 9. Bake 10 min

10 Time Required 1. Preheat oven 2. Dry ingredients 3. Melt chocolate 4. Add sugar 5. Add eggs 6. Combine wet & dry 7. Add chocolate chunks 8. Form into balls 9. Bake 5 min 6 min 2 min 1 min 10 min Total: 35 min

11 Two Chefs 1. Melt chocolate/Dry ingredients 2. Add sugar 3. Add eggs 4. Combine wet & dry 5. Add chocolate chunks 6. Form into balls 7. Bake 6 min 5 min 2 min 1 min 5 min 5 min 10 min Total: 25 min (> 35/2)

12 Lots of Chefs Total: 20 min 1. Melt choc/Dry ingr 2. Add sugar 3. Add eggs 4. Combine wet & dry 5. Add choc chunks 6. Form into balls 7. Bake 6 min 1 min 1 min 2 min 1 min 2 min 1 min 0 min 0 min 0 min 0 min … 10 min

13 Diminishing Returns # of chefs time ideal recipe 2 actual

14 A Sorting Program: BubbleSort 2962231641475811 58622316414729 11 23625816414729 11 2362581641472911 2958 23 6258 6211

15 Time Required (Bubblesort) After going down the whole list, what can we say about the result? After going down the whole list twice, what can we say about the result? 2311584762412916 2916114162582347 62 58

16 A Faster Program 29622316414758112958 62231647412911 2311581647412962 2958116247412316 5823 1158

17 Another Parallel Program To figure out where a number goes: Count how many numbers are smaller! Do this for each number in parallel! 296223164147581129

18 Summary Sequential programs are slow Use as many chefs as possible! Every day they get faster and cheaper New recipes are needed that scale efficiently Note: increased complexity of recipe So we need new ways to design these complex recipes

19 Module II: Parallel Program Sequential program: Bubble Sort Parallel programs: Even-Odd Transposition Sort Radix Sort

20 Fault-Tolerance Sometimes, when a program runs, things go wrong: a fault Faults are rare, but do occur Oven doesn’t work! Cookies end up gloopy No eggs in pantry! Chef stops, doesn’t know what to do (no cookies) Use salt by accident instead of sugar! Cookies end up gross “Fault-tolerant”: a program that still does the right thing, despite faults The program heals itself, and recovers

21 Making Sure the Cookies Turn Out How can you improve the odds of getting a good batch of cookies? Answer: use many chefs! Each chef makes a complete recipe Pick the best batch Even if some chefs experience faults, most will not “Triple Modular Redundancy” Simple, expensive

22 Tokens for Taking Turns Consider all the chefs across the city Say they need to take turns Only one can be on vacation at a time How do they coordinate when to go on vacation? Solution: use a “token” Pass token around Rule: If you have the token, you can go on vacation

23 Tokens Ring Problem: What about faults? What happens if token is lost? One fault means disaster!

24 Prevent Loss of Token Rule (for most chefs): if left neighbor is different from me, then I have the token Make my number equal to that neighbor’s 0 1 0 0 1 1 1

25 Fault: Corruption of Values Problem: multiple tokens in ring Tokens chase each other around ring One fault means disaster 0 1 0 0 1 1 1 0

26 Dijkstra’s Token Ring Use more than 2 values! Same rule If left neighbor different from me: I have the token! (use it) Change my value to be equal to neighbor Again, one chef is special If left neighbor same as me I have the token (use it) Change my value to be one bigger

27 Module III: Token Rings Form a ring Each person has number cards Each person has a chime When you get the token: Play your chime Then change your number We’ll run different versions I’ll introduce “faults” and see if you can recover!

28 Take-Home Messages Computer program: a sequence of instructions A recipe for a chef Software engineering: how to design programs Recipe requirements: ingredients and final dish Recipe design: correct, easy to understand and modify Parallel programming: lots of chefs in the kitchen Sequential programs are slow, parallel programs are fast! Fault tolerance: programs can heal themselves Redundancy Distributed programs


Download ppt "Computer Science An Introduction and Some Advanced Concepts Too! Prof. Paul Sivilotti Dept. of Computer & Info. Science The Ohio State University"

Similar presentations


Ads by Google