Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to do it using threads? # importing the multiprocessing module import multiprocessing import array as arr def find_sum(a,n1,n2,q): s=0 for i in range(n1-1,n2): s=s+a[i]

How to do it using threads?

# importing the multiprocessing module import multiprocessing import array as arr def find_sum(a,n1,n2,q): s=0 for i in range(n1-1,n2): s=s+a[i] q.put(s) if __name__ == "__main__": a=arr.array('i',[0,1,2,3,4,5,6,7,8,9]) q = multiprocessing.Queue() # creating processes p1 = multiprocessing.Process(target=find_sum, args=(a,1,4,q )) p2 = multiprocessing.Process(target=find_sum, args=(a,5,7,q)) p3 = multiprocessing.Process(target=find_sum, args=(a,8,10,q)) sumarray=0 # starting process 1 p1.start() p1.join() # starting process 2 p2.start() p2.join() # starting process 3 p3.start() p3.join() for i in range(0,3): sumarray+=q.get() print("Array sum: ",sumarray)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

=+ a. How does this change affect the demand for money?

Answered: 1 week ago

Question

What is conservative approach ?

Answered: 1 week ago

Question

What are the basic financial decisions ?

Answered: 1 week ago

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago