From: Bart Van Assche Date: Sun, 26 Jul 2009 09:04:42 +0000 (+0000) Subject: Updated drd/tests/omp_printf: X-Git-Tag: svn/VALGRIND_3_5_0~241 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=945f25de9d3245c358e5f7251ecb8fff186196fb;p=thirdparty%2Fvalgrind.git Updated drd/tests/omp_printf: - Added command-line options -i and -t to the omp_printf test program. - Modified the OpenMP directive such that this test program no longer triggers a data race on the loop variable 'i'. - Increased number of iterations and number of threads used during the test. - Changed error filtering from filter_error_summary to filter_stderr. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10607 --- diff --git a/drd/tests/omp_printf.c b/drd/tests/omp_printf.c index 3066a44bcb..3f6f5fa929 100644 --- a/drd/tests/omp_printf.c +++ b/drd/tests/omp_printf.c @@ -1,15 +1,20 @@ /* Simple OpenMP test program that calls printf() from a parallel section. */ +#include // assert() #include #include +#include // atoi() #include // getopt() static void usage(const char* const exe) { - printf("Usage: %s [-h] [-q] [-r] [-t] \n" - "-h: display this information.\n" - "-q: quiet mode -- do not print computed error.\n", - exe); + fprintf(stderr, + "Usage: %s [-h] [-i ] [-q] [-t]\n" + "-h: display this information.\n" + "-i : number of loop iterations.\n" + "-q: quiet mode -- do not print computed error.\n" + "-t : number of OMP threads.\n", + exe); } int main(int argc, char** argv) @@ -18,29 +23,45 @@ int main(int argc, char** argv) int optchar; int silent = 0; int tid; + int num_iterations = 2; + int num_threads = 2; - while ((optchar = getopt(argc, argv, "hq")) != EOF) + while ((optchar = getopt(argc, argv, "hi:qt:")) != EOF) { switch (optchar) { case 'h': usage(argv[0]); return 1; + case 'i': num_iterations = atoi(optarg); break; case 'q': silent = 1; break; + case 't': num_threads = atoi(optarg); break; default: return 1; } } -#pragma omp parallel private(tid) - for (i = 0; i < 2; i++) + /* + * Not the most user-friendly way of error checking, but still better than + * no error checking. + */ + assert(num_iterations > 0); + assert(num_threads > 0); + + omp_set_num_threads(num_threads); + omp_set_dynamic(0); + +#pragma omp parallel for private(tid) + for (i = 0; i < num_iterations; i++) { tid = omp_get_thread_num(); if (! silent) { - printf("omp_get_thread_num() = %d/%d\n", tid, omp_get_num_threads()); + fprintf(stderr, + "iteration %d; thread number = %d; number of threads = %d\n", + i, tid, omp_get_num_threads()); } else { - printf("%s", ""); + fprintf(stderr, "%s", ""); } } diff --git a/drd/tests/omp_printf.stderr.exp b/drd/tests/omp_printf.stderr.exp index f711c765c9..a7089bb434 100644 --- a/drd/tests/omp_printf.stderr.exp +++ b/drd/tests/omp_printf.stderr.exp @@ -1 +1,4 @@ -ERROR SUMMARY: 8 errors from 8 contexts + +Finished. + +ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) diff --git a/drd/tests/omp_printf.vgtest b/drd/tests/omp_printf.vgtest index 664981b380..0725404a42 100644 --- a/drd/tests/omp_printf.vgtest +++ b/drd/tests/omp_printf.vgtest @@ -1,5 +1,4 @@ prereq: ./run_openmp_test ./omp_printf prog: omp_printf vgopts: --check-stack-var=yes --read-var-info=yes -args: -q -stderr_filter: filter_error_summary +args: -i 100 -q -t 10