Simultaneous/parallel tasks

Hi, this is my first spread and hope some feedbacks. I need to do the following tasks simultaneously. How can I use Matlab to achieve it? (1) Download data every second from a remote terminal/server. (2) Process the data to judge if the secondly updated data satisfy certain conditions or not. (3) When certain conditions are met, send commands to the remote terminal/server to operate tasks.

 采纳的回答

Walter Roberson
Walter Roberson 2015-9-7

0 个投票

You can use timer() objects to run a routine at periodic intervals.
You can download data in multiple ways, including ftp(); urlread(); the fairly new webread(); scp() from the File Exchange, or by using tcp() to request the data.
One difficulty you will need to deal with is that downloading the data may require more than one second. TCP connections retry when data packets are dropped, so TCP based requests can take an indefinite amount of time to return.
All of the ways I listed to download data can also be used to send commands to a server.

2 个评论

Walter, thank you for the answer. The hard part is that when step (2) and step(3) operated, it is very likely to be longer than 1 second. This might result in missing some observations that need to be downloaded in step (1). Can timer() solve this problem? Thanks!
timer() is not suitable for the case where the operating to execute takes longer than the period with which it is to execute.
I guess if you had the Parallel Computing Toolbox, you could use SPMD, with one lab running a timer and dispatching a "download and process" instruction to an available lab. You would need at least three workers, one controlling and two overlapping downloads. If your download is bandwidth limited rather than being limited by the amount of time the server "thinks about it" then the second download will slow down the first one, resulting in it being later. That could potentially push the download into requiring more than 2 seconds in which case you would need another worker yet.
If you are needing to poll every 1 second and you need to react to each individual download, then chances are that the instructions you execute should reflect the latest available information. But depending on how you analyze the data, if it takes longer than the poll interval to download the data, it could be that the second download has already downloaded an update that you should be taking into account. But whether you can pull out the new data depends on how the download is being done.

请先登录,再进行评论。

更多回答(1 个)

Guillaume
Guillaume 2015-9-7

0 个投票

Hum, you're describing a very sequential process (download -> process -> feedback). What exactly are you hoping to parallelise?
In any case, if you want to execute parallel tasks with matlab, you need the parallel toolbox. Without the toolbox it possibly could be achieved by deferring to Java, .Net, or mex but in that case you may as well write your entire code in Java, .Net, or C

1 个评论

Guillaume, thank you for the answer. Let me clarify here. I need to download the data every second, but it is very likely that the time for evaluation and operating commands (step (2) and (3)) might be longer than one second. I need that when Matlab code evaluate and operate commands, the data download code still download data every second. Do you have some suggestions?

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Downloads 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by