Hi Everyone,
Is it possible to run two different programs simultaneously using the parallel computing toolbox, where one function is dependent on constantly updating the result of the other?
I have implemented a TCP server receiving data from a micro-controller using the java libraries within MATLAB which works well. I now need to do some computations of varied length on the most recent data set which has arrived, and my proposed solution to this is a First In First Out buffer in my server function which is updating as fast as the data arrives and is readable by my main function.
I have looked at the documentation and examples for matlabpool, parfor, spmd, batch etc. but I am not sure if any of these allow me to run two different programs with shared data.
Any advice would be greatly appreciated, or indeed suggestions of other solutions to this problem. I have included my server code in case it helps.
if true function [DMat] = ServerInit()
import java.net.Socket.* import java.net.SocketChannel.* import java.io.* import java.nio.* import java.io.DataInputStream.* import java.nio.channels.*; import java.net.*; import java.util.Scanner; %Declare host, port and retries
host=''; port=10001; number_of_retries = 1; % set to -1 for infinite
current_retry = 0; while true%Keep track of connection attempts
current_retry = current_retry + 1; if ((number_of_retries > 0) && (current_retry > number_of_retries)) fprintf(1, 'Too many retries\n'); break; end try % throws if unable to connect
fprintf(1, 'Retry %d connecting to %s:%d\n', ... current_retry, host, port); %Set-up and accept new connection
Server_socket = java.net.ServerSocket(port); Client_sock = Server_socket.accept(); %Set up data input stream called Scan
Scan=Scanner(Client_sock.getInputStream()); %Read next line (delimeter \n)
Data=Scan.nextLine(); remain=char(Data); for x=1:1:95 [token,remain]=strtok(remain,','); DMat(y,x)=str2double(token); end break; catch Server_socket.close() Client_sock.close() %pause before retrying
pause(1); end endend end
Best Answer