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 8133245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:32:53+00:00 2026-06-06T09:32:53+00:00

I have a huge data set and I have to compute for every point

  • 0

I have a huge data set and I have to compute for every point of it a series of properties. My code is really slow and I would like to make it faster parallelizing somehow the do loop. I would like each processor to compute the “series of properties” for a limited subsample of my data and then join all the properties together in one array.
I’ll try explain what I have to do with an example.

Let’s say that my data set is the array x:

x = linspace(0,20,10000)

The “property” I want to get is, for instance, the square root of x:

prop=[]
for i in arange(0,len(x)):
    prop.append(sqrt(x[i]))

The question is how can I parallelize the above loop? Let’s assume I have 4 processor and I would like each of them to compute the sqrt of 10000/4=2500 points.

I tried looking at some python modules like multiprocessing and mpi4py but from the guides I couldn’t find the answer to such a simple question.

EDITS

I’ll thank you all for the precious comments and links you provided me. However, I would like to clarify my question. I’m not interested in the sqrt function whatsoever.
I am doing a series of operations within a loop. I perfectly know loops are bad and vectorial operation are always preferable to them but in this case I really have to do a loop. I won’t go into the details of my problem because this would add an unnecessary complication to this question.
I would like to split my loop so that each processor does a part of it, meaning that I could run my code 40 times with 1/40 of the loop each and the merger the result but this would be stupid.
This is a brief example

     for i in arange(0,len(x)):
         # do some complicated stuff

What I want is use 40 cpus to do this:

    for npcu in arange(0,40):
       for i in arange(len(x)/40*ncpu,len(x)/40*(ncpu+1)):
          # do some complicated stuff

Is that possible or not with python?

  • 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-06T09:32:54+00:00Added an answer on June 6, 2026 at 9:32 am

    I’m not sure that this is the way that you should do things as I’d expect numpy to have a much more efficient method of going about it, but do you just mean something like this?

    import numpy
    import multiprocessing
    
    x = numpy.linspace(0,20,10000)
    p = multiprocessing.Pool(processes=4)
    
    print p.map(numpy.sqrt, x)
    

    Here are the results of timeit on both solutions. As @SvenMarcach points out, however, with a more expensive function multiprocessing will start to be much more effective.

    % python -m timeit -s 'import numpy; x=numpy.linspace(0,20,10000)' 'prop=[]                                                                          
    for i in numpy.arange(0,len(x)):
             prop.append(numpy.sqrt(x[i]))'
    10 loops, best of 3: 31.3 msec per loop
    
    % python -m timeit -s 'import numpy, multiprocessing; x=numpy.linspace(0,20,10000)
    p = multiprocessing.Pool(processes=4)' 'l = p.map(numpy.sqrt, x)' 
    10 loops, best of 3: 102 msec per loop
    

    At Sven’s request, here is the result of l = numpy.sqrt(x) which is significantly faster than either of the alternatives.

    % python -m timeit -s 'import numpy; x=numpy.linspace(0,20,10000)' 'l = numpy.sqrt(x)'
    10000 loops, best of 3: 70.3 usec per loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a selection of a huge set of data and I would like
I have a huge data set. The structure looks something like this: K_Field1, K_Field2,
I have a huge data set with genotypic information from different populations. I would
I have a huge set of data and want to display the data with
I have a huge set of data of tables in Open Office 3.0 document
I currently work with OpenLayers and have a huge set of data to draw
I have written a program which works on huge set of data. My CPU
I have a huge collection of visual foxpro dbf files that I would like
I have a set of flags which are part of a huge text data
Here is the situation: I have a huge data set that I need quick

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.