Commits

Peter Shinners  committed 3600156

narrowing in on the problems when using chunks

  • Participants
  • Parent commits 8901e94

Comments (0)

Files changed (3)

     hood->chunks = (numPoints + NRNRCHUNK - 1) / NRNRCHUNK;
     hood->indices = (index_t*)(hood + 1);
     hood->nextIndices = hood->indices + numPoints * 3;
-//printf("numchunks: %zu\n", hood->chunks);
 
     // Allocate temporary buffer for storing the inverse sorted array
     // Find inverse mappifng to sort index (point to index)
     if (inverseSize > numPoints) {
         inverseSize = numPoints;
     }
-    index_t* inverse = malloc(sizeof(index_t) * inverseSize);
+    index_t* inverse = (index_t*)malloc(sizeof(index_t) * inverseSize);
 
     // Break the data into small chunks
     index_t* chunkIndices = hood->indices;
         if (chunkSize > NRNRCHUNK) {
             chunkSize = NRNRCHUNK;
         }
-//printf("  create chunk %zu  size=%zu\n", c, chunkSize);
 
         // Initialize indices with list of all points
         for (index_t i = 0; i < chunkSize; ++i) {
             for (index_t i = 0; i < chunkSize; ++i) {
                 next[i] = inverse[ind[i]];
             }
-
 //printf("        next %zu:", d); for (size_t z=0; z < chunkSize; ++z) printf(" %zu", next[z]); printf("\n");
         }
 
     }
 
     free(inverse);
+
     return hood;
 }
 
 
 struct NrNrHood* NrNrFreeNeighborhood(struct NrNrHood* hood) {
-    if (!hood) {
+    if (hood) {
         free(hood);
     }
     return NULL;
 #include <inttypes.h>
 
 
-#define NRNRCHUNK 20000000
+#define NRNRCHUNK 6
 
 
 typedef size_t index_t;
 #include <time.h>
 
 
-#define DOCHECKS 0
+#define DOCHECKS 1
 
 
 float GetTime(void);
     // Create random points
 
     srand(1234);
-    size_t numPoints = 10000000;
+    size_t numPoints = 180;
     start = GetTime();
     float* points = (float*)malloc(sizeof(float) * 3 * numPoints);
 	for(size_t i=0; i<numPoints; i++) {
 		p[0] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
 		p[1] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
 		p[2] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
-		p[3] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
         //printf("  pt %zu: %.1f %.1f %.1f\n",i, p[0], p[1], p[2]);
     }
 	//printf("Create random points (%zu): %.3f sec\n", numPoints, GetTime() - start);
 	printf("Create neighborhood: %.3f sec\n", GetTime() - start);
 
     // Search block
-
     start = GetTime();
     float minPos[3] = {-40.0f,-20.0f,-60.0f};
     float maxPos[3] = { 40.0,  60.0f, 20.0f};
-    //printf("Searching: %.1f - %.1f,  %.1f - %.1f, %.1f - %.1f\n", minPos[0], maxPos[0], minPos[1], maxPos[1], minPos[2],maxPos[2]);
+    printf("Searching: %.1f - %.1f,  %.1f - %.1f, %.1f - %.1f\n", minPos[0], maxPos[0], minPos[1], maxPos[1], minPos[2],maxPos[2]);
 
     size_t* results;
     size_t count = NrNrSearchBlock(hood, &results, minPos, maxPos);
     printf("Search complete %zu: %.3f sec\n", count, GetTime() - start);
 
-#if 0
+#if 1
 for(size_t z = 0; z < count; ++z) {
     float* pos = points + results[z] * 3;
     printf("  found %zu: %.1f %.1f %.1f\n", results[z], pos[0], pos[1], pos[2]);
     // Cleanup
 
     start = GetTime();
-    free(points);
     results = NrNrFreeResults(results);
+
+    free(points);
     hood = NrNrFreeNeighborhood(hood);
     printf("Cleanup: %.3f sec\n", GetTime() - start);
 
 
 
 void CheckSearch(struct NrNrHood* hood, size_t numResults, const size_t* results, const float* minimum, const float* maximum) {
+    int foundError = 0;
     for (size_t i = 0; i < hood->numPoints; ++i) {
         const float* pos = hood->points + i * hood->dimensions;
         int inside = 1;
             }
         }
         if (inside && !inresults) {
-            printf("Error with results, points should be inside: index=%zu, %.2f %.2f %.2f\n", i,
+            printf("Error with results, points should be inside: index=%zu, %.1f %.1f %.1f\n", i,
                         hood->points[i * hood->dimensions], hood->points[i * hood->dimensions + 1], hood->points[i * hood->dimensions + 2]);
-            exit(1);
+            foundError = 1;
         } else if (!inside && inresults) {
-            printf("Error with results, points should not be inside: index=%zu, %.2f %.2f %.2f\n", i,
+            printf("Error with results, points should not be inside: index=%zu, %.1f %.1f %.1f\n", i,
                         hood->points[i * hood->dimensions], hood->points[i * hood->dimensions + 1], hood->points[i * hood->dimensions + 2]);
-            exit(1);
+            foundError = 1;
         }
     }
+    if (foundError) {
+        exit(1);
+    }
 }