Skip to content
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

Print some messages in parallel tests on MPI rank 0 only #3785

Merged
merged 3 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions test/h5test.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,22 +864,23 @@ h5_show_hostname(void)
WSADATA wsaData;
int err;
#endif
#ifdef H5_HAVE_PARALLEL
int mpi_rank, mpi_initialized, mpi_finalized;
#endif

/* try show the process or thread id in multiple processes cases*/
#ifdef H5_HAVE_PARALLEL
{
int mpi_rank, mpi_initialized, mpi_finalized;

MPI_Initialized(&mpi_initialized);
MPI_Finalized(&mpi_finalized);
MPI_Initialized(&mpi_initialized);
MPI_Finalized(&mpi_finalized);

if (mpi_initialized && !mpi_finalized) {
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
printf("MPI-process %d.", mpi_rank);
}
else
printf("thread 0.");
if (mpi_initialized && !mpi_finalized) {
/* Prevent output here from getting mixed with later output */
MPI_Barrier(MPI_COMM_WORLD);
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
printf("MPI-process %d.", mpi_rank);
}
else
printf("thread 0.");
#else
printf("thread %" PRIu64 ".", H5TS_thread_id());
#endif
Expand Down Expand Up @@ -915,6 +916,11 @@ h5_show_hostname(void)
#ifdef H5_HAVE_WIN32_API
WSACleanup();
#endif
#ifdef H5_HAVE_PARALLEL
/* Prevent output here from getting mixed with later output */
if (mpi_initialized && !mpi_finalized)
MPI_Barrier(MPI_COMM_WORLD);
#endif
}

#ifdef H5_HAVE_PARALLEL
Expand Down
84 changes: 47 additions & 37 deletions test/testframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,37 @@ TestUsage(void)
{
unsigned i;

print_func("Usage: %s [-v[erbose] (l[ow]|m[edium]|h[igh]|0-9)] %s\n", TestProgName,
(TestPrivateUsage ? "<extra options>" : ""));
print_func(" [-[e]x[clude] name]+ \n");
print_func(" [-o[nly] name]+ \n");
print_func(" [-b[egin] name] \n");
print_func(" [-s[ummary]] \n");
print_func(" [-c[leanoff]] \n");
print_func(" [-h[elp]] \n");
print_func("\n\n");
print_func("verbose controls the amount of information displayed\n");
print_func("exclude to exclude tests by name\n");
print_func("only to name tests which should be run\n");
print_func("begin start at the name of the test given\n");
print_func("summary prints a summary of test results at the end\n");
print_func("cleanoff does not delete *.hdf files after execution of tests\n");
print_func("help print out this information\n");
if (TestPrivateUsage) {
print_func("\nExtra options\n");
TestPrivateUsage();
}
print_func("\n\n");
print_func("This program currently tests the following: \n\n");
print_func("%16s %s\n", "Name", "Description");
print_func("%16s %s\n", "----", "-----------");
if (mpi_rank_framework_g == 0) {
print_func("Usage: %s [-v[erbose] (l[ow]|m[edium]|h[igh]|0-9)] %s\n", TestProgName,
(TestPrivateUsage ? "<extra options>" : ""));
print_func(" [-[e]x[clude] name]+ \n");
print_func(" [-o[nly] name]+ \n");
print_func(" [-b[egin] name] \n");
print_func(" [-s[ummary]] \n");
print_func(" [-c[leanoff]] \n");
print_func(" [-h[elp]] \n");
print_func("\n\n");
print_func("verbose controls the amount of information displayed\n");
print_func("exclude to exclude tests by name\n");
print_func("only to name tests which should be run\n");
print_func("begin start at the name of the test given\n");
print_func("summary prints a summary of test results at the end\n");
print_func("cleanoff does not delete *.hdf files after execution of tests\n");
print_func("help print out this information\n");
if (TestPrivateUsage) {
print_func("\nExtra options\n");
TestPrivateUsage();
}
print_func("\n\n");
print_func("This program currently tests the following: \n\n");
print_func("%16s %s\n", "Name", "Description");
print_func("%16s %s\n", "----", "-----------");

for (i = 0; i < Index; i++)
print_func("%16s %s\n", Test[i].Name, Test[i].Description);
for (i = 0; i < Index; i++)
print_func("%16s %s\n", Test[i].Name, Test[i].Description);

print_func("\n\n");
print_func("\n\n");
}
}

