From 1bcef50b864fb1ea6e00900b3982e71d183cfda5 Mon Sep 17 00:00:00 2001 From: jhendersonHDF Date: Fri, 27 Oct 2023 23:18:24 -0500 Subject: Print some messages in parallel tests on MPI rank 0 only (#3785) Avoids overly verbose output from all processes emitting progress, etc. info. --- test/h5test.c | 28 ++++++++++------- test/testframe.c | 84 ++++++++++++++++++++++++++++----------------------- testpar/t_2Gio.c | 6 ++-- testpar/t_mpi.c | 46 +++++++++++++--------------- testpar/t_shapesame.c | 17 +++++++---- 5 files changed, 99 insertions(+), 82 deletions(-) diff --git a/test/h5test.c b/test/h5test.c index 5348e1b..3046375 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -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 @@ -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 diff --git a/test/testframe.c b/test/testframe.c index 2b65027..5cb25ed 100644 --- a/test/testframe.c +++ b/test/testframe.c @@ -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 ? "" : "")); - 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 ? "" : "")); + 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"); + } } /* @@ -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); + } } /* @@ -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. */ @@ -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++) @@ -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; } } diff --git a/testpar/t_2Gio.c b/testpar/t_2Gio.c index c2aac77..48abf8e 100644 --- a/testpar/t_2Gio.c +++ b/testpar/t_2Gio.c @@ -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"); }; @@ -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); diff --git a/testpar/t_mpi.c b/testpar/t_mpi.c index eff39d0..0f1e27b 100644 --- a/testpar/t_mpi.c +++ b/testpar/t_mpi.c @@ -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) @@ -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 */ @@ -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); @@ -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 @@ -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; @@ -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), ""); @@ -432,7 +436,6 @@ finish: 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]; @@ -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. */ @@ -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; @@ -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]); diff --git a/testpar/t_shapesame.c b/testpar/t_shapesame.c index 98e3077..0a3d3d0 100644 --- a/testpar/t_shapesame.c +++ b/testpar/t_shapesame.c @@ -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); } @@ -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); } @@ -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); -- cgit v0.12