From fea2dcc0d5261fb42fa4c094675a6208b5d70681 Mon Sep 17 00:00:00 2001 From: CGH0S7 <776459475@qq.com> Date: Thu, 7 May 2026 16:47:55 +0800 Subject: [PATCH] Fix BSSN-EM runtime crash --- AMSS_NCKU_source/ABE.C | 20 ++++++------ AMSS_NCKU_source/Z4c_class.C | 22 +++++++------ AMSS_NCKU_source/bssnEM_class.C | 34 ++++++++----------- AMSS_NCKU_source/bssnEScalar_class.C | 22 +++++++------ AMSS_NCKU_source/bssn_class.C | 7 ++-- AMSS_NCKU_source/checkpoint.C | 47 +++++++++++++------------- AMSS_NCKU_source/monitor.C | 49 +++++++++++++++------------- 7 files changed, 103 insertions(+), 98 deletions(-) diff --git a/AMSS_NCKU_source/ABE.C b/AMSS_NCKU_source/ABE.C index 82a30fe..ba2b0c4 100644 --- a/AMSS_NCKU_source/ABE.C +++ b/AMSS_NCKU_source/ABE.C @@ -198,16 +198,16 @@ int main(int argc, char *argv[]) if (myrank == 0) { string out_dir; - char filename[50]; - map::iterator iter; - iter = parameters::str_par.find("output dir"); - if (iter != parameters::str_par.end()) - { - out_dir = iter->second; - } - sprintf(filename, "%s/setting.par", out_dir.c_str()); - ofstream setfile; - setfile.open(filename, ios::trunc); + string filename; + map::iterator iter; + iter = parameters::str_par.find("output dir"); + if (iter != parameters::str_par.end()) + { + out_dir = iter->second; + } + filename = out_dir + "/setting.par"; + ofstream setfile; + setfile.open(filename.c_str(), ios::trunc); if (!setfile.good()) { diff --git a/AMSS_NCKU_source/Z4c_class.C b/AMSS_NCKU_source/Z4c_class.C index 38930d3..b306cc4 100644 --- a/AMSS_NCKU_source/Z4c_class.C +++ b/AMSS_NCKU_source/Z4c_class.C @@ -1,9 +1,10 @@ #ifdef newc -#include -#include -#include -using namespace std; +#include +#include +#include +#include +using namespace std; #else #include #include @@ -3257,12 +3258,13 @@ void Z4c_class::Interp_Constraint() } } - ofstream outfile; - char filename[50]; - sprintf(filename, "%s/interp_constraint_%05d.dat", ErrorMonitor->out_dir.c_str(), int(PhysTime / dT + 0.5)); - // 0.5 for round off - - outfile.open(filename); + ofstream outfile; + char suffix[64]; + sprintf(suffix, "/interp_constraint_%05d.dat", int(PhysTime / dT + 0.5)); + string filename = ErrorMonitor->out_dir + suffix; + // 0.5 for round off + + outfile.open(filename.c_str()); outfile << "# corrdinate, H_Res, Px_Res, Py_Res, Pz_Res, Gx_Res, Gy_Res, Gz_Res, ...." << endl; for (int i = 0; i < n; i++) { diff --git a/AMSS_NCKU_source/bssnEM_class.C b/AMSS_NCKU_source/bssnEM_class.C index 1adb720..1076709 100644 --- a/AMSS_NCKU_source/bssnEM_class.C +++ b/AMSS_NCKU_source/bssnEM_class.C @@ -4,7 +4,8 @@ #include #include #include -using namespace std; +#include +using namespace std; #else #include #include @@ -330,13 +331,15 @@ bool bssn_em_cuda_keep_resident_after_step(int lev, int trfls_in, int analysis_l static int keep_all_levels = -1; if (keep_all_levels < 0) { - const char *env = getenv("AMSS_CUDA_KEEP_ALL_LEVELS"); + const char *env = getenv("AMSS_CUDA_EM_KEEP_ALL_LEVELS"); keep_all_levels = (env && atoi(env) != 0) ? 1 : 0; } static int enabled = -1; if (enabled < 0) { - const char *env = getenv("AMSS_CUDA_KEEP_RESIDENT_AFTER_STEP"); + const char *env = getenv("AMSS_CUDA_EM_KEEP_RESIDENT_AFTER_STEP"); + if (!env) + env = getenv("AMSS_CUDA_KEEP_RESIDENT_AFTER_STEP"); enabled = (env && atoi(env) != 0) ? 1 : 0; } if (!enabled) @@ -2334,17 +2337,7 @@ void bssnEM_class::Step(int lev, int YN) em_t0 = MPI_Wtime(); const bool needs_resident_download = !bssn_em_cuda_keep_resident_after_step(lev, trfls, a_lev); - const bool skip_zero_resident_download = - needs_resident_download && - bssn_em_zero_resident_download_fastpath_enabled() && - bssn_em_resident_zero_fastpath_ready(GH->PatL[lev], -#ifdef WithShell - 0, -#else - 0, -#endif - myrank); - if (needs_resident_download && !skip_zero_resident_download) + if (needs_resident_download) bssn_em_cuda_download_level_state(GH->PatL[lev], SynchList_cor, myrank, true); if (em_step_timing) em_t_resident += MPI_Wtime() - em_t0; @@ -2951,12 +2944,13 @@ void bssnEM_class::Interp_Constraint() } } - ofstream outfile; - char filename[50]; - sprintf(filename, "%s/interp_constraint_%05d.dat", ErrorMonitor->out_dir.c_str(), int(PhysTime / dT + 0.5)); - // 0.5 for round off - - outfile.open(filename); + ofstream outfile; + char suffix[64]; + sprintf(suffix, "/interp_constraint_%05d.dat", int(PhysTime / dT + 0.5)); + string filename = ErrorMonitor->out_dir + suffix; + // 0.5 for round off + + outfile.open(filename.c_str()); outfile << "# corrdinate, H_Res, Px_Res, Py_Res, Pz_Res, Gx_Res, Gy_Res, Gz_Res, ...." << endl; for (int i = 0; i < n; i++) { diff --git a/AMSS_NCKU_source/bssnEScalar_class.C b/AMSS_NCKU_source/bssnEScalar_class.C index cd85057..8de5829 100644 --- a/AMSS_NCKU_source/bssnEScalar_class.C +++ b/AMSS_NCKU_source/bssnEScalar_class.C @@ -1,9 +1,10 @@ #ifdef newc -#include -#include -#include -using namespace std; +#include +#include +#include +#include +using namespace std; #else #include #include @@ -2522,12 +2523,13 @@ void bssnEScalar_class::Interp_Constraint() } } - ofstream outfile; - char filename[50]; - sprintf(filename, "%s/interp_constraint_%05d.dat", ErrorMonitor->out_dir.c_str(), int(PhysTime / dT + 0.5)); - // 0.5 for round off - - outfile.open(filename); + ofstream outfile; + char suffix[64]; + sprintf(suffix, "/interp_constraint_%05d.dat", int(PhysTime / dT + 0.5)); + string filename = ErrorMonitor->out_dir + suffix; + // 0.5 for round off + + outfile.open(filename.c_str()); outfile << "# corrdinate, H_Res, Px_Res, Py_Res, Pz_Res, Gx_Res, Gy_Res, Gz_Res, fR_Res, ...." << endl; for (int i = 0; i < n; i++) { diff --git a/AMSS_NCKU_source/bssn_class.C b/AMSS_NCKU_source/bssn_class.C index cb042e7..3dc56e4 100644 --- a/AMSS_NCKU_source/bssn_class.C +++ b/AMSS_NCKU_source/bssn_class.C @@ -9665,11 +9665,12 @@ void bssn_class::Interp_Constraint(bool infg) if (myrank == 0) { ofstream outfile; - char filename[50]; - sprintf(filename, "%s/interp_constraint_%05d.dat", ErrorMonitor->out_dir.c_str(), int(PhysTime / dT + 0.5)); + char suffix[64]; + sprintf(suffix, "/interp_constraint_%05d.dat", int(PhysTime / dT + 0.5)); + string filename = ErrorMonitor->out_dir + suffix; // 0.5 for round off - outfile.open(filename); + outfile.open(filename.c_str()); outfile << "# corrdinate, H_Res, Px_Res, Py_Res, Pz_Res, Gx_Res, Gy_Res, Gz_Res, ...." << endl; for (int i = 0; i < n; i++) { diff --git a/AMSS_NCKU_source/checkpoint.C b/AMSS_NCKU_source/checkpoint.C index 25637b6..f1c332e 100644 --- a/AMSS_NCKU_source/checkpoint.C +++ b/AMSS_NCKU_source/checkpoint.C @@ -76,8 +76,11 @@ checkpoint::checkpoint(bool checked, const char fname[], int myrank) : filename( I_Print = (myrank == 0); - int i = strlen(fname); - filename = new char[i+30]; + size_t filename_len = out_dir.size() + strlen(fname) + 32; +#ifdef CHECKDETAIL + filename_len += 32; +#endif + filename = new char[filename_len]; // cout << filename << endl; // cout << i << endl; @@ -100,12 +103,12 @@ checkpoint::checkpoint(bool checked, const char fname[], int myrank) : filename( cout << " checkpoint class created " << endl; } } -checkpoint::~checkpoint() -{ - CheckList->clearList(); - if (I_Print) - delete[] filename; -} +checkpoint::~checkpoint() +{ + CheckList->clearList(); + if (filename) + delete[] filename; +} void checkpoint::addvariable(var *VV) { @@ -136,7 +139,7 @@ void checkpoint::writecheck_cgh(double time, cgh *GH) if (I_Print) { // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_cgh.CHK", filename); outfile.open(fname, ios::out | ios::trunc); @@ -195,7 +198,7 @@ void checkpoint::readcheck_cgh(double &time, cgh *GH, int myrank, int nprocs, in int DIM = dim; ifstream infile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_cgh.CHK", filename); infile.open(fname); @@ -297,7 +300,7 @@ void checkpoint::writecheck_sh(double time, ShellPatch *SH) if (I_Print) { - char fname[50]; + char fname[4096]; sprintf(fname, "%s_sh.CHK", filename); outfile.open(fname, ios::out | ios::trunc); @@ -335,7 +338,7 @@ void checkpoint::readcheck_sh(ShellPatch *SH, int myrank) int DIM = dim; ifstream infile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_sh.CHK", filename); infile.open(fname); @@ -390,7 +393,7 @@ void checkpoint::write_Black_Hole_position(int BH_num_input, int BH_num, double if (I_Print) { - char fname[50]; + char fname[4096]; sprintf(fname, "%s_BHp.CHK", filename); outfile.open(fname, ios::out | ios::trunc); @@ -417,7 +420,7 @@ void checkpoint::read_Black_Hole_position(int &BH_num_input, int &BH_num, double { ifstream infile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_BHp.CHK", filename); infile.open(fname); @@ -461,7 +464,7 @@ void checkpoint::write_bssn(double LastDump, double Last2dDump, double LastAnas) if (I_Print) { - char fname[50]; + char fname[4096]; sprintf(fname, "%s_bssn.CHK", filename); outfile.open(fname, ios::out | ios::trunc); @@ -481,7 +484,7 @@ void checkpoint::read_bssn(double &LastDump, double &Last2dDump, double &LastAna { ifstream infile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_bssn.CHK", filename); infile.open(fname); @@ -506,7 +509,7 @@ void checkpoint::write_bssn(double LastDump, double Last2dDump, double LastAnas) ofstream outfile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_bssn.CHK", filename); outfile.open(fname, ios::out | ios::trunc); @@ -527,7 +530,7 @@ void checkpoint::read_bssn(double &LastDump, double &Last2dDump, double &LastAna { ifstream infile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_bssn.CHK", filename); infile.open(fname); @@ -551,7 +554,7 @@ void checkpoint::write_Black_Hole_position(int BH_num_input, int BH_num, double ofstream outfile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_BHp.CHK", filename); outfile.open(fname, ios::out | ios::trunc); @@ -581,7 +584,7 @@ void checkpoint::read_Black_Hole_position(int &BH_num_input, int &BH_num, double { ifstream infile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_BHp.CHK", filename); infile.open(fname); @@ -628,7 +631,7 @@ void checkpoint::writecheck_cgh(double time, cgh *GH) ofstream outfile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_cgh.CHK", filename); outfile.open(fname, ios::out | ios::trunc); @@ -738,7 +741,7 @@ void checkpoint::readcheck_cgh(double &time, cgh *GH, int myrank, int nprocs, in int DIM = dim; ifstream infile; // char fname[50]; - char fname[50+50]; + char fname[4096]; sprintf(fname, "%s_cgh.CHK", filename); infile.open(fname); diff --git a/AMSS_NCKU_source/monitor.C b/AMSS_NCKU_source/monitor.C index 20c718f..b44c78d 100644 --- a/AMSS_NCKU_source/monitor.C +++ b/AMSS_NCKU_source/monitor.C @@ -1,7 +1,8 @@ -#ifdef newc -#include -using namespace std; +#ifdef newc +#include +#include +using namespace std; #else #include #endif @@ -77,16 +78,17 @@ monitor::monitor(const char fname[], int myrank, string head) parameters::str_par.insert(map::value_type("output dir", out_dir)); } // considering checkpoint run - char filename[50]; - sprintf(filename, "%s/%s", out_dir.c_str(), fname); - int i = 1; - while ((access(filename, F_OK)) != -1) - { - sprintf(filename, "%s/%d_%s", out_dir.c_str(), i, fname); - i++; - } - - outfile.open(filename, ios::trunc); + string filename = out_dir + "/" + fname; + int i = 1; + while ((access(filename.c_str(), F_OK)) != -1) + { + stringstream ss; + ss << out_dir << "/" << i << "_" << fname; + filename = ss.str(); + i++; + } + + outfile.open(filename.c_str(), ios::trunc); time_t tnow; time(&tnow); @@ -107,16 +109,17 @@ monitor::monitor(const char fname[], int myrank, const int out_rank, string head if (I_Print) { // considering checkpoint run - char filename[50]; - sprintf(filename, "%s/%s", out_dir.c_str(), fname); - int i = 1; - while ((access(filename, F_OK)) != -1) - { - sprintf(filename, "%s/%d_%s", out_dir.c_str(), i, fname); - i++; - } - - outfile.open(filename, ios::trunc); + string filename = out_dir + "/" + fname; + int i = 1; + while ((access(filename.c_str(), F_OK)) != -1) + { + stringstream ss; + ss << out_dir << "/" << i << "_" << fname; + filename = ss.str(); + i++; + } + + outfile.open(filename.c_str(), ios::trunc); time_t tnow; time(&tnow);