Trying to read text file inside parfor loop versus passing it as a parameter

조회 수: 7 (최근 30일)
I have a couple txt/csv files that contain upward to 5000 lines. Each line contains information that I intend to read in as input to a function inside parfor loop. Is it best if I read the text files as a matrix/struct/etc. and the parfor loop can access the information from said matrix/struct? Or is it better have the part that read files inside the parfor loop?
  댓글 수: 3
Giang Le
Giang Le 2020년 3월 24일
Same file! The file basically contains multiple lines. Each line is a set of different parameters/function input.
Mohammad Sami
Mohammad Sami 2020년 3월 24일
편집: Mohammad Sami 2020년 3월 24일
I suggest just load it once before parfor loop. As long as each loop is not modifying the contents, it should be fine.

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

채택된 답변

Rashed Mohammed
Rashed Mohammed 2020년 5월 19일
Hi Giang Le,
Assuming that you are trying to call a function with its parameters read from a file parallelly. However, using IO functions inside parfor loop can be slow. Hence as suggested by Sami, read the data before hand using readmatrix and then pass the content as parameters to function parallelly using parfor.
Hope this helps!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by