/*
Expand All @@ -192,12 +194,14 @@ TestUsage(void)
void
TestInfo(const char *ProgName)
{
unsigned major, minor, release;
if (mpi_rank_framework_g == 0) {
unsigned major, minor, release;

H5get_libversion(&major, &minor, &release);
H5get_libversion(&major, &minor, &release);

print_func("\nFor help use: %s -help\n", ProgName);
print_func("Linked with hdf5 version %u.%u release %u\n", major, minor, release);
print_func("\nFor help use: %s -help\n", ProgName);
print_func("Linked with hdf5 version %u.%u release %u\n", major, minor, release);
}
}

/*
Expand Down Expand Up @@ -301,20 +305,24 @@ PerformTests(void)

for (Loop = 0; Loop < Index; Loop++)
if (Test[Loop].SkipFlag) {
MESSAGE(2, ("Skipping -- %s (%s) \n", Test[Loop].Description, Test[Loop].Name));
if (mpi_rank_framework_g == 0)
MESSAGE(2, ("Skipping -- %s (%s) \n", Test[Loop].Description, Test[Loop].Name));
}
else {
if (mpi_rank_framework_g == 0)
MESSAGE(2, ("Testing -- %s (%s) \n", Test[Loop].Description, Test[Loop].Name));
MESSAGE(5, ("===============================================\n"));
if (mpi_rank_framework_g == 0)
MESSAGE(5, ("===============================================\n"));
Test[Loop].NumErrors = num_errs;
Test_parameters = Test[Loop].Parameters;
TestAlarmOn();
Test[Loop].Call();
TestAlarmOff();
Test[Loop].NumErrors = num_errs - Test[Loop].NumErrors;
MESSAGE(5, ("===============================================\n"));
MESSAGE(5, ("There were %d errors detected.\n\n", (int)Test[Loop].NumErrors));
if (mpi_rank_framework_g == 0) {
MESSAGE(5, ("===============================================\n"));
MESSAGE(5, ("There were %d errors detected.\n\n", (int)Test[Loop].NumErrors));
}
}

Test_parameters = NULL; /* clear it. */
Expand Down Expand Up @@ -358,7 +366,8 @@ TestCleanup(void)
{
unsigned Loop;

MESSAGE(2, ("\nCleaning Up temp files...\n\n"));
if (mpi_rank_framework_g == 0)
MESSAGE(2, ("\nCleaning Up temp files...\n\n"));

/* call individual cleanup routines in each source module */
for (Loop = 0; Loop < Index; Loop++)
Expand Down Expand Up @@ -619,7 +628,8 @@ SetTest(const char *testname, int action)
break;
default:
/* error */
printf("*** ERROR: Unknown action (%d) for SetTest\n", action);
if (mpi_rank_framework_g == 0)
printf("*** ERROR: Unknown action (%d) for SetTest\n", action);
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions testpar/t_2Gio.c
Original file line number Diff line number Diff line change
Expand Up @@ -4291,9 +4291,10 @@ main(int argc, char **argv)
printf("2 GByte IO TESTS START\n");
printf("2 MPI ranks will run the tests...\n");
printf("===================================\n");
h5_show_hostname();
}

h5_show_hostname();

if (H5dont_atexit() < 0) {
printf("Failed to turn off atexit processing. Continue.\n");
};
Expand Down Expand Up @@ -4345,8 +4346,7 @@ main(int argc, char **argv)
#endif /* H5_HAVE_FILTER_DEFLATE */

/* Display testing information */
if (MAINPROCESS)
TestInfo(argv[0]);
TestInfo(argv[0]);

/* setup file access property list */
fapl = H5Pcreate(H5P_FILE_ACCESS);
Expand Down
46 changes: 21 additions & 25 deletions testpar/t_mpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ test_mpio_overlap_writes(char *filename)
MPI_Offset mpi_off;
MPI_Status mpi_stat;

if (VERBOSE_MED)
printf("MPIO independent overlapping writes test on file %s\n", filename);

nerrs = 0;
/* set up MPI parameters */
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);

if (VERBOSE_MED && MAINPROCESS)
printf("MPIO independent overlapping writes test on file %s\n", filename);

/* Need at least 2 processes */
if (mpi_size < 2) {
if (MAINPROCESS)
Expand Down Expand Up @@ -211,7 +211,7 @@ test_mpio_gb_file(char *filename)
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);

if (VERBOSE_MED)
if (VERBOSE_MED && MAINPROCESS)
printf("MPI_Offset range test\n");

/* figure out the signness and sizeof MPI_Offset */
Expand Down Expand Up @@ -274,12 +274,13 @@ test_mpio_gb_file(char *filename)
/*
* Verify if we can write to a file of multiple GB sizes.
*/
if (VERBOSE_MED)
if (VERBOSE_MED && MAINPROCESS)
printf("MPIO GB file test %s\n", filename);

if (sizeof_mpi_offset <= 4) {
printf("Skipped GB file range test "
"because MPI_Offset cannot support it\n");
if (MAINPROCESS)
printf("Skipped GB file range test "
"because MPI_Offset cannot support it\n");
}
else {
buf = (char *)malloc(MB);
Expand All @@ -294,7 +295,8 @@ test_mpio_gb_file(char *filename)
mrc = MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, info, &fh);
VRFY((mrc == MPI_SUCCESS), "MPI_FILE_OPEN");

