diff options
author | rhaas <rhaas@c83d129a-5a75-4d5a-9c4d-ed3a5855bf45> | 2013-08-13 14:56:11 +0000 |
---|---|---|
committer | rhaas <rhaas@c83d129a-5a75-4d5a-9c4d-ed3a5855bf45> | 2013-08-13 14:56:11 +0000 |
commit | 82e680ff56a16092478c0561514ab0d7cc0e5f3f (patch) | |
tree | cab427a2c21b5e3832ecd7e4cb523f5999fa2310 | |
parent | f9736f2be8a25428a0b913604ac5d36c5b1cde7f (diff) |
GRHydro: avoid allocating large arrays on the stack
From: Roland Haas <rhaas@tapir.caltech.edu>
git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinEvolve/GRHydro/trunk@568 c83d129a-5a75-4d5a-9c4d-ed3a5855bf45
-rw-r--r-- | src/GRHydro_Prim2Con.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/GRHydro_Prim2Con.c b/src/GRHydro_Prim2Con.c index 36578b0..b3c59be 100644 --- a/src/GRHydro_Prim2Con.c +++ b/src/GRHydro_Prim2Con.c @@ -69,8 +69,9 @@ void Primitive2ConservativeC(CCTK_ARGUMENTS) // 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 @@ void Primitive2ConservativeC(CCTK_ARGUMENTS) 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 @@ void Primitive2ConservativeC(CCTK_ARGUMENTS) 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 @@ void Primitive2ConservativeC(CCTK_ARGUMENTS) } } // for i, i<n error checking } + free(keyerr); } // end branch for no temp reconsturction } // end of evolve temper branch |