Changeset: 8bec7e8b0201 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8bec7e8b0201 Modified Files: geom/monetdb5/geom.c Branch: sfcgal Log Message:
Major revision of the filter join code. Clean Error messages, make sure you release everything you allocate. Verify if all memory allocations succeed. Proper handle of empty BATs. Make it ready to use OpenMP diffs (truncated from 1471 to 300 lines): diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c --- a/geom/monetdb5/geom.c +++ b/geom/monetdb5/geom.c @@ -8130,11 +8130,8 @@ WKBWKBtoBITsubjoin_intern(bat *lres, bat GEOSGeom *rGeometries = NULL; mbr **rMBRs = NULL; int *rSRIDs = NULL; - str msg = NULL; -#ifdef GEOMBULK_DEBUG - static struct timeval start, stop; - unsigned long long t; -#endif + str msg = MAL_SUCCEED; + bit* outs = NULL; if( (bl= BATdescriptor(*lid)) == NULL ) throw(MAL, name, RUNTIME_OBJECT_MISSING); @@ -8159,43 +8156,78 @@ WKBWKBtoBITsubjoin_intern(bat *lres, bat throw(MAL, name, MAL_MALLOC_FAIL); } + if ( !BATcount(br) || !BATcount(bl)) { + BBPunfix(*lid); + BBPunfix(*rid); + BBPkeepref(*lres = xl->batCacheid); + BBPkeepref(*rres = xr->batCacheid); + return MAL_SUCCEED; + } + /*iterator over the BATs*/ lBAT_iter = bat_iterator(bl); rBAT_iter = bat_iterator(br); /*Get the Geometry for the inner BAT*/ - rGeometries = (GEOSGeom*) GDKzalloc(sizeof(GEOSGeom) * BATcount(br)); - rMBRs = (mbr**) GDKzalloc(sizeof(mbr*) * BATcount(br)); - rSRIDs = (int*) GDKzalloc(sizeof(int) * BATcount(br)); + if ( (rGeometries = (GEOSGeom*) GDKzalloc(sizeof(GEOSGeom) * BATcount(br))) == NULL) { + BBPunfix(*lid); + BBPunfix(*rid); + BBPunfix(xl->batCacheid); + BBPunfix(xr->batCacheid); + throw(MAL, name, MAL_MALLOC_FAIL); + } + if ( (rMBRs = (mbr**) GDKzalloc(sizeof(mbr*) * BATcount(br))) == NULL) { + GDKfree(rGeometries); + BBPunfix(*lid); + BBPunfix(*rid); + BBPunfix(xl->batCacheid); + BBPunfix(xr->batCacheid); + throw(MAL, name, MAL_MALLOC_FAIL); + } + if ( (rSRIDs = (int*) GDKzalloc(sizeof(int) * BATcount(br))) == NULL) { + GDKfree(rGeometries); + GDKfree(rMBRs); + BBPunfix(*lid); + BBPunfix(*rid); + BBPunfix(xl->batCacheid); + BBPunfix(xr->batCacheid); + throw(MAL, name, MAL_MALLOC_FAIL); + } BATloop(br, pr, qr) { wkb *rWKB = (wkb *) BUNtail(rBAT_iter, pr); rGeometries[pr] = wkb2geos(rWKB); - if ( !rGeometries[pr] ) { - BBPunfix(*lid); - BBPunfix(*rid); - BBPunfix(xl->batCacheid); - BBPunfix(xr->batCacheid); - throw(MAL, name, "wkb2geos failed"); + if (!rGeometries[pr] ) { + for (j = 0; j < pr-1;j++) { + GEOSGeom_destroy(rGeometries[j]); + } + msg = createException(MAL, name, "wkb2geos failed"); + break; } rMBRs[pr] = mbrFromGeos(rGeometries[pr]); if (rMBRs[pr] == NULL || mbr_isnil(rMBRs[pr])) { - for (j = 0; j < BATcount(br);j++) { + for (j = 0; j < pr;j++) { GEOSGeom_destroy(rGeometries[j]); } - GDKfree(rMBRs); - GDKfree(rSRIDs); - GDKfree(rGeometries); - BBPunfix(*lid); - BBPunfix(*rid); - BBPunfix(xl->batCacheid); - BBPunfix(xr->batCacheid); - throw(MAL, name, "Failed to create mbrFromGeos"); + msg = createException(MAL, name, "Failed to create mbrFromGeos"); + return msg; } rSRIDs[pr] = GEOSGetSRID(rGeometries[pr]); } - - omp_set_dynamic(OPENCL_DYNAMIC); // Explicitly disable dynamic teams - omp_set_num_threads(OPENCL_THREADS); + if ( (msg ==MAL_SUCCEED) && BATcount(br) && (outs = (bit*) GDKzalloc(sizeof(bit)*BATcount(br))) == NULL) { + msg = createException(MAL, name, MAL_MALLOC_FAIL); + } + + if (msg != MAL_SUCCEED) { + GDKfree(rMBRs); + GDKfree(rSRIDs); + GDKfree(rGeometries); + BBPunfix(*lid); + BBPunfix(*rid); + BBPunfix(xl->batCacheid); + BBPunfix(xr->batCacheid); + return msg; + } + lo = bl->hseqbase; BATloop(bl, pl, ql) { str err = NULL; @@ -8208,110 +8240,68 @@ WKBWKBtoBITsubjoin_intern(bat *lres, bat lWKB = (wkb *) BUNtail(lBAT_iter, pl); lGeometry = wkb2geos(lWKB); if ( !lGeometry ) { - for (j = 0; j < pl;j++) { - GEOSGeom_destroy(rGeometries[j]); - } - GDKfree(rMBRs); - GDKfree(rSRIDs); - GDKfree(rGeometries); - BBPunfix(*lid); - BBPunfix(*rid); - BBPunfix(xl->batCacheid); - BBPunfix(xr->batCacheid); - throw(MAL, name, "wkb2geos failed"); + msg = createException(MAL, name, "wkb2geos failed"); + break; } + lSRID = GEOSGetSRID(lGeometry); lMBR = mbrFromGeos(lGeometry); if (lMBR == NULL || mbr_isnil(lMBR)) { - for (j = 0; j < BATcount(br);j++) { - GEOSGeom_destroy(rGeometries[j]); - } - GDKfree(rMBRs); - GDKfree(rSRIDs); - GDKfree(rGeometries); - BBPunfix(*lid); - BBPunfix(*rid); - BBPunfix(xl->batCacheid); - BBPunfix(xr->batCacheid); - throw(MAL, name, "mbrFromGeos failed"); + GEOSGeom_destroy(lGeometry); + msg = createException(MAL, name, "mbrFromGeos failed"); + break; } - lSRID = GEOSGetSRID(lGeometry); - -#ifdef GEOMBULK_DEBUG - fprintf(stdout, "%s %d %d %d\n", name, pl, ql, BATcount(br)); - gettimeofday(&start, NULL); -#endif - for (j = 0; j < BATcount(br); j++, ro++) { - bit out = 0; + + //for (j = 0; j < BATcount(br); j++, ro++) { + omp_set_dynamic(OPENCL_DYNAMIC); // Explicitly disable dynamic teams + omp_set_num_threads(OPENCL_THREADS); + //#pragma omp parallel for + for (j = 0; j < BATcount(br); j++) { mbr *rMBR = NULL; GEOSGeom rGeometry = rGeometries[j]; - - if (!lGeometry ||!rGeometry) { - msg = createException(MAL, name, "One of the geometries is NULL"); - break; - } - - //if (GEOSGetSRID(lGeometry) != GEOSGetSRID(rGeometry)) { - //if (GEOSGetSRID(lGeometry) != rSRIDs[j]) { + outs[j] = 0; + + if (msg != MAL_SUCCEED) + continue; + if (lSRID != rSRIDs[j]) { msg = createException(MAL, name, "Geometries of different SRID"); break; } - /* - err = mbrOverlaps(&out, &lMBR, &rMBRs[j]); - if (err != MAL_SUCCEED) { - msg = err; - break; - } else if (out) { - */ rMBR = rMBRs[j]; - if ((out = !((rMBR)->ymax < (lMBR)->ymin || + if ((outs[j] = !((rMBR)->ymax < (lMBR)->ymin || (rMBR)->ymin > (lMBR)->ymax || (rMBR)->xmax < (lMBR)->xmin || (rMBR)->xmin > (lMBR)->xmax))) { - out = 0; - //if ((out = GEOSIntersects(lGeometry, rGeometry)) == 2){ - if ((out = (*func)(lGeometry, rGeometry)) == 2){ - msg = createException(MAL, name, "GEOSIntersects failed"); + outs[j] = 0; + if ((outs[j] = (*func)(lGeometry, rGeometry)) == 2){ + msg = createException(MAL, name, "%s failed", name); + //#pragma omp cancelregion break; } - if (out) { - BUNappend(xl, &lo, FALSE); - BUNappend(xr, &ro, FALSE); - } } - //GDKfree(rMBR); - } - - if (msg) { - if (lGeometry) - GEOSGeom_destroy(lGeometry); - for (j = 0; j < BATcount(br);j++) { - GEOSGeom_destroy(rGeometries[j]); - } - GDKfree(rMBRs); - GDKfree(rSRIDs); - GDKfree(rGeometries); - BBPunfix(*lid); - BBPunfix(*rid); - BBPunfix(xl->batCacheid); - BBPunfix(xr->batCacheid); - return msg; } if (lGeometry) GEOSGeom_destroy(lGeometry); GDKfree(lMBR); + + if (msg != MAL_SUCCEED) + break; + + for (j = 0; j < BATcount(br); j++ , ro++) { + bit out = outs[j]; + if (out == 1) { + BUNappend(xl, &lo, FALSE); + BUNappend(xr, &ro, FALSE); + outs[j] = 0; + } + } lo++; - -#ifdef GEOMBULK_DEBUG - gettimeofday(&stop, NULL); - t = 1000 * (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec) / 1000; - fprintf(stdout, "%s %llu ms\n", name, t); -#endif - } - + } + if (outs) + GDKfree(outs); if (rGeometries) { for (j = 0; j < BATcount(br);j++) { GEOSGeom_destroy(rGeometries[j]); @@ -8322,17 +8312,18 @@ WKBWKBtoBITsubjoin_intern(bat *lres, bat GDKfree(rMBRs); if (rSRIDs) GDKfree(rSRIDs); - /* - BATrmprops(xl) - BATsettrivprop(xl); - BATrmprops(xr) - BATsettrivprop(xr); - */ BBPunfix(*lid); BBPunfix(*rid); - BBPkeepref(*lres = xl->batCacheid); - BBPkeepref(*rres = xr->batCacheid); - return MAL_SUCCEED; + + if (msg != MAL_SUCCEED) { + BBPunfix(xl->batCacheid); + BBPunfix(xr->batCacheid); + } else { + BBPkeepref(*lres = xl->batCacheid); + BBPkeepref(*rres = xr->batCacheid); + } + + return msg; } str @@ -8358,6 +8349,7 @@ Containssubjoin(bat *lres, bat *rres, ba static str IntersectsXYZsubjoin_intern(bat *lres, bat *rres, bat *lid, bat *xid, bat*yid, bat *zid, int *srid) { + str msg = MAL_SUCCEED; BAT *xl, *xr, *bl, *bx, *by, *bz; oid lo, ro; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list