필터 지우기
필터 지우기

parfor and persistent variables

조회 수: 3 (최근 30일)
H R
H R 2017년 6월 1일
답변: Walter Roberson 2017년 6월 1일
Dear all,
I have a matlab function that accepts a set of parameters say (query array), generates a unique input data (text) file and calls an external program to execute based on the generated input data file. The function then returns the results of the exe program. I would like to run this function as many times but also i would like to generate unique input files for each iteration (for instance X1.data, X2.data, X3.data,...) and I would like to keep track of the input parameters, generated data files and the function output.
The way that I do it, I use a for loop and define a persistent variable count inside the matlab function. Therefore, each time the function is called I assign a new integer (1, 2, 3,... to the generated date files e.g. X1.data X2.data, X3.data,...). In addition, I have a global stramwriter that writes the function input parameters and the the outputs into a text file one after each other.
I would like to use parfor for this exercise, however, I know that persistent variables will not be unique between the workers and also my global streamwriter would not work properly. Do you have any idea how to generate these unique data files and record the matlab function input-outputs using parfor?
I'd appreciate your comments.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 6월 1일
If you have R2017a or later, consider using the new parallel data queue, perhaps together with afterEach

카테고리

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