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

  • Home
  • SEARCH
  • 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 7583009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:34:40+00:00 2026-05-30T18:34:40+00:00

I have a 3 dimensional grid, in which for each point of the grid

  • 0

I have a 3 dimensional grid, in which for each point of the grid I want to calculate a time dependent function G(t) for a large number of time steps and then summing the G function for each grid point. Using 4 for loops the execution time is becoming very large, so I am trying to avoid this using parfor.

a part of my code:

for i=1:50
    for j=1:50
        for k=1:25
            x_in=i*dx;
            y_in=j*dy;
            z_in=k*dz;
            %dx,dy, dz are some fixed values
            r=sqrt((xx-x_in).^2+(yy-y_in).^2+(zz-z_in).^2);
            %xx,yy,zz are 50x50x25 matrices generated from meshgrid
            % r is a 3d matrix which produced from a 3 for-loop, for all the points of grid
            parfor q=1:100
                t=0.5*q;
                G(q)=((a*p)/(t.^1.5)).*(exp(-r.^2/(4*a*t)));
                % a,p are some fixed values
            end
            GG(i,j,k)=sum(G(:));
        end
    end
end

When I am using parfor the execution time becomes larger, and I am not sure why this is happening. Maybe I am not so familiar with sliced and indexed variables on a parfor loop.

My pc processor has 8 threads and ram memory ddr3 8GB

Any help will be great.

Thanks

  • 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-05-30T18:34:42+00:00Added an answer on May 30, 2026 at 6:34 pm

    As has been discussed in a previous question, parfor comes with an overhead. Therefore, loop that is too simple will execute more slowly with parfor.

    In your case, the solution may be to parallelize the outermost loops.

    %# preassign GG
    GG = zeros(50,50,25);
    
    %# loop over indices into GG
    parfor idx = 1:(50*50*25)
        [i,j,k] = ind2sub([50 50 25],idx);
        x_in=i*dx;
        y_in=j*dy;
        z_in=k*dz;
        %dx,dy, dz are some fixed values
    
        r=sqrt((xx-x_in).^2+(yy-y_in).^2+(zz-z_in).^2);
    
        %xx,yy,zz are 50x50x25 matrices generated from meshgrid
        % r is a 3d matrix which produced from a 3 for-loop, for all the points of grid
    
        for q=1:100
            t=0.5*q;
            G(q)=((a*p)/(t.^1.5)).*(exp(-r.^2/(4*a*t)));
            % a,p are some fixed values
        end
        GG(idx)=sum(G(:));
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say, we have an N-dimensional grid and some point X in it with coordinates
I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a list of two-dimensional points and I want to obtain which of
In some crunching number program, I have a function which can be just 1
I have a large 2 dimensional grid, let us say 10000 X 10000. From
I have a 2-dimensional array of objects and I basically want to databind each
I have a one-dimensional function minimizer. Right now I'm passing it function pointers. However
In a multi-dimensional space, I have a collection of rectangles, all of which are
I have a two dimensional grid of cells. In this simulation, cells may request
I have a 2D vector which contains the coordinates which I want to represent

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.