SPI openmp parallel critical

François Deliège fdeliege at gmail.com
Thu Apr 2 04:16:11 PDT 2009

Hi list,

I am writing a C user defined function that is loading values obtained from
an SPI table and that has to perform some operation on each of these
values.  The values are binary and have a variable size.  Since CPU is a
bottleneck and since I have multiple cores, I would like the operations to
be performed in parallel. Everything goes fine if I define as a critical
segment the part where I get the data from tuptable.

However, if I remove the critical section I get this error:
ERROR:  lock 53 is not held
I don't always get the error, but it always crashes if I start to have a few
values in the SPI table.

I would like to eliminate that critical section.  Any advice ?
I guess someone else already ran in this kind of problem. :-)

ret = SPI_execute(command, 1, 0);
proc = SPI_processed;
#pragma omp parallel for shared(proc, SPI_tuptable ) private( mydata,
for (j = 0; j < proc; j++) {
    // returns datum from the first element
    #pragma omp critical  // would like to eliminate this
    { mydata = (mydatatype
SPI_tuptable->tupdesc, 1, &isnull)); }
    ... // do something with mydata



More information about the freebsd-threads mailing list