Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7840519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:48:50+00:00 2026-06-02T15:48:50+00:00

I am trying to do some computations using the multiprocessing module in python 2.7.2.

  • 0

I am trying to do some computations using the multiprocessing module in python 2.7.2.
My code is like this:

from multiprocessing import Pool
import sys
sys.setrecursionlimit(10000)
partitions = []
class Partitions:
    parts = {} #My goal is to use this dict to speed
               #up calculations in every process that
               #uses it, without having to build it up
               #from nothing each time
    def __init__(self):
        pass
    def p1(self, k, n):
        if (k,n) in Partitions.parts:
            return Partitions.parts[(k, n)]
        if k>n:
            return 0
        if k==n:
            return 1
        Partitions.parts[(k,n)] = self.p1(k+1, n) + self.p1(k, n-k)
        return Partitions.parts[(k,n)]

    def P(self, n):
        result = 0
        for k in xrange(1,n/2 + 1):
            result += self.p1(k, n-k)
        return 1 + result

p = Partitions()

def log(results):
    if results:
        partitions.extend(results)
    return None

def partWorker(start,stop):
    ps = []
    for n in xrange(start, stop):
        ps.append(((1,n), p.P(n)))
    return ps

def main():
    pool = Pool()
    step = 150
    for i in xrange(0,301,step):
        pool.apply_async(partWorker, (i, i+step), callback = log)

    pool.close()
    pool.join()

    return None

if __name__=="__main__":
    main()

I am new to this, I basically copied the format of the prime code on this page:
python prime crunching: processing pool is slower?
Can I get process running in each core all looking at the same dictionary to assist their
calculations? The way it behaves now, each process creates it’s own dictionaries and it eats up ram like crazy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:48:55+00:00Added an answer on June 2, 2026 at 3:48 pm

    I’m not sure if this is what you want … but, take a look at multiprocessing.Manager ( http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes ). Managers allow you to share a dict between processes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I was trying some practice programs in python and I came across this
I am trying to accelerate some computations using OpenCL and part of the algorithm
I am trying to do some computations using Laplace transforms in R. I used
I am trying some way to optimize following sql statement: exe_sql DELETE FROM tblEvent_type
After following this MVC 4 tutorial series I was trying some of the stuff
I'm using Eclipse with C++ plugins on my macbook, trying some practice projects to
Im trying push some data into a CRM system via an XML import. I
I'm trying to do some parsing that will be easier using regular expressions. The
I am trying to get serialized results from a WCF service from database using
So i am trying to run some c code that compiles perfectly in windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.