Can parellelized program run slower than single process program?

Aldrich DeMata aldrich.demata at gmail.com
Thu Jun 21 07:54:59 CEST 2012


The multiprocessing module allows the programmer to fully leverage *multiple
* processors on a given machine (python docs). This allows the operating
system to take advantage of any parallelism inherent in the hardware design.

If you are using the module on non-multiprocessor machines, I think you are
not using it to its full capability, and the module's overhead will just
slow down your code.

Aldrich


On Thu, Jun 21, 2012 at 12:05 AM, Yesterday Paid
<howmuchistoday at gmail.com>wrote:

> from multiprocessing import Pool
> from itertools import product
>
> def sym(lst):
>    x,y=lst
>    tmp=x*y
>    if rec(tmp):
>        return tmp
>    else:
>        return None
>
> def rec(num):
>    num=str(num)
>    if num == "".join(reversed(num)):    return True
>    else:    return False
>
> if __name__ == "__main__":
>    pool=Pool(processes=8)
>    lst=product(xrange(100,1000),repeat=2)
>    rst=pool.map(sym,lst)
>    #rst=sym(lst)
>    print max(rst)
>
>
> in my old computer(2006),
> when run it on single process, it takes 2 seconds
> but using multiprocessing.pool, it takes almost 8 or 9 seconds
> is it possible?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120621/5a9fffab/attachment-0001.html>


More information about the Python-list mailing list