How can i read data from a text file with parfor or spmd .i have to read as two workers and to combine the result lastly.please reply soon..
Show older comments
How can i read data from a text file with parfor or spmd .i have to read as two workers and to combine the result lastly.please reply soon..
Answers (1)
Edric Ellis
on 21 Jun 2013
Something like this?
spmd
fh = fopen(sprintf('file_%d.txt', labindex), 'rt');
data = fscanf(fh, '%f');
fclose(fh);
gcat(data, 1); % GCAT combines the data
end
2 Comments
shyni
on 22 Jun 2013
Edric Ellis
on 24 Jun 2013
Looks like your file name is incorrect. You could try adding
spmd
fname = sprintf(...);
fh = fopen(fname, 'rt');
if fh == -1
error('Could not read file: %s', fname);
end
...
end
This will indicate which file couldn't be found.
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!