gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 336ddee 04/19: Error in `match_kdtree_worker`


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 336ddee 04/19: Error in `match_kdtree_worker` in lib/match.c
Date: Sun, 14 Nov 2021 20:40:58 -0500 (EST)

branch: master
commit 336ddee7178e5b2f71ce440a9b1baccb1fcfeda3
Author: Sachin Kumar Singh <sachinkumarsingh092@gmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Error in `match_kdtree_worker` in lib/match.c
    
    A segmentation falut occurs during the execution of tests/during-dev.sh
    which is traced back to `gal_pointer_alloc` in `match_kdtree_worker` in
    lib/match.c.
---
 bin/match/match.c    | 11 +++++++++--
 lib/gnuastro/match.h |  6 +++++-
 lib/match.c          | 14 +++++++++++++-
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/bin/match/match.c b/bin/match/match.c
index a8a2bbe..cf94b15 100644
--- a/bin/match/match.c
+++ b/bin/match/match.c
@@ -32,6 +32,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/table.h>
 #include <gnuastro/kdtree.h>
 #include <gnuastro/pointer.h>
+#include <gnuastro/threads.h>
 #include <gnuastro/permutation.h>
 
 #include <gnuastro-internal/checkset.h>
@@ -500,7 +501,10 @@ match_catalog_kdtree_auto(struct matchparams *p)
 static gal_data_t *
 match_catalog_kdtree(struct matchparams *p)
 {
+  size_t root;
   gal_data_t *out=NULL;
+  gal_data_t *kdtree=NULL;
+  size_t numthreads = gal_threads_number();
 
   /* If we are in automatic mode, we should look at the data (number of
      rows/columns) and system (number of threads) to decide if the mode
@@ -518,8 +522,11 @@ match_catalog_kdtree(struct matchparams *p)
 
     /* Do the k-d tree matching. */
     case MATCH_KDTREE_INTERNAL:
-      error(EXIT_FAILURE, 0, "%s: internal kd tree usage not "
-            "yet implemented", __func__);
+      kdtree = gal_kdtree_create(p->cols1, &root);
+      out = gal_match_kdtree(p->cols1, p->cols2, kdtree, root,
+                             p->aperture->array, numthreads,
+                             p->cp.minmapsize, p->cp.quietmmap);
+      gal_list_data_free(kdtree);
       break;
 
     /* No 'default' necessary because the modes include disabling. */
diff --git a/lib/gnuastro/match.h b/lib/gnuastro/match.h
index aa1a7c6..b35d918 100644
--- a/lib/gnuastro/match.h
+++ b/lib/gnuastro/match.h
@@ -51,7 +51,11 @@ gal_match_coordinates(gal_data_t *coord1, gal_data_t *coord2,
                       size_t *nummatched);
 
 
-
+gal_data_t *
+gal_match_kdtree(gal_data_t *coord1, gal_data_t *coord2,
+                 gal_data_t *coord1_kdtree, size_t kdtree_root,
+                 double *aperture, size_t numthreads, size_t minmapsize,
+                 int quietmmap);
 
 
 __END_C_DECLS    /* From C++ preparations */
diff --git a/lib/match.c b/lib/match.c
index 4497788..ff60fa5 100644
--- a/lib/match.c
+++ b/lib/match.c
@@ -1006,7 +1006,7 @@ match_kdtree_worker(void *in_prm)
 
   /* High level definitions. */
   gal_data_t *ccol;
-  double *point, least_dist;
+  double *point=NULL, least_dist;
   size_t i, j, index, mindex;
 
   /* Allocate space for all the matching points (based on the number of
@@ -1020,8 +1020,12 @@ match_kdtree_worker(void *in_prm)
       /* Fill the 'point' for this thread. */
       j=0;
       index = tprm->indexs[i];
+      printf("%s: index = %zu point = %g ccol = %g\n", __func__, index, 
point[0], ((double *)(p->coord2->array))[index]);
       for(ccol=p->coord2; ccol!=NULL; ccol=ccol->next)
+        {
         point[ j++ ] = ((double *)(ccol->array))[index];
+          printf("%s: point: %g\n", __func__, point[j]);
+        }
 
       /* Find the index of the nearest neighbor to this item. */
       mindex=gal_kdtree_nearest_neighbour(p->coord1, p->coord1_kdtree,
@@ -1088,6 +1092,14 @@ gal_match_kdtree(gal_data_t *coord1, gal_data_t *coord2,
   p.c2match=c2match->array;
   p.kdtree_root=kdtree_root;
   p.coord1_kdtree=coord1_kdtree;
+  
+  /** NUMBER OF ARGUMENTS IS INCORRECT BUT COMPILER FINDS IT TO BE FINE **/
   gal_threads_spin_off(match_kdtree_worker, &p, coord2->size, numthreads,
                        minmapsize, quietmmap);
+
+  for (int i = 0; i < coord2->size; ++i)
+    printf("%s: size of c2match = %zu", __func__, p.c2match[i]);
+
+  exit(0);
+  return c2match;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]