Scatter tutorial - Supercomputing and Parallel Programming in Python and MPI 9

sentdex · Beginner ·🛠️ AI Tools & Apps ·12y ago

Key Takeaways

This video tutorial covers the use of scatter in MPI for Python, a technique for distributing data across multiple nodes in a supercomputing system. The tutorial demonstrates how to use the scatter function from the mpi4py library to divide a list of objects among nodes and explains the importance of ensuring that the number of objects does not exceed the number of nodes.

Full Transcript

hello everyone and welcome to another MPI for Python tutorial video for high performance computing supercomputing and parallel programming so in the last video we covered broadcasting now it's how we could take one variable or object and pass it to every other node in the system so we could share that variable amongst everybody so that was broadcasting I think that was fairly simple to understand next up we have what's known as scatter and gather so what scatter is gonna do is say in the master node we have a group of objects so let's say we have a list what we can do is we can take that list and you do scatter and it's gonna take that list explode the list and send it in parts to each of the nodes it's gonna divide up that list and send it to each of the nodes and then what gather does is basically the opposite of that so it's gonna take all the objects from all of the nodes gather them together and go to the target which usually will be the master node so with that let's go ahead and get started so as usual what we're gonna want to do is from MPI 4 equals MPI comm underscore world size equals get size man all these upper cases are killing me break equals calmed I get underscore rank okay that's all we need for this so then what we're gonna have is just the same kind of thing that we've had for quite a few of these is just when the if rank equals 0 what do we want to do we're gonna say data equals and then we're gonna make a generator here and generate a dynamic list of all of the ranks we could make a simple one but like we've got hard code it but that's not a good idea anyways data is going to equal this generator and what we're going to do is we're gonna say data equals x plus 1 to the power of X for X in range of size for X range even if you want it so that's what data is gonna be so basically if data is gonna be X plus 1 to the power of itself for each of the X's in the range of size which is referencing how big is this how big is this supercomputer in nodes this just basically makes sure that we will have one object per node it's just you know some sort of just arbitrary object that we're gonna give it so anyways mm-hmm once we've done that let's print out what we have just so you understand so you can see what data actually represents just in case you're not totally following what's happening here so we're gonna say we will be scattering and then data simple enough next we're gonna say else data equals none and you should kind of recognize this from before and then we come down here we say data equals calm dot scatter what are we scattering well data and from where that's gonna be Ruth zero now what we're gonna do is print rank rank and data okay so let's save that let me move it to news and then we'll come over to the master node up arrow and now I've changed mind s89 hit enter and again we're using five here Oh what have we done oh we've typo'd fantastic why didn't anybody tell me okay import okay so here we have we will be scattering and then it says we're gonna be scattering a 1/2 964 and 625 so you could hard-code on just a list right of 1/2 964 625 or whatever variables you want but you can see what it's done here is it scattered this stuff so rank 0 has data what data did bring 0 get it got the 1 Rank 1 got what data the 2 ring 2 got the 9 and so on so that should be a pretty easy to understand example of what scatter does it's just gonna kind of take everything and go picking just divert our divers just diversify it but at the same time I guess the word I'm looking for is scatter what if we did for X in range of size +5 right so what if we made that size a little bit bigger here Barrow let's see what happens so what happens in this case is in order to have scattered this stuff we wanted to be able to send multiple variables to some of these right so we were expecting only 5 and we wound up with 10 now first off I wouldn't be surprised if there was some way in this scatter call are the actual scatter command to scatter multiple at the same time you could make the object itself a an array right we've seen that we can pass an array or I guess it's not really a you could pass a numpy array or a Python list but anyway you'll want to just keep it in mind that you can't send more variables then you're ready to accept or more objects then you're ready to accept so if you're going to do this you would need to first divide it up by size so you would take the list maybe div by size in them say put X many variables and something like that you can even use modulo to round it off so let's say you had nine nine objects that you wanted to pass you could use the modulo to put everything in in one group and then modulo the rest so something like that anyways I might have a more in-depth example of scatter later I'll have to look through the documentation that would make sure there is an already like a prebuilt command within scatter that allows to do this before we go coding our on so anyways that's gonna conclude this tutorial video hopefully you guys enjoy in the next video what we talking about is gather so anyways stay tuned to the next video as always thanks for watching thanks for all the support and subscriptions and until next time

Original Description

Supercomputer Playlist: http://www.youtube.com/watch?v=13x90STvKnQ&list=PLQVvvaa0QuDf9IW-fe6No8SCw-aVnCfRi&feature=share In this mpi4py video, you are shown how to use scatter and what it is. http://seaofbtc.com http://sentdex.com http://hkinsley.com https://twitter.com/sentdex Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

This video tutorial teaches the basics of using scatter in MPI for Python to distribute data across multiple nodes in a supercomputing system. It covers the importance of ensuring that the number of objects does not exceed the number of nodes and demonstrates how to use the scatter function from the mpi4py library.

Key Takeaways
  1. Import the mpi4py library
  2. Initialize the MPI environment
  3. Define a list of objects to be scattered
  4. Use the scatter function to divide the list among nodes
  5. Print the scattered data to verify the result
💡 The scatter function in MPI for Python allows for efficient distribution of data across multiple nodes in a supercomputing system, but it requires careful consideration of the number of objects and nodes to avoid errors.

Related AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →