I am working on a finite volume CFD code that operates on a triangular mesh. It loops over all edges between cells and adds or subtracts things from the values in the two adjacent cells to assemble the "flux" vector.
I am having a lot of trouble implementing this loop as a parfor loop because the loop variable is the edge number, but the assignment indices are the numbers of the neighboring cells. I've commented on the lines that don't work below.
flux = zeros(5,Nelem); % preallocate flux matrix
sdl = zeros(1,Nelem); % preallocate wavespeed matrix
% Loop over interior edges
parfor idxEdge = 1:NedgeInterior % Find L and R neighboring elements, their corresponding states, and the edge normal vector
% and length.
elemL = elemInterior(idxEdge,1); % cell number of left neighboring cell
UL = U(:,elemL); elemR = elemInterior(idxEdge,2); % cell number of right neighboring cell
UR = U(:,elemR); nEdge = normInterior(idxEdge,:); lEdge = lengthInterior(idxEdge); % Calculate flux over the edge
[F,smag] = calcFlux(UL,UR,nEdge); % Add edge flux contribution to element-wise net flux matrix
flux(:,elemL) = flux(:,elemL) + F.*lEdge; % doesn't work, Error: The variable flux in a parfor cannot be classified.
flux(:,elemR) = flux(:,elemR) - F.*lEdge; % doesn't work, Error: The variable flux in a parfor cannot be classified. % Add edge wave speed contribution to element-wise wave speed vector
sdl(elemL) = sdl(elemL) + smag.*lEdge; % doesn't work, Error: The variable sdl in a parfor cannot be classified.
sdl(elemR) = sdl(elemR) + smag.*lEdge; % doesn't work, Error: The variable sdl in a parfor cannot be classified. end
I know parfor doesn't like assignment indices that aren't loop indices, but I see no other way to structure the code. The loop index must be the edge number, but the assignment incides must be the neighboring cell numbers. Is there any workaround I could try to make this work?
Best Answer