... Lab 2.pdf ?:?? X University of Jeddah CCAI 412: Parallel Computing Lab #2 Multiprocessing in Python Multiprocessing vs Multithreading 1. In multiprocessing, each process has its own memory and there is no share memory while in multithreading, threads access same memory. 2. Creating process is heavyweight while thread is lightweight 3. Inter-process communication little complicated and we can do it by creating a shared data or queue Single Processor Single Thread Single Processor Multithread Multiprocessing Python Example 1: # importing the multiprocessing module import multiprocessing def print_cube(num): print("Cube of ", num, ":", num**3) def print_square(num): print("Square of ", num, ":", num**2) # creating processes p1 = multiprocessing.Process(target=print_square, args=(10,)) p2 = multiprocessing.Process(target=print_cube, args=(10,)) # starting process 1 p1.start() # starting process 2 p2.start() # wait until process 1 is finished p1.join() # wait until process 2 is finished p2.join()
Added by Margaret C.
Close
Step 1
Step 1: Analyze the given question and identify the key information or variables involved. Show more…
Show all steps
Your feedback will help us improve your experience
Trent Speier and 92 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Find the coordinates of the point on the plane curve described by the parametric equations corresponding to the given value of t x=6+2cost, y=5+3sint; t=pi/2 What are the coordinates of the point? Simplify your answer. Type an exact answer, using radicals as needed. Type an ordered pair.
Trent S.
1.) Rectangle Area The area of a rectangle is calculated according to the following formula: Area= Width * Length Design a function that accepts a rectangle's width and length as arguments and returns the rectangle's area. Use the function in a program that prompts the user to enter the rectangle's width and length, and then displays the rectangle's area.
Shelayah R.
Task: Design a modular program in Python to process payroll for all hourly paid employees and save all user-entered data and processed results to a txt file. The program should allow the user to enter each employee's ID, name, hours worked, and hourly pay rate. It should then calculate the gross pay, taking into account overtime hours (hours beyond 40) paid at a rate of 50% more. The program should display a pay statement for each employee. Finally, the program should display the total number of employees, the total number of hours worked by all employees, and the total gross pay. The program should contain the following functions: main(), getEmployeeInfo(), calcGrossPay(hours, rate), displayPayStatement(empID, empName, hoursWorked, hourlyPayRate, grossPay), and savePayStatement(empID, empName, hoursWorked, hourlyPayRate, grossPay). The getEmployeeInfo() function should return the employee's ID, name, hours worked, and hourly pay rate.
Supreeta N.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD