Reading update of variable in parallel function?

조회 수: 3 (최근 30일)
E.B
E.B 2019년 8월 12일
댓글: Walter Roberson 2019년 8월 14일
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

채택된 답변

Walter Roberson
Walter Roberson 2019년 8월 12일
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
E.B
E.B 2019년 8월 13일
what i need to do .i can't implement with matlab.
or using matlab with another language?
Walter Roberson
Walter Roberson 2019년 8월 14일
We seem to be unable to figure out how to assist you in implementing your needs in MATLAB.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by