Changeset: 6bd80247ea50 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6bd80247ea50 Modified Files: geom/monetdb5/geomBulk.c Branch: sfcgal Log Message:
OpenMP for most of the Bulk operators diffs (truncated from 969 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 @@ -13,6 +13,10 @@ #include "geom.h" #include <omp.h> +#define GEOMBULK_DEBUG 0 +#define OPENCL_DYNAMIC 0 +#define OPENCL_THREADS 1 + /*******************************/ /********** One input **********/ /*******************************/ @@ -21,9 +25,14 @@ str geom_2_geom_bat(bat *outBAT_id, bat *inBAT_id, int *columnType, int *columnSRID) { BAT *outBAT = NULL, *inBAT = NULL; - wkb *inWKB = NULL, *outWKB = NULL; BUN p = 0, q = 0; BATiter inBAT_iter; + wkb **outs = NULL; + str msg = MAL_SUCCEED; +#ifdef GEOMBULK_DEBUG + static struct timeval start, stop; + unsigned long long t; +#endif //get the descriptor of the BAT if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) { @@ -38,30 +47,67 @@ geom_2_geom_bat(bat *outBAT_id, bat *inB //iterator over the BAT inBAT_iter = bat_iterator(inBAT); - //for (i = 0; i < BATcount(inBAT); i++) { - BATloop(inBAT, p, q) { //iterate over all valid elements + + omp_set_dynamic(OPENCL_DYNAMIC); // Explicitly disable dynamic teams + omp_set_num_threads(OPENCL_THREADS); + q = BUNlast(inBAT); +#ifdef GEOMBULK_DEBUG + fprintf(stdout, "batcalc.wkb %d %d\n", p, q); + gettimeofday(&start, NULL); +#endif + outs = (wkb**) GDKmalloc(sizeof(wkb*) * BATcount(inBAT)); + //BATloop(inBAT, p, q) { //iterate over all valid elements + #pragma omp parallel for + for (p = 0; p < q; p++) { str err = NULL; + wkb *inWKB = NULL, *outWKB = NULL; //if for used --> inWKB = (wkb *) BUNtail(inBATi, i + BUNfirst(inBAT)); inWKB = (wkb *) BUNtail(inBAT_iter, p); if ((err = geom_2_geom(&outWKB, &inWKB, columnType, columnSRID)) != MAL_SUCCEED) { //check type - BBPunfix(inBAT->batCacheid); - BBPunfix(outBAT->batCacheid); - return err; + msg = err; + #pragma omp cancelregion } - BUNappend(outBAT, outWKB, TRUE); //add the point to the new BAT - GDKfree(outWKB); - outWKB = NULL; + outs[p] = outWKB; + //BUNappend(outBAT, outWKB, TRUE); //add the point to the new BAT + //GDKfree(outWKB); + //outWKB = NULL; } +#ifdef GEOMBULK_DEBUG + gettimeofday(&stop, NULL); + t = 1000 * (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec) / 1000; + fprintf(stdout, "batcalc.wkb %llu ms\n", t); +#endif - //set some properties of the new BAT + BBPunfix(inBAT->batCacheid); + + if (msg != MAL_SUCCEED) { + BBPunfix(outBAT->batCacheid); + return msg; + } + +#ifdef GEOMBULK_DEBUG + gettimeofday(&start, NULL); +#endif + for (p = 0; p < q; p++) { + BUNappend(outBAT, outs[p], TRUE); //add the point to the new BAT + GDKfree(outs[p]); + outs[p] = NULL; + } + + if (outs) + GDKfree(outs); +#ifdef GEOMBULK_DEBUG + gettimeofday(&stop, NULL); + t = 1000 * (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec) / 1000; + fprintf(stdout, "batcalc.wkb BUNappend %llu ms\n", t); +#endif + BATsetcount(outBAT, BATcount(inBAT)); - BATsettrivprop(outBAT); BATderiveProps(outBAT, FALSE); - BBPunfix(inBAT->batCacheid); BBPkeepref(*outBAT_id = outBAT->batCacheid); + return MAL_SUCCEED; - } /*create WKB from WKT */ @@ -118,9 +164,14 @@ wkbCoordinateFromMBR_bat(bat *outBAT_id, { BAT *outBAT = NULL, *inBAT = NULL; mbr *inMBR = NULL; - double outDbl = 0.0; BUN p = 0, q = 0; BATiter inBAT_iter; + str msg = MAL_SUCCEED; +#ifdef GEOMBULK_DEBUG + static struct timeval start, stop; + unsigned long long t; +#endif + double *outs; //get the descriptor of the BAT if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) { @@ -135,26 +186,50 @@ wkbCoordinateFromMBR_bat(bat *outBAT_id, //iterator over the BAT inBAT_iter = bat_iterator(inBAT); - BATloop(inBAT, p, q) { //iterate over all valid elements + + omp_set_dynamic(OPENCL_DYNAMIC); // Explicitly disable dynamic teams + omp_set_num_threads(OPENCL_THREADS); + q = BUNlast(inBAT); +#ifdef GEOMBULK_DEBUG + fprintf(stdout, "batgeom.coordinateFromMBR %d %d\n", p, q); + gettimeofday(&start, NULL); +#endif + //BATloop(inBAT, p, q) { //iterate over all valid elements + outs = (double*) Tloc(outBAT, 0); + #pragma omp parallel for + //BATloop(inBAT, p, q) { //iterate over all valid elements + for (p = 0; p < q; p++) { str err = NULL; + //double outDbl = 0.0; inMBR = (mbr *) BUNtail(inBAT_iter, p); - if ((err = wkbCoordinateFromMBR(&outDbl, &inMBR, coordinateIdx)) != MAL_SUCCEED) { - BBPunfix(inBAT->batCacheid); - BBPunfix(outBAT->batCacheid); - return err; + //if ((err = wkbCoordinateFromMBR(&outDbl, &inMBR, coordinateIdx)) != MAL_SUCCEED) { + if ((err = wkbCoordinateFromMBR(&outs[p], &inMBR, coordinateIdx)) != MAL_SUCCEED) { + msg = err; + #pragma omp cancelregion } - BUNappend(outBAT, &outDbl, TRUE); + //BUNappend(outBAT, &outDbl, TRUE); } +#ifdef GEOMBULK_DEBUG + gettimeofday(&stop, NULL); + t = 1000 * (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec) / 1000; + fprintf(stdout, "batgeom.coordinateFromMBR %llu ms\n", t); +#endif + + BBPunfix(inBAT->batCacheid); + + if (msg != MAL_SUCCEED) { + BBPunfix(outBAT->batCacheid); + return msg; + } //set some properties of the new BAT BATsetcount(outBAT, BATcount(inBAT)); BATsettrivprop(outBAT); - BATderiveProps(outBAT, FALSE); - BBPunfix(inBAT->batCacheid); + //BATderiveProps(outBAT, FALSE); BBPkeepref(*outBAT_id = outBAT->batCacheid); + return MAL_SUCCEED; - } /**************************************************************************/ @@ -228,8 +303,11 @@ WKBtoDBL_bat(bat *outBAT_id, bat *inBAT_ BUN p = 0, q = 0; BATiter inBAT_iter; str msg = MAL_SUCCEED; +#ifdef GEOMBULK_DEBUG static struct timeval start, stop; unsigned long long t; +#endif + double *outs; //get the descriptor of the BAT if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) { @@ -245,38 +323,44 @@ WKBtoDBL_bat(bat *outBAT_id, bat *inBAT_ //iterator over the input BAT inBAT_iter = bat_iterator(inBAT); - omp_set_dynamic(0); // Explicitly disable dynamic teams - omp_set_num_threads(1); + omp_set_dynamic(OPENCL_DYNAMIC); // Explicitly disable dynamic teams + omp_set_num_threads(OPENCL_THREADS); q = BUNlast(inBAT); - fprintf(stdout, "%d %d\n", p, q); +#ifdef GEOMBULK_DEBUG + fprintf(stdout, "%s %d %d\n", name, p, q); gettimeofday(&start, NULL); +#endif //BATloop(inBAT, p, q) { //iterate over all valid elements + outs = (double*) Tloc(outBAT, 0); #pragma omp parallel for for (p = 0; p < q; p++) { str err = NULL; wkb *inWKB = NULL; - double outSingle; + //double outSingle; inWKB = (wkb *) BUNtail(inBAT_iter, p); - if ((err = (*func) (&outSingle, &inWKB)) != MAL_SUCCEED) { + //if ((err = (*func) (&outSingle, &inWKB)) != MAL_SUCCEED) { + if ((err = (*func) (&outs[p], &inWKB)) != MAL_SUCCEED) { msg = err; #pragma omp cancelregion } - BUNappend(outBAT, &outSingle, TRUE); //add the result to the new BAT + //BUNappend(outBAT, &outSingle, TRUE); //add the result to the new BAT } +#ifdef GEOMBULK_DEBUG gettimeofday(&stop, NULL); t = 1000 * (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec) / 1000; - fprintf(stdout, "%llu ms\n", t); + fprintf(stdout, "%s %llu ms\n", name, t); +#endif + + BBPunfix(inBAT->batCacheid); if (msg != MAL_SUCCEED) { - BBPunfix(inBAT->batCacheid); BBPunfix(outBAT->batCacheid); return msg; } - //set the number of elements in the outBAT + BATsetcount(outBAT, BATcount(inBAT)); - - BBPunfix(inBAT->batCacheid); + BATderiveProps(outBAT, FALSE); BBPkeepref(*outBAT_id = outBAT->batCacheid); return MAL_SUCCEED; @@ -300,6 +384,12 @@ WKBtoWKB_bat(bat *outBAT_id, bat *inBAT_ wkb *inWKB = NULL; BUN p = 0, q = 0; BATiter inBAT_iter; + wkb **outs = NULL; + str msg = MAL_SUCCEED; +#ifdef GEOMBULK_DEBUG + static struct timeval start, stop; + unsigned long long t; +#endif //get the descriptor of the BAT if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) { @@ -314,25 +404,64 @@ WKBtoWKB_bat(bat *outBAT_id, bat *inBAT_ //iterator over the input BAT inBAT_iter = bat_iterator(inBAT); - BATloop(inBAT, p, q) { //iterate over all valid elements + + omp_set_dynamic(OPENCL_DYNAMIC); // Explicitly disable dynamic teams + omp_set_num_threads(OPENCL_THREADS); + q = BUNlast(inBAT); +#ifdef GEOMBULK_DEBUG + fprintf(stdout, "%s %d %d\n", name, p, q); + gettimeofday(&start, NULL); +#endif + outs = (wkb**) GDKmalloc(sizeof(wkb*) * BATcount(inBAT)); + //BATloop(inBAT, p, q) { //iterate over all valid elements + #pragma omp parallel for + for (p = 0; p < q; p++) { str err = NULL; wkb *outSingle; inWKB = (wkb *) BUNtail(inBAT_iter, p); if ((err = (*func) (&outSingle, &inWKB)) != MAL_SUCCEED) { - BBPunfix(inBAT->batCacheid); - BBPunfix(outBAT->batCacheid); - return err; + msg = err; + #pragma omp cancelregion } - BUNappend(outBAT, outSingle, TRUE); //add the result to the new BAT - GDKfree(outSingle); - outSingle = NULL; + outs[p] = outSingle; + //BUNappend(outBAT, outSingle, TRUE); //add the result to the new BAT _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list