This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 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 " : #dont run this code on an import of this file import sys, time file = open(sys.argv, "rb" ) start = time.time() print get longest repeated offset(file) print "took: %s seconds" % (time.time() start) 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, "rb" ) result queue = multiprocessing.Queue()queue = multiprocessing....
View Full Document
- Fall '08