{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

4834_lecture_28_ho - EEL 4834 Lecture 28 EEL 4834 Lecture...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
EEL 4834: Lecture 28 EEL 4834: Lecture 28 Multicore Programming: using multiprocessing Professor O. Boykin University of Florida, Department of Electrical and Computer Engineering November 10, 2009 EEL 4834: Lecture 28 Example Program Consider this program which finds the single character which is repeated the most number of times in a file: def get longest repeated offset(myfile): last char = myfile.read(1) offset = 0 last count = 1 max char = last char max count = last count while last char: this char = myfile.read(1) offset += 1 if last char == this char: last count += 1 else: last count = 1 last char = this char if last count > max count: max char = this char max count = last count return (max char, offset, max count) if name == " main " : #don’t run this code on an import of this file import sys, time file = open(sys.argv[1], "rb" ) start = time.time() print get longest repeated offset(file) print "took: %s seconds" % (time.time() start)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
EEL 4834: Lecture 28 It takes a long time on a big file! What if we want to do something else at the same time? Use Processes! EEL 4834: Lecture 28 import multiprocessing, sys, time, thread0 def run and enqueue(queue, func, args): start = time.time() result = func( * args) end = time.time() queue.put((result, end start)) #needed on windows: if name == " main " : myfile = open(sys.argv[1], "rb" ) result queue = multiprocessing.Queue() rc proc = multiprocessing.Process(target=run
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}