# [Liboil] Gauss-Seidel optimisation

Mattijs Janssens m.janssens at opencfd.co.uk
Wed Jan 2 11:26:07 PST 2008

```Hello,

one of my inner loops does a Gauss-Seidel iteration using indirect addressing.
Is it possible to use liboil to optimise this?

I have been thinking about using oil_permute_xxx to collect the data in a
straight array before doing the calculation but this of course then becomes

My current algorithm loops over all the cells (=columns). Per cell it looks up
the neighbouring cells and corresponding face (as start and end index into an
addressing array; compact row storage). The two bottlenecks are the indirect
addressing in the 'accumulation' and 'distribution' phase.

- accumulation: get a coefficient from a face and a value from a cell
(indirect addressing) and multiply. Store in local variable.

- distribution: get a coefficient from a face, multiply with local variable
and store in cell (indirect addressing).

Below is the actual code:

for (register label cellI=0; cellI<nCells; cellI++)
{
// Start and end of this row
fStart = fEnd;
fEnd = ownStartPtr[cellI + 1];

// Get the accumulated neighbour side
curPsi = bPrimePtr[cellI];

// Accumulate the owner product side
for (register label curFace=fStart; curFace<fEnd; curFace++)
{
curPsi -= upperPtr[curFace]*psiPtr[uPtr[curFace]];
}

// Finish current psi
curPsi /= diagPtr[cellI];

// Distribute the neighbour side using current psi
for (register label curFace=fStart; curFace<fEnd; curFace++)
{
bPrimePtr[uPtr[curFace]] -= lowerPtr[curFace]*curPsi;
}

psiPtr[cellI] = curPsi;
}

--

Mattijs Janssens

OpenCFD Ltd.