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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:32:42+00:00 2026-06-08T05:32:42+00:00

I am using matlab2011 for parallel calculation with multiple cores, which in my code

  • 0

I am using matlab2011 for parallel calculation with multiple cores, which in my code is simply implemented with the block SPMD END. However, for some times, I want to turn off the spmd in the program based on the input parameter. I try the following code, but it doesn’t work

if (switchSpmdOn)
  spmd
end
% here I put my code for calculation in parallel or series
if (switchSpmdOn)
  end % this end is used to close the spmd block
end

I am wondering if there is anything like marco to turn off spmd in the code.

  • 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-08T05:32:45+00:00Added an answer on June 8, 2026 at 5:32 am

    You can pass the number of workers as a parameter to spmd. If the number of workers specified is 0, i.e.,

    spmd(0)
       statement; %# block body
    end
    

    then MATLAB will execute the block body locally and create Composite objects, the same as if there is no pool available.

    Example

    switchSpmdOn = true;
    
    %# set the number of workers
    if (switchSpmdOn)
        workers = 3; 
        matlabpool(workers);
    else
        workers = 0;
    end
    
    %# application. if 'workers' is 0, MATLAB will execute this code locally
    spmd (workers)
        %# build magic squares in parallel
        q = magic(labindex + 2);
    end
    
    for ii=1:length(q)
      % plot each magic square
      figure, imagesc(q{ii});
    end
    
    if (switchSpmdOn)
        matlabpool close
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using EF Code First I have an model object that has multiple properties that
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using MVC2 I have an AJAX form which is posting to a bound model.
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
Using Java,I have to fetch multiple sets of values from an XML file to
Using MVVM. I have a DataTemplate which I am using to display an expander
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
Using Rails 3.1. I have some pages that render same layout, except the contents

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.