Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Parallel or distributed plotting

Subject: Parallel or distributed plotting

From: Carlos R del Blanco

Date: 8 Jul, 2010 13:25:10

Message: 1 of 7

Hello, my problem is that I have to plot and print to a file a lot of results. The 90% of the computation time is due to that. So I would like to plot and especially print to file using several core, processors or even computers.

I have tried two possibilities that have failed:
1) Using the parallel computing toolbox: the problem is that the workers have no object graphics capabilities, so apparently it is impossible.
2)Using the COM interface to open new Matlab sessions: the problem is that I can put in the server Matlab sessions graphic objects, cell arrays or structures, only matrices and scalars. Therefore, I would have to do major modifications to decompose my cell, and data structures in simple matrices and scalar in order to transmit all the information to the Matlab server session. It seems very tricky and annoying, and in addition, I don't know if it would be very efficient.

Has somebody got an idea?

Thanks in advance.

Subject: Parallel or distributed plotting

From: Edric M Ellis

Date: 8 Jul, 2010 15:29:00

Message: 2 of 7

"Carlos R del Blanco" <cda@gti.ssr.upm.es> writes:

> Hello, my problem is that I have to plot and print to a file a lot of
> results. The 90% of the computation time is due to that. So I would
> like to plot and especially print to file using several core,
> processors or even computers.
>
> I have tried two possibilities that have failed:
> 1) Using the parallel computing toolbox: the problem is that the
> workers have no object graphics capabilities, so apparently it is
> impossible.

Even though Parallel Computing Toolbox workers cannot display graphics
on-screen, they can certainly print to file. Do you have an example
where things don't work as you'd expect?

Cheers,

Edric.

Subject: Parallel or distributed plotting

From: Carlos R del Blanco

Date: 8 Jul, 2010 15:50:05

Message: 3 of 7

Yes, I have problems in printing. For example, I plot a figure in the Matlab client, then I use the saveas function, that internally calls to the print function to plot to a file the figure. For this operation I need the figure handle. Then I obtain this error:

??? Error using ==> parallel_function at 594
Error in ==> saveas at 59
Invalid handle.

Specifically the piece of code is:

h =imshow(RGB_double);
parfor i_h = 1:2
   if(i_h == 1)
      saveas(h, '.\img.jpg');
   end
   if(i_h == 2)
      saveas(h, '.\img.fig');
   end
end

I can imagine that the graphic object "lives" in the workspace of the Matlab client, so it can be seen by any Matlab worker.

Edric M Ellis <eellis@mathworks.com> wrote in message <ytwwrt656wz.fsf@uk-eellis-deb5-64.mathworks.co.uk>...
> "Carlos R del Blanco" <cda@gti.ssr.upm.es> writes:
>
> > Hello, my problem is that I have to plot and print to a file a lot of
> > results. The 90% of the computation time is due to that. So I would
> > like to plot and especially print to file using several core,
> > processors or even computers.
> >
> > I have tried two possibilities that have failed:
> > 1) Using the parallel computing toolbox: the problem is that the
> > workers have no object graphics capabilities, so apparently it is
> > impossible.
>
> Even though Parallel Computing Toolbox workers cannot display graphics
> on-screen, they can certainly print to file. Do you have an example
> where things don't work as you'd expect?
>
> Cheers,
>
> Edric.

Subject: Parallel or distributed plotting

From: Steven Lord

Date: 8 Jul, 2010 18:23:14

Message: 4 of 7


"Carlos R del Blanco" <cda@gti.ssr.upm.es> wrote in message
news:i14s3d$q4m$1@fred.mathworks.com...
> Yes, I have problems in printing. For example, I plot a figure in the
> Matlab client, then I use the saveas function, that internally calls to
> the print function to plot to a file the figure. For this operation I need
> the figure handle. Then I obtain this error:
>
> ??? Error using ==> parallel_function at 594
> Error in ==> saveas at 59
> Invalid handle.
>
> Specifically the piece of code is:
>
> h =imshow(RGB_double);

This image object is created _by the client session_.

> parfor i_h = 1:2
> if(i_h == 1)
> saveas(h, '.\img.jpg');

This command is executed _by the worker session._

> end
> if(i_h == 2)
> saveas(h, '.\img.fig');
> end
> end
>
> I can imagine that the graphic object "lives" in the workspace of the
> Matlab client

You can think of it that way, yes.

>, so it can be seen by any Matlab worker.

No. A MATLAB worker is a separate session of MATLAB from the client; if you
manually started two sessions of MATLAB on the same machine, would you
expect one to have access to the graphics created by the other? You
shouldn't. The same goes for the client session and workers.

You may be confusing graphics objects with functions; because functions can
exist outside MATLAB sessions (as files on disk) they are not tied to any
particular MATLAB session and so could be used by client or worker sessions.
But graphics objects are created and "owned" by one particular MATLAB
session and only last as long as that MATLAB session does -- other MATLAB
sessions can't interact with them directly.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Parallel or distributed plotting

