2.04: Introducing Parallel Programming
Lesson Overview
This lesson will be a basic introduction to parallel programming where students will think about how they can go about getting Marty to do two things at the same time rather than one after the other. First, this will be demonstrated in Marty Blocks before trying it out with Marty.
- Code blocks, Parallel, Sequence, Programming,
Content Sections
2.04: Introducing Parallel Programming
Lesson Overview
This lesson will be a basic introduction to parallel programming where students will think about how they can go about getting Marty to do two things at the same time rather than one after the other. First, this will be demonstrated in Marty Blocks before trying it out with Marty.
- Code blocks, Parallel, Sequence, Programming,
- Awareness of event blocks and what they do; knowledge of a variety of movement blocks
- iPad or Tablet with MartyBlocks
-
- Marty the Robot v2
- Marty Workbook
- Tablets
- Access to the MartyBlocks editor
Learning Objectives
- I can describe what parallel means.
- I can create separate blocks of code that work in parallel - they do not overlap and are carried out at the same time.
Warm up
Ask learners if they have ever helped with dinner, for example, chopping some vegetables, stirring something that was cooking or mesuring ingredients. Inform learners that if others were working with them to create the meal, they were working in parallel with other people.
Share with learners a couple of funny video clips of people working in parallel but then something going wrong. The first two video clips show what happens when the working relationship breaks down. The third clip doesn't show people working in parallel but only what can happen when someone stops working in parallel. The third clip isn't as meaningful as the first two.
The first video of Marty shows him doing a dance that requires the arms and legs moving together. The dance block, by itself, also accomplishes this but having separate movements, in parallel, allows for a lot more control in terms of timing and angle of movement. The movements are timed to music, which isn't a requirement of the work today it is just to show the greater control that can come of specific actions, rather than just the dance block/
The code isn't behaving for this, yet. It will be inserted when the code is fixed.
Have learners think of actions they complete each day that involves them doing two things at once: some examples could be holding down shift and a letter on the keyboard to get a capital letter, turning a key and a handle to open a locked door, stirring a mixture and adding ingredients while cooking, holding down two buttons on a device to take a screen capture. Have learners complete the workbook page about actions that require parallel parts. The actions can be very close together when they happen at the same time but, as long as one does not stop the other from being accomplished, they are parallel actions.
Get Learning
Tying in the vocabulary of parallel programming with mathematics, the next slide in the presentation shows two parallel lines traveling across the slide. This will hopefully reinforce the idea that parallel programming has elements that work at the same time but don't interact. The parallel lines go on, forever, never touching, and always staying the same distance apart (click on the slide to see the animation occur). The workbook has six shapes with learners to mark the parallel sides. Arrows have been used to show that these sides would extend in this direction without touching the other side. The trapezium (or trapezoid) and parallelogram are the other two shapes that need marks for parallel sides; the triangles do not have parallel sides.
There is an example of a person patting their head and rubbing their stomach, which illustrates the kind of process learners will be coding today: these two actions do not interfere, they are independent actions. This may be challenging for some learners so make it fun. If you feel that this will be too challenging for some learners, feel free to delete the slide.
Discuss which sort of movements could not be done in parallel and why they can't be. Have learners complete the task in their workbook identifying potential parallel processes and actions that cannot be completed in parallel. Suggest that learners try this with themselves: which actions are they able to complete in parallel and why are they not able to. Explore the reasons for their thoughts; this should be fairly straightforward, you can't lift and lower the same hand at the same time; you can't lift both feet off the ground at the same time because of gravity (not the same as a jump); some of Marty's actions require a variety of parts to move at the same time, so you couldn't press dance and expect to move the arms, legs or eyebrows at the same time as the dance block is being executed.
video of Marty performing dance moves via parallel events
Time for Practice
Give learners a chance to think what sort of actions they would like Marty to carry out: maybe it is a dance, perhaps something simpler like walking and waving or even making a sound (but hopefully not too much) while moving.
Show learners how to create parallel blocks by dragging two event blocks onto the workspace. Drag the lift and lower left arm blocks under one of the event blocks and do the same with the right arm for the other event block. The slide on the presentation shows how this should look. The next again slide shows the video of Marty executing the code. Give learners an opportunity to scan through the blocks and see that there are no blocks that do this by themselves: you need to make use of parallel programming principles to create a complex action, for Marty.
The movement on the video happens once and stops. Challenge learners to have an action that repeats or a more complex one: first the arms move in parallel, then arms and one leg, maybe the eyebrows, etc.
Cool Down
Bring learners back together to discuss the challenges they faced and overcame. Have groups model their creations and explain what is happening, when. Encourage questions about differences between the design of different groups' code. If a group chose to explore any extension activities, allow for time to explain this.
Suggested questions you might ask:
- Which interesting combinations did you create?
- Were there any movements that you could not create to run in parallel that were unexpected? Does anyone have any thoughts as to why they might not have executed, properly?
- Can anyone think of a good reason why control of each individual movement mighty be better for a programmer rather than relying on a pre-made block that brings a lot of movements together?
Carry out any end of lesson routines.
Log off devices and clear everything away.
Extensions & Support
Extend
- Challenge Learners to create some of the pre-made moves: dance, wiggle, kick, wave, etc.
- Learners will need to observe and record the individual movements and then work on the timing to perfect their code.
Support
With every block of code learners put onto the workspace, encourage them to 'be' Marty: have them model the movement and feel what other movements they would be able to do at the same time but also encourage them to think about concepts like balance and comfort.
Encourage learners to think back about opposite actions and why two opposite actions cannot occur at the same time.
Additional Reading
- Educator’s Guide
- Introduction to Programming with Marty using Marty Blocks
- Technologies: Computing Science
- Literacy & English: Listening and Talking
- Health and Wellbeing: Mental, Emotional, Social and Physical Wellbeing
- Literacy & English: Writing
- Computing, Design and Technology: Design and Technology
- Computing, Design and Technology: Computing
- CSTA Education Standards
- Elementary Technology Applications: Grade 3 to Grade 5
- Digital Technologies, Design & technologies: Digital Technologies
- International Society for Technology in Education (ISTE)