From 4acf8cac8f7c87f8d051bb71e5b5c6b2680c3221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AE=B6=E9=BD=90?= <1544375273@qq.com> Date: Sat, 28 Mar 2026 13:19:02 +0800 Subject: [PATCH 1/2] 2025PKUCourseHW5: Case: 1 - Change rank_seed_offset to static const Consider the previous contributions made by classmates, I'm only capable to make small difference without disrupting the entire program ---- like such a small "static". --- source/source_pw/module_stodft/sto_wf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/source_pw/module_stodft/sto_wf.cpp b/source/source_pw/module_stodft/sto_wf.cpp index 2de8a8c28c..173e2e7c6e 100644 --- a/source/source_pw/module_stodft/sto_wf.cpp +++ b/source/source_pw/module_stodft/sto_wf.cpp @@ -63,7 +63,7 @@ void Stochastic_WF::clean_chiallorder() template void Stochastic_WF::init_sto_orbitals(const int seed_in) { - const unsigned int rank_seed_offset = 10000; + static const unsigned int rank_seed_offset = 10000; if (seed_in == 0 || seed_in == -1) { srand(static_cast(time(nullptr)) + GlobalV::MY_RANK * rank_seed_offset); // GlobalV global variables are reserved From dfa74df881d29c3b63705bd0d5de24baafaffbdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AE=B6=E9=BD=90?= <1544375273@qq.com> Date: Sat, 28 Mar 2026 23:28:57 +0800 Subject: [PATCH 2/2] 2026PKUCourseHW5: Case: 4 - Implement file loading in root process Added file loading logic for the root process with error handling. Especially, we include the check for "else" case. --- source/source_hsolver/module_genelpa/utils.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/source/source_hsolver/module_genelpa/utils.cpp b/source/source_hsolver/module_genelpa/utils.cpp index ed79a5790a..9bae58524a 100644 --- a/source/source_hsolver/module_genelpa/utils.cpp +++ b/source/source_hsolver/module_genelpa/utils.cpp @@ -88,11 +88,27 @@ void loadMatrix(const char FileName[], int nFull, double* a, int* desca, int bla int nprows, npcols, myprow, mypcol; Cblacs_gridinfo(blacs_ctxt, &nprows, &npcols, &myprow, &mypcol); int myid = Cblacs_pnum(blacs_ctxt, myprow, mypcol); - const int ROOT_PROC = 0; + std::ifstream matrixFile; + if (myid == ROOT_PROC) + { matrixFile.open(FileName); + if (!matrixFile.is_open()) + { + #ifdef __MPI + std::cerr << "LoadError in opening '" << FileName << "'" << std::endl; + MPI_Abort(MPI_COMM_WORLD, 1); + #else + throw std::runtime_error(std::string("LoadError in opening '") + FileName + "'"); + #endif + } + } + else + { + std::cout << "Process " << myid << ": Waiting for root process to load file..." << std::endl; + } double* b = nullptr; // buffer const int MAX_BUFFER_SIZE = 1e9; // max buffer size is 1GB