[Commits] [svn:einsteintoolkit] GRHydro/trunk/src/ (Rev. 568)

rhaas at tapir.caltech.edu rhaas at tapir.caltech.edu
Tue Aug 13 09:56:11 CDT 2013


User: rhaas
Date: 2013/08/13 09:56 AM

Modified:
 /trunk/src/
  GRHydro_Prim2Con.c

Log:
 GRHydro: avoid allocating large arrays on the stack
 
 From: Roland Haas <rhaas at tapir.caltech.edu>

File Changes:

Directory: /trunk/src/
======================

File [modified]: GRHydro_Prim2Con.c
Delta lines: +12 -8
===================================================================
--- trunk/src/GRHydro_Prim2Con.c	2013-08-13 14:56:08 UTC (rev 567)
+++ trunk/src/GRHydro_Prim2Con.c	2013-08-13 14:56:11 UTC (rev 568)
@@ -69,8 +69,9 @@
 
    // EOS calls (now GF-wide)
    if(!*evolve_temper) {
-     int n = cctk_lsh[0]*cctk_lsh[1]*cctk_lsh[2];
-     int keyerr[n]; int anyerr = 0;
+     int n = cctk_ash[0]*cctk_ash[1]*cctk_ash[2];
+     int *keyerr = malloc(sizeof(*keyerr)*n);
+     int anyerr = 0;
      int keytemp = 0;
 
      // don't need special error handling for analytic EOS
@@ -80,12 +81,12 @@
      EOS_Omni_pressOMP(*GRHydro_eos_handle,keytemp,GRHydro_eos_rf_prec,n,
 		    rhoplus,epsplus,NULL,NULL,pressplus,keyerr,&anyerr);
      
+     free(keyerr);
    } else {
      if(reconstruct_temper) {
-       int n = cctk_lsh[0]*cctk_lsh[1]*cctk_lsh[2];
-       // Linux usually offers ~8MB of stack which is good for ~1M points.
-       // We should consider malloc() if we ever smash the stack.
-       int keyerr[n]; int anyerr = 0;
+       int n = cctk_ash[0]*cctk_ash[1]*cctk_ash[2];
+       int *keyerr = malloc(sizeof(*keyerr)*n);
+       int anyerr = 0;
        int keytemp = 1;
 
        // ensure Y_e and temperature within bounds
@@ -140,10 +141,12 @@
 	 CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,
 		    "Aborting!");
        }
+       free(keyerr);
      } else {
        // ******************** EPS RECONSTRUCTION BRANCH ******************
-       int n = cctk_lsh[0]*cctk_lsh[1]*cctk_lsh[2];
-       int keyerr[n]; int anyerr = 0;
+       int n = cctk_ash[0]*cctk_ash[1]*cctk_ash[2];
+       int *keyerr = malloc(sizeof(*keyerr)*n);
+       int anyerr = 0;
        int keytemp = 0;
 
        // ensure Y_e and temperature within bounds
@@ -236,6 +239,7 @@
 	   }
 	 } // for i, i<n error checking
        }
+       free(keyerr);
      } // end branch for no temp reconsturction
    } // end of evolve temper branch
 



More information about the Commits mailing list