Changeset: ab8d4f0f7ff0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ab8d4f0f7ff0
Modified Files:
geom/monetdb5/geomBulk.c
Branch: sfcgal
Log Message:
OpenMP and BATiter are not friends. Make sure each thread has its own BATiter.
Still issues with C++ structures shared between threads, more to protect in
coming rounds. Fix errors messages and more leaks
diffs (truncated from 1464 to 300 lines):
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -23,7 +23,8 @@ geom_2_geom_bat(bat *outBAT_id, bat *inB
{
BAT *outBAT = NULL, *inBAT = NULL;
BUN p = 0, q = 0;
- BATiter inBAT_iter;
+ BATiter *inBAT_iters = NULL;
+ int numIters = 1, j = 0;
wkb **outs = NULL;
str msg = MAL_SUCCEED;
#ifdef GEOMBULK_DEBUG
@@ -41,9 +42,19 @@ geom_2_geom_bat(bat *outBAT_id, bat *inB
BBPunfix(inBAT->batCacheid);
throw(MAL, "batcalc.wkb", MAL_MALLOC_FAIL);
}
+#ifdef OPENMP
+ numIters = OPENCL_THREADS;
+#endif
//iterator over the BAT
- inBAT_iter = bat_iterator(inBAT);
+ if ( (inBAT_iters = (BATiter*) GDKmalloc(sizeof(BATiter)*numIters)) ==
NULL) {
+ BBPunfix(inBAT->batCacheid);
+ BBPunfix(outBAT->batCacheid);
+ throw(MAL, "batcalc.wkb", MAL_MALLOC_FAIL);
+ }
+ for (j = 0; j < numIters; j++) {
+ inBAT_iters[j] = bat_iterator(inBAT);
+ }
q = BUNlast(inBAT);
@@ -60,11 +71,16 @@ geom_2_geom_bat(bat *outBAT_id, bat *inB
for (p = 0; p < q; p++) {
str err = NULL;
wkb *inWKB = NULL, *outWKB = NULL;
+ int tNum = 0;
+
+#ifdef OPENMP
+ tNum = omp_get_thread_num();
+#endif
if (msg)
continue;
- inWKB = (wkb *) BUNtail(inBAT_iter, p);
+ inWKB = (wkb *) BUNtail(inBAT_iters[tNum], p);
if ((err = geom_2_geom(&outWKB, &inWKB, columnType,
columnSRID)) != MAL_SUCCEED) { //check type
msg = err;
#ifdef OPENMP
@@ -82,6 +98,7 @@ geom_2_geom_bat(bat *outBAT_id, bat *inB
#endif
BBPunfix(inBAT->batCacheid);
+ GDKfree(inBAT_iters);
if (msg != MAL_SUCCEED) {
BBPunfix(outBAT->batCacheid);
@@ -161,7 +178,8 @@ wkbCoordinateFromMBR_bat(bat *outBAT_id,
{
BAT *outBAT = NULL, *inBAT = NULL;
BUN p = 0, q = 0;
- BATiter inBAT_iter;
+ BATiter *inBAT_iters = NULL;
+ int numIters = 1, j = 0;
str msg = MAL_SUCCEED;
#ifdef GEOMBULK_DEBUG
static struct timeval start, stop;
@@ -179,9 +197,19 @@ wkbCoordinateFromMBR_bat(bat *outBAT_id,
BBPunfix(inBAT->batCacheid);
throw(MAL, "batgeom.coordinateFromMBR", MAL_MALLOC_FAIL);
}
+#ifdef OPENMP
+ numIters = OPENCL_THREADS;
+#endif
//iterator over the BAT
- inBAT_iter = bat_iterator(inBAT);
+ if ( (inBAT_iters = (BATiter*) GDKmalloc(sizeof(BATiter)*numIters)) ==
NULL) {
+ BBPunfix(inBAT->batCacheid);
+ BBPunfix(outBAT->batCacheid);
+ throw(MAL, "batcalc.wkb", MAL_MALLOC_FAIL);
+ }
+ for (j = 0; j < numIters; j++) {
+ inBAT_iters[j] = bat_iterator(inBAT);
+ }
q = BUNlast(inBAT);
#ifdef GEOMBULK_DEBUG
@@ -197,10 +225,16 @@ wkbCoordinateFromMBR_bat(bat *outBAT_id,
for (p = 0; p < q; p++) {
str err = NULL;
mbr *inMBR = NULL;
+ int tNum = 0;
+
+#ifdef OPENMP
+ tNum = omp_get_thread_num();
+#endif
+
if (msg)
continue;
- inMBR = (mbr *) BUNtail(inBAT_iter, p);
+ inMBR = (mbr *) BUNtail(inBAT_iters[tNum], p);
if ((err = wkbCoordinateFromMBR(&outs[p], &inMBR,
coordinateIdx)) != MAL_SUCCEED) {
msg = err;
#ifdef OPENMP
@@ -217,6 +251,7 @@ wkbCoordinateFromMBR_bat(bat *outBAT_id,
#endif
BBPunfix(inBAT->batCacheid);
+ GDKfree(inBAT_iters);
if (msg != MAL_SUCCEED) {
BBPunfix(outBAT->batCacheid);
@@ -298,7 +333,8 @@ WKBtoDBL_bat(bat *outBAT_id, bat *inBAT_
{
BAT *outBAT = NULL, *inBAT = NULL;
BUN p = 0, q = 0;
- BATiter inBAT_iter;
+ BATiter *inBAT_iters = NULL;
+ int numIters = 1, j = 0;
str msg = MAL_SUCCEED;
#ifdef GEOMBULK_DEBUG
static struct timeval start, stop;
@@ -316,10 +352,20 @@ WKBtoDBL_bat(bat *outBAT_id, bat *inBAT_
BBPunfix(inBAT->batCacheid);
throw(MAL, name, MAL_MALLOC_FAIL);
}
-
- //iterator over the input BAT
- inBAT_iter = bat_iterator(inBAT);
-
+#ifdef OPENMP
+ numIters = OPENCL_THREADS;
+#endif
+
+ //iterator over the BAT
+ if ( (inBAT_iters = (BATiter*) GDKmalloc(sizeof(BATiter)*numIters)) ==
NULL) {
+ BBPunfix(inBAT->batCacheid);
+ BBPunfix(outBAT->batCacheid);
+ throw(MAL, "batcalc.wkb", MAL_MALLOC_FAIL);
+ }
+ for (j = 0; j < numIters; j++) {
+ inBAT_iters[j] = bat_iterator(inBAT);
+ }
+
q = BUNlast(inBAT);
#ifdef GEOMBULK_DEBUG
gettimeofday(&start, NULL);
@@ -334,11 +380,16 @@ WKBtoDBL_bat(bat *outBAT_id, bat *inBAT_
for (p = 0; p < q; p++) {
str err = NULL;
wkb *inWKB = NULL;
- //double outSingle;
+ int tNum = 0;
+
+#ifdef OPENMP
+ tNum = omp_get_thread_num();
+#endif
+
if (msg)
continue;
- inWKB = (wkb *) BUNtail(inBAT_iter, p);
+ inWKB = (wkb *) BUNtail(inBAT_iters[tNum], p);
if ((err = (*func) (&outs[p], &inWKB)) != MAL_SUCCEED) {
msg = err;
#ifdef OPENMP
@@ -355,6 +406,7 @@ WKBtoDBL_bat(bat *outBAT_id, bat *inBAT_
#endif
BBPunfix(inBAT->batCacheid);
+ GDKfree(inBAT_iters);
if (msg != MAL_SUCCEED) {
BBPunfix(outBAT->batCacheid);
@@ -385,7 +437,8 @@ WKBtoWKB_bat(bat *outBAT_id, bat *inBAT_
{
BAT *outBAT = NULL, *inBAT = NULL;
BUN p = 0, q = 0;
- BATiter inBAT_iter;
+ BATiter *inBAT_iters = NULL;
+ int numIters = 1, j = 0;
wkb **outs = NULL;
str msg = MAL_SUCCEED;
#ifdef GEOMBULK_DEBUG
@@ -403,10 +456,20 @@ WKBtoWKB_bat(bat *outBAT_id, bat *inBAT_
BBPunfix(inBAT->batCacheid);
throw(MAL, name, MAL_MALLOC_FAIL);
}
-
- //iterator over the input BAT
- inBAT_iter = bat_iterator(inBAT);
-
+#ifdef OPENMP
+ numIters = OPENCL_THREADS;
+#endif
+
+ //iterator over the BAT
+ if ( (inBAT_iters = (BATiter*) GDKmalloc(sizeof(BATiter)*numIters)) ==
NULL) {
+ BBPunfix(inBAT->batCacheid);
+ BBPunfix(outBAT->batCacheid);
+ throw(MAL, name, MAL_MALLOC_FAIL);
+ }
+ for (j = 0; j < numIters; j++) {
+ inBAT_iters[j] = bat_iterator(inBAT);
+ }
+
q = BUNlast(inBAT);
#ifdef GEOMBULK_DEBUG
gettimeofday(&start, NULL);
@@ -422,10 +485,16 @@ WKBtoWKB_bat(bat *outBAT_id, bat *inBAT_
str err = NULL;
wkb *outSingle;
wkb *inWKB = NULL;
+ int tNum = 0;
+
+#ifdef OPENMP
+ tNum = omp_get_thread_num();
+#endif
+
if (msg)
continue;
- inWKB = (wkb *) BUNtail(inBAT_iter, p);
+ inWKB = (wkb *) BUNtail(inBAT_iters[tNum], p);
if ((err = (*func) (&outSingle, &inWKB)) != MAL_SUCCEED) {
msg = err;
#ifdef OPENMP
@@ -443,6 +512,7 @@ WKBtoWKB_bat(bat *outBAT_id, bat *inBAT_
#endif
BBPunfix(inBAT->batCacheid);
+ GDKfree(inBAT_iters);
if (msg != MAL_SUCCEED) {
BBPunfix(outBAT->batCacheid);
@@ -492,7 +562,8 @@ WKBtoWKBflagINT_bat(bat *outBAT_id, bat
{
BAT *outBAT = NULL, *inBAT = NULL;
BUN p = 0, q = 0;
- BATiter inBAT_iter;
+ BATiter *inBAT_iters = NULL;
+ int numIters = 1, j = 0;
wkb **outs = NULL;
str msg = MAL_SUCCEED;
#ifdef GEOMBULK_DEBUG
@@ -510,9 +581,19 @@ WKBtoWKBflagINT_bat(bat *outBAT_id, bat
BBPunfix(inBAT->batCacheid);
throw(MAL, name, MAL_MALLOC_FAIL);
}
-
- //iterator over the input BAT
- inBAT_iter = bat_iterator(inBAT);
+#ifdef OPENMP
+ numIters = OPENCL_THREADS;
+#endif
+
+ //iterator over the BAT
+ if ( (inBAT_iters = (BATiter*) GDKmalloc(sizeof(BATiter)*numIters)) ==
NULL) {
+ BBPunfix(inBAT->batCacheid);
+ BBPunfix(outBAT->batCacheid);
+ throw(MAL, name, MAL_MALLOC_FAIL);
+ }
+ for (j = 0; j < numIters; j++) {
+ inBAT_iters[j] = bat_iterator(inBAT);
+ }
q = BUNlast(inBAT);
#ifdef GEOMBULK_DEBUG
@@ -529,10 +610,16 @@ WKBtoWKBflagINT_bat(bat *outBAT_id, bat
str err = NULL;
wkb *outSingle;
wkb *inWKB = NULL;
+ int tNum = 0;
+
+#ifdef OPENMP
+ tNum = omp_get_thread_num();
+#endif
+
if (msg)
continue;
- inWKB = (wkb *) BUNtail(inBAT_iter, p);
+ inWKB = (wkb *) BUNtail(inBAT_iters[tNum], p);
if ((err = (*func) (&outSingle, &inWKB, flag)) != MAL_SUCCEED) {
msg = err;
#ifdef OPENMP
@@ -550,6 +637,7 @@ WKBtoWKBflagINT_bat(bat *outBAT_id, bat
#endif
BBPunfix(inBAT->batCacheid);
+ GDKfree(inBAT_iters);
if (msg != MAL_SUCCEED) {
BBPunfix(outBAT->batCacheid);
@@ -605,7 +693,8 @@ WKBtoWKBflagDBL_bat(bat *outBAT_id, bat
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list