Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Apr 2009 12:45:56 +0200
From:      =?ISO-8859-1?Q?Fran=E7ois_Deli=E8ge?= <fdeliege@gmail.com>
To:        freebsd-threads@freebsd.org
Subject:   SPI openmp parallel critical
Message-ID:  <92c2d900904020345x1541daefy85705fa049b54d8e@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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. :-)

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

Cheers,

Francois



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?92c2d900904020345x1541daefy85705fa049b54d8e>