Azzera filtri
Azzera filtri

How to make command line free while a program rans?

9 visualizzazioni (ultimi 30 giorni)
Imagine, I made a program that contineously executes loop FOR-END (a Watch, for example). I'd like to run another program while the first one is still running. However, the command line >> is busy. How to "free" it?
Of course, this is the problem of parallel computing. I am a newbile in it now. As far as I learned, there are several ways to start parallelization, either ">> pmode start" or ">> pool = parpool(2)". (I have two 'Workers').
Do I follow the right way?
After ">> pmode start" we get two-splitted Window with Lab1 and Lab2. How to submit a job to only one of them?
Looking forward,
  7 Commenti
Yevgeny Gayev
Yevgeny Gayev il 29 Ago 2019
Yes, I know this, and tried this, thanks.
I guess however that it is somewhat illegal. Besides, I try to learn and exploit MATLAB's power in parallelization, and this was an example. Documentation about the parallelization is huge and difficult, and do not correspond exactly to what I am looking for.
Generally, two ways for parallelization are known, two or more threads on the same processor, and splitting task to several processors if present. I am speaking mainly about the first way.
Thanks to all the discussing experts!
Stephen23 il 29 Ago 2019
Modificato: Stephen23 il 29 Ago 2019
"Do you mean to make a GUI-envelope, Stephen?"
I have no idea what a "GUI-envelope" is.
I often use graphics callbacks to run code, thus keeping the command line "free" for me to do other things. Of course this requires writing a small GUI, but that is not very difficult.
"I tried this way, no succes."
As you did not show what you tried it is difficult for us to help you fix it.
"May be, I should use OOP-features in MATLAB?"
I don't see how OOP is related to the topic you are asking about.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 29 Ago 2019
The only way to "free the command line" in MATLAB is to run your code with a timer, or in response to a callback (such as as a serial port bytes available function). The function that is run must return fairly soon, as the command line would not process commands while the function is running.
pmode does not free the command line. None of the facilities in the Parallel Computing Toolbox free the command line.
In some situations what is needed is not that the command line be freed, but instead that the user be able to trigger interactions while the code is running. In such cases it may be possible to build a GUI that has buttons or controls that allow parameters to be configured and then to trigger an action, with the action being executed in the context of a callback for the graphics object. For this to work, the main looping code that is executing must cooperate, by periodically permitting any pending callbacks to be executed, by calling pause() or drawnow() or waitfor() or uiwait()
  1 Commento
Yevgeny Gayev
Yevgeny Gayev il 30 Ago 2019
" by periodically permitting any pending callbacks to be executed, by calling pause() or drawnow() or waitfor() or uiwait()" -- this suggestion sounds promissing, thanks!

Accedi per commentare.

Più risposte (3)

Jason Ross
Jason Ross il 29 Ago 2019
You can use the batch function to send work to a parallel worker and then retrieve the results later. While the batch job is running, the command prompt is freed. If you want to send the job to only one worker you can specify that in the batch command.

Chidvi Modala
Chidvi Modala il 29 Ago 2019
To submit a job to only one of the window, pmode is not the best fit. The commands you type at the pmode prompt in the Parallel Command Window are executed on all workers at the same time.
You can refer to following link to get more information

Yevgeny Gayev
Yevgeny Gayev il 30 Ago 2019
Dear experts, unfortunately, I have no chance to continue this discussion immediately, because I am busy with our new study year starting now. But I certainly come to this problem somewhat later. However, few comments right now.
“no idea what a "GUI-envelope" is" -- Sorry, Stephen for my English!
I had in mind that most intellect is usually invested in the program. The GUI, I guess, is an envelope only to make the program friendly, nice and pretty like a sweet.
"I don't see how OOP is related to the topic".
I had in mind the following. To do other things when MATLAB-instance is busy with loops and iterations of their current task (like in the Watch program suggested as an example), we need to run another execution thread, thus to use parallelization like in Java. Perhaps, some interruption points are to be foreseen in the program. It is my hope that such a feature has been foreseen in the MATLAB OOP. May be, I am wrong.
Thanks to all the commentators!
  2 Commenti
Yevgeny Gayev
Yevgeny Gayev il 17 Set 2019
Dear experts, I'd like to thank Walter Roberson who suggested: "The only way to "free the command line" in MATLAB is to run your code with a timer".
Yes, I tried this way and it looks promising, what I had in mind.
Indeed, the TIMER object allows scheduling several tasks to MATLAB. However, I met several unclear problems, like "You cannot set the read-only property 'executionmode' of timer". Unfortunately, features of this object have not been sufficiently explained.
Perhaps, the object TIMER runs one of several execution threads, like Thread class or Runnable interface in Java. Where can I find more information about this?
Walter Roberson
Walter Roberson il 17 Set 2019
Timers can interrupt the currently executing code at the end of any line of MATLAB code. They do not use a different thread for execution of the MATLAB code. It is not impossible that there is a different thread associated with scheduling them -- that would be an internal detail not exposed to the user.
You cannot set executionmode of a timer that is started. To change the execution mode of a timer, you must stop() the timer.

Accedi per commentare.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by