-
Notifications
You must be signed in to change notification settings - Fork 194
2026PKUCourseHW5:Fix file open check in utils.cpp #7136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,10 +91,15 @@ void loadMatrix(const char FileName[], int nFull, double* a, int* desca, int bla | |
|
|
||
| const int ROOT_PROC = 0; | ||
| std::ifstream matrixFile; | ||
| if (myid == ROOT_PROC) | ||
| if (myid == ROOT_PROC){ | ||
| matrixFile.open(FileName); | ||
|
|
||
| double* b; // buffer | ||
| if (!matrixFile.is_open()) { | ||
| std::cerr << "Error: failed to open file " << FileName << std::endl; | ||
| exit(EXIT_FAILURE); | ||
| } | ||
|
Comment on lines
+97
to
+100
|
||
| } | ||
| double* b; // buffer | ||
| const int MAX_BUFFER_SIZE = 1e9; // max buffer size is 1GB | ||
|
Comment on lines
+94
to
103
|
||
|
|
||
| int N = nFull; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an MPI/BLACS run, calling
exit(EXIT_FAILURE)only onROOT_PROCwill leave the other ranks continuing intoCpdgemr2d(...), which can hang/crash because a collective is entered with one rank missing. Consider broadcasting theis_openstatus to all ranks and having all ranks take the same error path, or aborting the whole BLACS/MPI communicator (e.g., viaMPI_Aborton the communicator associated withblacs_ctxt).