From: Carlos R del Blanco

Date: 8 Jul, 2010 19:49:04

Message: 5 of 7

"Steven Lord" <slord@mathworks.com> wrote in message <i1552i$epi$1@fred.mathworks.com>...
>
> "Carlos R del Blanco" <cda@gti.ssr.upm.es> wrote in message
> news:i14s3d$q4m$1@fred.mathworks.com...
> > Yes, I have problems in printing. For example, I plot a figure in the
> > Matlab client, then I use the saveas function, that internally calls to
> > the print function to plot to a file the figure. For this operation I need
> > the figure handle. Then I obtain this error:
> >
> > ??? Error using ==> parallel_function at 594
> > Error in ==> saveas at 59
> > Invalid handle.
> >
> > Specifically the piece of code is:
> >
> > h =imshow(RGB_double);
>
> This image object is created _by the client session_.
>
> > parfor i_h = 1:2
> > if(i_h == 1)
> > saveas(h, '.\img.jpg');
>
> This command is executed _by the worker session._
>
> > end
> > if(i_h == 2)
> > saveas(h, '.\img.fig');
> > end
> > end
> >
> > I can imagine that the graphic object "lives" in the workspace of the
> > Matlab client
>
> You can think of it that way, yes.
>
> >, so it can be seen by any Matlab worker.
>
> No. A MATLAB worker is a separate session of MATLAB from the client; if you
> manually started two sessions of MATLAB on the same machine, would you
> expect one to have access to the graphics created by the other? You
> shouldn't. The same goes for the client session and workers.
>
> You may be confusing graphics objects with functions; because functions can
> exist outside MATLAB sessions (as files on disk) they are not tied to any
> particular MATLAB session and so could be used by client or worker sessions.
> But graphics objects are created and "owned" by one particular MATLAB
> session and only last as long as that MATLAB session does -- other MATLAB
> sessions can't interact with them directly.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
>

Oh, sorry, there was an error, I wanted to say "so it can NOT be seen by any Matlab worker", so of course I agree with you. The question is: can I transfer the graphic object to the worker in order to print it? or, since the workers have not graphics capabilities, does it imply that is totally impossible?

Subject: Parallel or distributed plotting

From: Edric M Ellis

Date: 9 Jul, 2010 10:48:09

Message: 6 of 7

"Carlos R del Blanco" <cda@gti.ssr.upm.es> writes:

> Oh, sorry, there was an error, I wanted to say "so it can NOT be seen
> by any Matlab worker", so of course I agree with you. The question is:
> can I transfer the graphic object to the worker in order to print it?
> or, since the workers have not graphics capabilities, does it imply
> that is totally impossible?

You can transfer the *data* that you wish to plot to the workers, have
them create the plot (even though they do not have a display - they
still know how to do all the work off-screen), and then do the
print/saveas. For example:


matlabpool local 3
imdata = imread( 'ngc6543a.jpg' ); % sample image which comes with MATLAB

parfor ii=1:3
    imagesc( imdata( :, :, ii ) );
    fname = sprintf( 'page_%d.jpg', ii );
    print( '-djpeg90', fname );
end

Cheers,

Edric.

Subject: Parallel or distributed plotting

From: Carlos R del Blanco

Date: 10 Jul, 2010 14:08:05

Message: 7 of 7

Thank you very much. Only one additional remark: using imshow() instead of imagesc() doesn't work, it gives an error related to java:

??? Error using ==> parallel_function at 598
Error in ==> imshow at 191
IMSHOW requires Java to run.

My hypothesis that the worker have some restrictions with the Java Run Time environtment.


Edric M Ellis <eellis@mathworks.com> wrote in message <ytwsk3t53ti.fsf@uk-eellis-deb5-64.mathworks.co.uk>...
> "Carlos R del Blanco" <cda@gti.ssr.upm.es> writes:
>
> > Oh, sorry, there was an error, I wanted to say "so it can NOT be seen
> > by any Matlab worker", so of course I agree with you. The question is:
> > can I transfer the graphic object to the worker in order to print it?
> > or, since the workers have not graphics capabilities, does it imply
> > that is totally impossible?
>
> You can transfer the *data* that you wish to plot to the workers, have
> them create the plot (even though they do not have a display - they
> still know how to do all the work off-screen), and then do the
> print/saveas. For example:
>
>
> matlabpool local 3
> imdata = imread( 'ngc6543a.jpg' ); % sample image which comes with MATLAB
>
> parfor ii=1:3
> imagesc( imdata( :, :, ii ) );
> fname = sprintf( 'page_%d.jpg', ii );
> print( '-djpeg90', fname );
> end
>
> Cheers,
>
> Edric.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us