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

18 visualizaciones (últimos 30 días)
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 comentarios
Giang Le
Giang Le el 24 de Mzo. de 2020
Same file! The file basically contains multiple lines. Each line is a set of different parameters/function input.
Mohammad Sami
Mohammad Sami el 24 de Mzo. de 2020
Editada: Mohammad Sami el 24 de Mzo. de 2020
I suggest just load it once before parfor loop. As long as each loop is not modifying the contents, it should be fine.

Iniciar sesión para comentar.

Respuesta aceptada

Rashed Mohammed
Rashed Mohammed el 19 de Mayo de 2020
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!

Más respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by