Java知识分享网 - 轻松学习从此开始!    

Java知识分享网

Java1234官方群25:java1234官方群17
Java1234官方群25:838462530
        
SpringBoot+SpringSecurity+Vue+ElementPlus权限系统实战课程 震撼发布        

最新Java全栈就业实战课程(免费)

springcloud分布式电商秒杀实战课程

IDEA永久激活

66套java实战课程无套路领取

锋哥开始收Java学员啦!

Python学习路线图

锋哥开始收Java学员啦!
当前位置: 主页 > Java文档 > Java基础相关 >

Multitreading PDF 下载


分享到:
时间:2020-09-28 09:20来源:http://www.java1234.com 作者:小锋  侵权举报
Multitreading PDF 下载
失效链接处理
Multitreading  PDF 下载

本站整理下载:
 
相关截图:
 
主要内容:

Introduction
For this assignment, implement the Sieve of Eratosthenes using a pool of 
processes in Python, use test runs to see how quickly the program runs under 
different combinations of parameters, and write a short description of your 
results along with possible explanations for why the results came out that way. 
The Sieve of Eratosthenes
The sieve is a simple way to find prime numbers that involves taking a list 
of integers and throwing away ones that are multiples. We start with an array 
sieve with sieve[0] and sieve[1] false and sieve[2..n-1] all true (where n is 
the length of the sieve). For each k = 2, 3, …, n/2, set sieve[m*k] false for all m ≥ 2 (and m*k < n, of course). When you’re done, sieve[p] is true iff p is prime. 
Calculate a list of those p; that’s the list of primes < n.
For the python version of the program, write a python3 program that declares a 
sieve array as a global variable and initializes it using 
multiprocessing.sharedctypes.RawArray (see the discussion below). 
The main() routine should run the sieve algorithm, return a list of prime numbers, 
and print out the time it took to calculate the sieve, in ms.
The main() routine should have keyword arguments poolsize (for the 
pool size to use) and chunksize (see below). To explain the chunk size, 
imagine a do_sieve(k) routine that removes all multiples of k from the sieve (but 
if k ≤ 1, it just removes k). To process the sieve, we’d need to run do_sieve on k
= 0, 1, …, size of sieve - 1. Now imagine extending this routine to take k and
chunksize and having it remove all multiples of k, k+1, k+2, …, 
k+chunksize-1. To process the entire sieve, we will run this routine with 
starting k values of 0, chunksize, 2*chunksize, and so on. These runs will be 
in parallel. A chunksize of 1 creates as many processes as possible to process 
the sieve; a 
chunksize equal to the sieve size is a sequentially-running sieve.
Using Shared Ctype Data
The matrix multiplication routine from lecture doesn’t have to share the 
results of the parallel computations between different processes. The top-level 
routine runs the parallel routines and collects the results.
For the sieve algorithm, we do have to share the sieve array among all the 
parallel sieving calls, since the final sieve array is the result of striking out all 
multiples of 2 and all multiples of 3 and so on. For the processes to share the 
sieve array, it must be global, as in the matrix multiplication program, but the we 
need multiprocessing.sharedctypes.RawArray to create the array. If 
you read the Python documentation on this class (and obviously, you should), 
you’ll find that the values produced by this class are shared across processes. 
The smallest unit of array data you can use are signed and unsigned characters. 
You’ll need to pick one of these types and decide on values you want to use to 
represent true and false


 

------分隔线----------------------------

锋哥公众号


锋哥微信


关注公众号
【Java资料站】
回复 666
获取 
66套java
从菜鸡到大神
项目实战课程

锋哥推荐