[yt-svn] commit/yt-3.0: MatthewTurk: Convert alloca's to malloc's and free's.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Aug 29 19:30:38 PDT 2013


1 new commit in yt-3.0:

https://bitbucket.org/yt_analysis/yt-3.0/commits/3aba7ca1ff0b/
Changeset:   3aba7ca1ff0b
Branch:      yt-3.0
User:        MatthewTurk
Date:        2013-08-30 04:18:22
Summary:     Convert alloca's to malloc's and free's.

For cases where ngrids is very large (octrees) the stack can get completely
blown out by allocating dynamically.  This changes to mallocs.
Affected #:  1 file

diff -r cff348ad309725c0296b9b8f04ddcf9aa022f779 -r 3aba7ca1ff0bebcbbcd8d1e2a526dea084e0fbdb yt/utilities/lib/amr_kdtools.pyx
--- a/yt/utilities/lib/amr_kdtools.pyx
+++ b/yt/utilities/lib/amr_kdtools.pyx
@@ -267,12 +267,12 @@
     The entire purpose of this function is to move everything from ndarrays
     to internal C pointers. 
     """
-    pgles = <np.float64_t **> alloca(ngrids * sizeof(np.float64_t*))
-    pgres = <np.float64_t **> alloca(ngrids * sizeof(np.float64_t*))
-    pgids = <np.int64_t *> alloca(ngrids * sizeof(np.int64_t))
+    pgles = <np.float64_t **> malloc(ngrids * sizeof(np.float64_t*))
+    pgres = <np.float64_t **> malloc(ngrids * sizeof(np.float64_t*))
+    pgids = <np.int64_t *> malloc(ngrids * sizeof(np.int64_t))
     for i in range(ngrids):
-        pgles[i] = <np.float64_t *> alloca(3 * sizeof(np.float64_t))
-        pgres[i] = <np.float64_t *> alloca(3 * sizeof(np.float64_t))
+        pgles[i] = <np.float64_t *> malloc(3 * sizeof(np.float64_t))
+        pgres[i] = <np.float64_t *> malloc(3 * sizeof(np.float64_t))
         pgids[i] = gids[i]
         for j in range(3):
             pgles[i][j] = gles[i, j]
@@ -280,6 +280,11 @@
 
     add_grids(node, ngrids, pgles, pgres, pgids, rank, size)
 
+    for i in range(ngrids):
+        free(pgles[i])
+        free(pgres[i])
+    free(pgles)
+    free(pgres)
 
  
 @cython.boundscheck(False)
@@ -553,22 +558,30 @@
     # Find a Split
     cdef int i, j, k
 
-    data = <np.float64_t ***> alloca(ngrids * sizeof(np.float64_t**))
+    data = <np.float64_t ***> malloc(ngrids * sizeof(np.float64_t**))
     for i in range(ngrids):
-        data[i] = <np.float64_t **> alloca(2 * sizeof(np.float64_t*))
+        data[i] = <np.float64_t **> malloc(2 * sizeof(np.float64_t*))
         for j in range(2):
-            data[i][j] = <np.float64_t *> alloca(3 * sizeof(np.float64_t))
+            data[i][j] = <np.float64_t *> malloc(3 * sizeof(np.float64_t))
         for j in range(3):
             data[i][0][j] = gles[i][j]
             data[i][1][j] = gres[i][j]
 
-    less_ids = <np.uint8_t *> alloca(ngrids * sizeof(np.uint8_t))
-    greater_ids = <np.uint8_t *> alloca(ngrids * sizeof(np.uint8_t))
+    less_ids = <np.uint8_t *> malloc(ngrids * sizeof(np.uint8_t))
+    greater_ids = <np.uint8_t *> malloc(ngrids * sizeof(np.uint8_t))
 
     best_dim, split_pos, nless, ngreater = \
         kdtree_get_choices(ngrids, data, node.left_edge, node.right_edge,
                           less_ids, greater_ids)
  
+    for i in range(ngrids):
+        for j in range(2):
+            free(data[i][j])
+        free(data[i])
+    free(data)
+    free(less_ids)
+    free(greater_ids)
+
     # If best_dim is -1, then we have found a place where there are no choices.
     # Exit out and set the node to None.
     if best_dim == -1:
@@ -579,8 +592,6 @@
     split.dim = best_dim
     split.pos = split_pos
 
-    #del data
-
     # Create a Split
     divide(node, split)

Repository URL: https://bitbucket.org/yt_analysis/yt-3.0/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list