printf("MPIO GB file write test %s\n", filename);
if (MAINPROCESS)
printf("MPIO GB file write test %s\n", filename);

/* instead of writing every bytes of the file, we will just write
* some data around the 2 and 4 GB boundaries. That should cover
Expand Down Expand Up @@ -333,7 +335,8 @@ test_mpio_gb_file(char *filename)
*/
/* open it again to verify the data written */
/* but only if there was no write errors */
printf("MPIO GB file read test %s\n", filename);
if (MAINPROCESS)
printf("MPIO GB file read test %s\n", filename);
if (errors_sum(writerrs) > 0) {
printf("proc %d: Skip read test due to previous write errors\n", mpi_rank);
goto finish;
Expand Down Expand Up @@ -377,7 +380,8 @@ test_mpio_gb_file(char *filename)
mrc = MPI_Barrier(MPI_COMM_WORLD);
VRFY((mrc == MPI_SUCCESS), "Sync before leaving test");

printf("Test if MPI_File_get_size works correctly with %s\n", filename);
if (MAINPROCESS)
printf("Test if MPI_File_get_size works correctly with %s\n", filename);

mrc = MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_RDONLY, info, &fh);
VRFY((mrc == MPI_SUCCESS), "");
Expand Down Expand Up @@ -432,7 +436,6 @@ test_mpio_gb_file(char *filename)
static int
test_mpio_1wMr(char *filename, int special_request)
{
char hostname[128];
int mpi_size, mpi_rank;
MPI_File fh;
char mpi_err_str[MPI_MAX_ERROR_STRING];
Expand All @@ -456,19 +459,8 @@ test_mpio_1wMr(char *filename, int special_request)
}

/* show the hostname so that we can tell where the processes are running */
if (VERBOSE_DEF) {
#ifdef H5_HAVE_GETHOSTNAME
if (gethostname(hostname, sizeof(hostname)) < 0) {
printf("gethostname failed\n");
hostname[0] = '\0';
}
#else
printf("gethostname unavailable\n");
hostname[0] = '\0';
#endif
PRINTID;
printf("hostname=%s\n", hostname);
}
if (VERBOSE_DEF)
h5_show_hostname();

/* Delete any old file in order to start anew. */
/* Must delete because MPI_File_open does not have a Truncate mode. */
Expand Down Expand Up @@ -1005,6 +997,10 @@ test_mpio_special_collective(char *filename)
static int
parse_options(int argc, char **argv)
{
int mpi_rank;

MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);

while (--argc) {
if (**(++argv) != '-') {
break;
Expand Down Expand Up @@ -1053,7 +1049,7 @@ parse_options(int argc, char **argv)
return (1);
}
H5Pclose(plist);
if (VERBOSE_MED) {
if (VERBOSE_MED && MAINPROCESS) {
printf("Test filenames are:\n");
for (i = 0; i < n; i++)
printf(" %s\n", filenames[i]);
Expand Down
17 changes: 11 additions & 6 deletions testpar/t_shapesame.c
Original file line number Diff line number Diff line change
Expand Up @@ -4089,7 +4089,8 @@ parse_options(int argc, char **argv)
case 'h': /* print help message--return with nerrors set */
return (1);
default:
printf("Illegal option(%s)\n", *argv);
if (MAINPROCESS)
printf("Illegal option(%s)\n", *argv);
nerrors++;
return (1);
}
Expand All @@ -4098,12 +4099,14 @@ parse_options(int argc, char **argv)

/* check validity of dimension and chunk sizes */
if (dim0 <= 0 || dim1 <= 0) {
printf("Illegal dim sizes (%d, %d)\n", dim0, dim1);
if (MAINPROCESS)
printf("Illegal dim sizes (%d, %d)\n", dim0, dim1);
nerrors++;
return (1);
}
if (chunkdim0 <= 0 || chunkdim1 <= 0) {
printf("Illegal chunkdim sizes (%d, %d)\n", chunkdim0, chunkdim1);
if (MAINPROCESS)
printf("Illegal chunkdim sizes (%d, %d)\n", chunkdim0, chunkdim1);
nerrors++;
return (1);
}
Expand All @@ -4128,9 +4131,11 @@ parse_options(int argc, char **argv)
nerrors++;
return (1);
}
printf("Test filenames are:\n");
for (i = 0; i < n; i++)
printf(" %s\n", filenames[i]);
if (MAINPROCESS) {
printf("Test filenames are:\n");
for (i = 0; i < n; i++)
printf(" %s\n", filenames[i]);
}
}

return (0);
Expand Down