MATLAB Answers

Alrik
1

Task Parallelism in Matlab

Asked by Alrik
on 16 Feb 2012

Hello, I'd like to have some task parallelism (as opposed to data parallelism) in a program that I'm writing, but have ran into some issues. Ideally, I'd like to have two distinct functions running concurrently (on the same machine), with the option of sharing data between them. Their data would be different, but obtained from a common source (a DAQ card).

I have access to the parallel computing toolbox, and have been looking at spmd, parfor, distributed parallel Jobs and parallel jobs, but none seem to quite fit what I'm looking for. In C++/Java, I'd just spawn two threads and have them run their respective functions, with a semaphore and some shared memory if I wanted to have any inter-thread communication. However, Matlab doesn't seem to have any analogous functionality to this; I've taken a stab at trying to use the Parallel Toolbox's parallel/distributed Jobs + Tasks, but Matlab assumes I'm trying to run on a cluster (even if I'm using the local scheduler) and seems to insist on serializing, then reconstructing any parameters I pass to the workers (which is a problem, as the DAQ's analoginput needs to either be obtained via the same analoginput object, or have its accesses synchronized, which is something I'd like to avoid).

In addition, as I understand it, the matlab display can only be modified by the main thread, which means that during any of the parallel constructs (i.e. parfor and spmd), the display cannot be updated, which would be another problem I'd have to work around (possibly by having a C++ GUI and updating it via a mex file and some inter-process communication scheme, which seems like a lot of trouble to go to for this).

I guess my question boils down to whether I should continue trying to find some matlab-based task-parallel functionality (i.e. using spmd and having different labs perform different tasks), or if there's a good way to do this in matlab that I haven't found out about yet, or if using matlab will be more trouble than it's worth, and just moving to a non-matlab solution. I'd like to stick with using matlab if possible; if anyone has had prior experience with this, I'd appreciate any insights you have to offer.

Sorry for the long post, and thanks for any help!

-al

  0 Comments

Sign in to comment.

1 Answer

Answer by Thomas
on 16 Feb 2012
 Accepted Answer

Don't know if this will help but NASA has some simple task parallel example for MATLAB on the following wiki page

http://www.nccs.nasa.gov/matlab_instructions.html#step11

Some more reading here:

http://www.mathworks.com/products/parallel-computing/demos.html?file=/products/demos/shipping/distcomp/paralleldemo_resource_bench.html

FYI- I Use a lot of task parallelism for Sensor Network Simulations on a cluster, however my task are independent of each other.

  1 Comment

Thanks for the links; they offered a nice read. I've ended up using the spmd construct and designating tasks based on the labindex, which thus far seems to be better than I had originally expected it to be.

Sign in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today