Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41073

Re: Advice regarding multiprocessing module

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'initialize': 0.05; '__name__': 0.07; 'python': 0.09; 'blocking': 0.09; 'skip:r 50': 0.09; 'slow.': 0.09; 'subject:module': 0.09; 'subject:skip:m 10': 0.09; 'cc:addr:python-list': 0.10; "'__main__':": 0.16; 'cc:name:python list': 0.16; 'dump': 0.16; 'param': 0.16; 'processes.': 0.16; 'time.time()': 0.16; 'wrote:': 0.17; 'skip:p 30': 0.20; 'issue.': 0.20; 'parameters': 0.20; 'occurs': 0.22; "haven't": 0.23; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'creating': 0.26; 'values': 0.26; 'core': 0.27; 'first.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'fixed': 0.28; 'skip:( 20': 0.28; 'run': 0.28; 'comparison': 0.29; 'factor': 0.29; 'overhead': 0.29; 'queue': 0.29; 'time:': 0.29; 'distribute': 0.30; 'code': 0.31; 'point': 0.31; 'print': 0.32; 'subject:regarding': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'clear': 0.35; 'board': 0.35; 'received:209.85': 0.35; 'but': 0.36; "i'll": 0.36; 'reported': 0.37; 'rather': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'where': 0.40; 'your': 0.60; 'more.': 0.62; 'safe': 0.63; 'times': 0.63; 'more': 0.63; 'jobs': 0.65; 'results': 0.65; '2013': 0.84; 'calculations': 0.84; 'killing': 0.84; 'oscar': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=BXIGBNjgUYoNOSFBC5i91fTSHQ37D2JCcFI1rR6eDec=; b=X0ATIiSv6R0p9hr4Nnk2wMFkHpOtJ8ApR+pg1mn5kuJQvDAXrUd7tqUUI1w1EVPs4U jjcELlB+y4mKI8e9u+D9dVfh6z79P6RQrCL+jaPmPsZ9zdTm8CdpwBWkHksH0ngDmbGc EVriICuhJApt8vhIj6mQoecCL82V4herUxax242wQDVn5B/oWBXG9TTXPqDO9iyUCzZg vD0gaJTpTIPlBRxYqPL3GusPhExowjd1JBwSyRh5c8JHFcNq154GwAlvOfzuVNE0O64j PQH9TRKGKGmP9Xd314sIF9XrlQDrBIWumRe9rve6ZK0E/kddOTarXBPw1ZtAyl9HA0I9 fb3A==
X-Received by 10.221.9.136 with SMTP id ow8mr4800173vcb.58.1363017554422; Mon, 11 Mar 2013 08:59:14 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <513DF0BC.1000902@uci.edu>
References <1522066129.3339778.1363000462968.JavaMail.root@sequans.com> <513DF0BC.1000902@uci.edu>
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
Date Mon, 11 Mar 2013 15:58:54 +0000
Subject Re: Advice regarding multiprocessing module
To Abhinav M Kulkarni <amkulkar@uci.edu>
Content-Type text/plain; charset=ISO-8859-1
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3193.1363017562.2939.python-list@python.org> (permalink)
Lines 63
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1363017562 news.xs4all.nl 6934 [2001:888:2000:d::a6]:33712
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41073

Show key headers only | View raw


On 11 March 2013 14:57, Abhinav M Kulkarni <amkulkar@uci.edu> wrote:
> Hi Jean,
>
> Below is the code where I am creating multiple processes:
>
> if __name__ == '__main__':
>     # List all files in the games directory
>     files = list_sgf_files()
>
>     # Read board configurations
>     (intermediateBoards, finalizedBoards) = read_boards(files)
>
>     # Initialize parameters
>     param = Param()
>
>     # Run maxItr iterations of gradient descent
>     for itr in range(maxItr):
>         # Each process analyzes one single data point
>         # They dump their gradient calculations in queue q
>         # Queue in Python is process safe
>         start_time = time.time()
>         q = Queue()
>         jobs = []
>         # Create a process for each game board
>         for i in range(len(files)):
>             p = Process(target=TrainGoCRFIsingGibbs, args=(intermediateBoards[i], finalizedBoards[i], param, q))

Use a multiprocessing.Pool for this, rather than creating one process
for each job. e.g.:

p = Pool(4) # 1 process for each core
results = []
for ib, fb in zip(intermediateBoards, finalizedBoards):
    results.append(p.apply_async(TrainGoCRFIsingGibbs, args=(ib, fb, param, q)))
p.close()
p.join()

# To retrieve the return values
for r in results:
    print(r.get())

This will distribute your jobs over a fixed number of processes. You
avoid the overhead of creating and killing processes and the process
switching that occurs when you have more processes than cores.

>             p.start()
>             jobs.append(p)
>         # Blocking wait for each process to finish
>         for p in jobs:
>             p.join()
>         elapsed_time = time.time() - start_time
>         print 'Iteration: ', itr, '\tElapsed time: ', elapsed_time
>
> As you recommended, I'll use the profiler to see which part of the code is
> slow.

Do this without using multiprocessing first. Loosely you can hope that
multiprocessing would give you a factor of 4 speedup but no more. You
haven't reported a comparison of times with/without multiprocessing so
it's not clear that that is the issue.


Oscar

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Advice regarding multiprocessing module Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-03-11 15:58 +0000

csiph-web