Deployed applications - Display from within a parfor loop and some other questions
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear readers,
I have a number of questions regarding the Matlab program I am trying to deploy as a standalone Windows application. The program uses a single (but crucial) 'parfor' loop. (I should point out that the same code using just the simple 'for' loop works as intended.)
1.) From within the parfor loop, I am trying to display some information for the user. At the moment I am using the 'disp' function, e.g.:
parfor i = 1:10
...
disp(['The index of this iteration is: ', num2str(i)])
...
end
This block of code works as intended when I run it from within Matlab. However, when I compile the application and try to run it from Command Prompt, the program doesn't display the required data anymore. What seems to be the problem? Are there any other functions that could help me achieve the required result (i.e. displaying lines of text for the user)?
2.) For a number of variables, Code Analyzer gives me the following error (the program still works, but the variables are underlined in red):
"The temporary variable 'x' uses a value set outside of the PARFOR loop."
I know that for declaring the variable 'x', I am combining some data defined before the parfor loop and some data from within the loop (typically the iteration index). But what seems to be the problem?
3.) When building the deployed .exe file, I get the following warnings:
"The temporary variable 'y' will be cleared at the beginning of each
iteration of the parfor loop. Any value assigned to it before the loop will be lost."
I am well aware of this and it is OK with me, however, I don't know how to disable the warning. I tried using the warning('off, 'all'), but the warnings persist. What especially bothers me is the fact that these warnings are also displayed each time that I run the deployed application from Command Prompt.
4.) As a final question, I noticed that there is a huge difference in file size of the deployed application when I'm using the parfor loop compared to the case when I'm instead using a simple for loop. The application with the parfor loop is well over 8 MB in size, whereas the application with the for loop is only 400 kB. I guess that trying to compile the code for using parallel processing takes many more lines, but I'm interested in hearing more about this.
Thank you very much in advance for all the help!
5 commentaires
Richard Alcock
le 15 Jan 2013
I don't see those messages from those pieces of code either. I suspect there are other places in the large program that refer to some of the same variables as these smaller snippets, and it is these other uses that are causing the problem. My advice would be to break up the larger program into several smaller functions, where each function only has the variables it needs. This will at least make it easier to isolate the problems, and might make things completely clean.
Réponse acceptée
Richard Alcock
le 15 Jan 2013
1) The lack of display from inside the parfor loop is unfortunately a problem in the R2012b release of Parallel Computing Toolbox. I see the same thing on my computer. The development team are aware of the issue and are working on a fix for a future version.
If you are trying to show a progress through a long process you might be interested in one of the "parfor progress monitors" available on the File Exchange - see http://www.mathworks.co.uk/matlabcentral/fileexchange/index?term=parfor+progress.
2) and 3) As discussed in comments, as I can't reproduce the problem, I don't know exactly what to suggest. Try breaking code into smaller pieces.
4) When you are using parfor the application needs to include all the needed functions and other files to run your code in parallel on a MATLAB pool. The short version is that it is these files that increase the size of the application.
4 commentaires
Richard Alcock
le 22 Jan 2013
Thanks for the extra details. I can now reproduce both of these issues, and I've passed them onto the development team.
To workaround (2), you can try setting "show" to something that evaluates to false. Any other these seem to work for me:
show = false(1);
show = strcmp('yes', 'no');
show = 1<0;
Not ideal, but they do get rid of the warning!
For (3), an alternative to setting "y" at the start of the loop, is to use an if/elseif/else block instead of the switch/case/otherwise block.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!