From b0ee12aa8f2f7f1c9f3b0c6d996bb7a5a2eb11bc Mon Sep 17 00:00:00 2001 From: Oliver Hahn Date: Wed, 12 Feb 2014 22:53:39 +0100 Subject: [PATCH 1/2] fixed an overflow error in random number generation for very large grids --- random.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/random.cc b/random.cc index d4de057..0d3831c 100644 --- a/random.cc +++ b/random.cc @@ -241,6 +241,7 @@ random_numbers::random_numbers( unsigned res, unsigned cubesize, long basesee LOGINFO("Generating random numbers (2) with seed %ld", baseseed); double mean = 0.0; + size_t res_l = res; bool musicnoise = true; if( !musicnoise ) @@ -271,7 +272,7 @@ random_numbers::random_numbers( unsigned res, unsigned cubesize, long basesee for( unsigned k=0; k::random_numbers( unsigned res, std::string randfname, bool ran LOGINFO("Random number file \'%s\'\n contains %ld numbers. Reading...",randfname.c_str(),nx*ny*nz); - double sum = 0.0, sum2 = 0.0; - unsigned count = 0; + long double sum = 0.0, sum2 = 0.0; + size_t count = 0; //perform actual reading if( vartype == 4 ) @@ -495,8 +496,8 @@ random_numbers::random_numbers( /*const*/ random_numbers & rc, bool kdegra //if( res > rc.m_res || (res/rc.m_res)%2 != 0 ) // throw std::runtime_error("Invalid restriction in random number container copy constructor."); - double sum = 0.0, sum2 = 0.0; - unsigned count = 0; + long double sum = 0.0, sum2 = 0.0; + size_t count = 0; if( kdegrade ) { From e276a8a15c485f8dcb7165fc244353dbdb375808 Mon Sep 17 00:00:00 2001 From: Oliver Hahn Date: Tue, 25 Feb 2014 18:32:28 +0100 Subject: [PATCH 2/2] fix to TIPSY output plugin when running with baryons also added more verbose error messages to TIPSY plugin --- plugins/output_tipsy.cc | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/plugins/output_tipsy.cc b/plugins/output_tipsy.cc index 85e0392..3f1a73d 100644 --- a/plugins/output_tipsy.cc +++ b/plugins/output_tipsy.cc @@ -764,15 +764,18 @@ public: for( unsigned j=0; jsize(1); ++j ) for( unsigned k=0; ksize(2); ++k ) { - if( temp_dat.size() < block_buf_size_ ) - temp_dat.push_back( pmass ); - else - { - ofs_temp.write( (char*)&temp_dat[0], sizeof(T_store)*block_buf_size_ ); - nwritten += block_buf_size_; - temp_dat.clear(); - temp_dat.push_back( pmass ); - } + if( gh.is_in_mask(ilevel,i,j,k) && !gh.is_refined(ilevel,i,j,k) ) + { + if( temp_dat.size() < block_buf_size_ ) + temp_dat.push_back( pmass ); + else + { + ofs_temp.write( (char*)&temp_dat[0], sizeof(T_store)*block_buf_size_ ); + nwritten += block_buf_size_; + temp_dat.clear(); + temp_dat.push_back( pmass ); + } + } } if( temp_dat.size() > 0 ) @@ -781,13 +784,17 @@ public: nwritten+=temp_dat.size(); } - if( nwritten != nptot ) - throw std::runtime_error("Internal consistency error while writing temporary file for baryon masses"); - + if( nwritten != nptot ){ + LOGERR("TIPSY output plugin wrote %ld gas particles, should have %ld", nwritten, nptot); + throw std::runtime_error("Internal consistency error while writing temporary file for baryon masses"); + } + ofs_temp.write( (char *)&blksize, sizeof(size_t) ); - if( ofs_temp.bad() ) - throw std::runtime_error("I/O error while writing temporary file for baryon masses"); + if( ofs_temp.bad() ){ + LOGERR("I/O error while writing temporary file for baryon masse"); + throw std::runtime_error("I/O error while writing temporary file for baryon masses"); + } } }