4834_lecture_28_ho

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

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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[1], "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[1], "rb" ) result queue = multiprocessing.Queue()queue = multiprocessing....
View Full Document

Page1 / 6

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online