Reading update of variable in parallel function?

5 views (last 30 days)
I need to implement two function in parallel but one of them reads update value of another function .
Details:
i read CSV file " 200" row as stream data (sensor data) in matrix and at same time another function need to read updated matrix
both need to be simulated in parallel
Two parallel function will be implemented
1- function read() read each raw from file in matrix "Datachunk1"
2- function( out ) has if condition
"if condition" will implement sequentional with another function and take too much time than function read
"else condition" will need to read updated matrix Datachunk1" 50 raw" at a time do operations then deleted them from matrix .this process continue till reading all 200 raw."4 chunks"
i have matlab >2016 i didn't try parallel function before.
part of code
function read()
fid = fopen('t.csv');
filename = fullfile(pwd, 't.csv');
while(i ~=200)
i = i + 1;
next_line = fgetl(fid);
D=Datachunk1;
Datachunk1=cell2mat(textscan(next_line,'%f %f %f %f','Delimiter', ',','CollectOutput', true))
Datachunk1=[D;Datachunk1];
end
end
function out(inputs,position)
if position==0
call by another function
/*do some operations
end
else
Datachunk1
/*do some operations in Datachunk1
end
end

Accepted Answer

Walter Roberson
Walter Roberson on 12 Aug 2019
You have several options:
  1. instead of parfor use spmd. spmd permits you to use labSend to send data to another worker
  2. you can carefully arrange a series of three parallel queue objects such that you can send data from one worker back to the client, and then have the client send it to the other worker (the workers cannot communicate directly for this purpose)
  3. you can look in the File Exchange for the Shared Matrix contribution
  4. you can use a shared file, especially if you use memory map (but that is not strictly needed)
When the second worker goes to delete items out of the matrix, that is going to be a problem, as most of these methods will not reflect the deletion back to the first worker. Matlab arrays always live in exactly one process, and the memory management routines are not able to allocate or deallocate on a different process.
  14 Comments
E.B
E.B on 13 Aug 2019
what i need to do .i can't implement with matlab.
or using matlab with another language?
Walter Roberson
Walter Roberson on 14 Aug 2019
We seem to be unable to figure out how to assist you in implementing your needs in MATLAB.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!