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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:20:56+00:00 2026-06-17T19:20:56+00:00

I created two functions: generating data and processing data. Data processing is time-consuming, so

  • 0

I created two functions: generating data and processing data. Data processing is time-consuming, so I want to process them in a parallel thread. But I have some problems with them. At first, here is my program:

result = zeros(1, 10);

matlabpool open local 2
spmd
    for a = 1:5
        data = generate_data();
        display(sprintf('Received data on CPU%d: %d', labindex, data));
        result(end + 1) = process_data(data);
    end
    display(sprintf('All done on CPU%d', labindex));
end
matlabpool close

And log of what it returned:

Starting matlabpool using the 'local' profile ... connected to 2 workers.
Lab 1: 
  Received data on CPU1: 100
Lab 2: 
  Received data on CPU2: 100
Lab 1: 
  Received data on CPU1: 101
  Received data on CPU1: 102
  Received data on CPU1: 103
  Received data on CPU1: 104
  All done on CPU1
Lab 2: 
  Received data on CPU2: 101
  Received data on CPU2: 102
  Received data on CPU2: 103
  Received data on CPU2: 104
  All done on CPU2
Sending a stop signal to all the workers ... stopped.

There is problem, which I have:

  1. Values which it is returning by generate_data are the same for
    both thread. I should be different. Threads should process different
    data, rather than same data twice. I cannot generate the entire data
    set at once and use getLocalPart.

  2. Variable result isn’t a 1×10 matrix of doubles, but 1×2 matrix of
    composites. I read about (co)distributed array but it didn’t help
    me. What I should do to receive the 1×10 matrix of doubles?

  3. What I should do to CPU1 processes CPU2’s data, when finishes to
    process own data? Generally I don’t have any idea how to do this.

  4. It is possible to remove “Lab 1:” and “Lab 2:”? They are messing
    my log 🙂

Taking into consideration above, log (for the larger data set) should look this way:

Starting matlabpool using the 'local' profile ... connected to 2 workers.
Received data on CPU1: 100
Received data on CPU2: 101
Received data on CPU1: 102
Received data on CPU1: 103
Received data on CPU1: 104
Received data on CPU1: 105
Received data on CPU2: 106
Received data on CPU1: 107
Received data on CPU1: 108
Received data on CPU2: 109
All done on CPU1
All done on CPU2
Sending a stop signal to all the workers ... stopped.
  • 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-17T19:20:58+00:00Added an answer on June 17, 2026 at 7:20 pm

    Why don’t you use the much simpler parfor? At the moment you’re running the loop on each workers, and I assume that you wanted to run the iterations of the loop in parallel.

    nIter = 10;
    result = zeros(1, nIter);
    
    matlabpool open local 2
    
        parfor a = 1:nIter
            data = generate_data();
            fprintf('%s: processing set %i/%i\n',datestr(now),a,nIter)
            result(a) = process_data(data);
        end
    end
    matlabpool close
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two functions that sorts a list using bubble sort, but I
Basically I have created two MATLAB functions which involve some basic signal processing and
I have created two functions that sum and subtract the numeric values of two
Possible Duplicate: jQuery delay between animations I have created two functions: One that animates
I created a website but i have a problem. i want to build once
I have created two functions in controller of Symfony as follow: first is newAction
I created two simple functions to filter inserted data before it's entered into a
I have two JS functions that preforms AJAX calls, I've wanted to test them
I have a function that creates time intervals between two time marks. The function
good morning, I was trying the SharedPreferences Class and I have created two classes,

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.