memcheck/tests/sh-mem-random.c: Set huge_addr to 240GB
[valgrind.git] / drd / tests / omp_printf.c
blob3f6f5fa9295adfaa6313369b3734ff8cff639f08
1 /* Simple OpenMP test program that calls printf() from a parallel section. */
3 #include <assert.h> // assert()
4 #include <omp.h>
5 #include <stdio.h>
6 #include <stdlib.h> // atoi()
7 #include <unistd.h> // getopt()
9 static void usage(const char* const exe)
11 fprintf(stderr,
12 "Usage: %s [-h] [-i <n>] [-q] [-t<n>]\n"
13 "-h: display this information.\n"
14 "-i <n>: number of loop iterations.\n"
15 "-q: quiet mode -- do not print computed error.\n"
16 "-t <n>: number of OMP threads.\n",
17 exe);
20 int main(int argc, char** argv)
22 int i;
23 int optchar;
24 int silent = 0;
25 int tid;
26 int num_iterations = 2;
27 int num_threads = 2;
29 while ((optchar = getopt(argc, argv, "hi:qt:")) != EOF)
31 switch (optchar)
33 case 'h': usage(argv[0]); return 1;
34 case 'i': num_iterations = atoi(optarg); break;
35 case 'q': silent = 1; break;
36 case 't': num_threads = atoi(optarg); break;
37 default:
38 return 1;
43 * Not the most user-friendly way of error checking, but still better than
44 * no error checking.
46 assert(num_iterations > 0);
47 assert(num_threads > 0);
49 omp_set_num_threads(num_threads);
50 omp_set_dynamic(0);
52 #pragma omp parallel for private(tid)
53 for (i = 0; i < num_iterations; i++)
55 tid = omp_get_thread_num();
56 if (! silent)
58 fprintf(stderr,
59 "iteration %d; thread number = %d; number of threads = %d\n",
60 i, tid, omp_get_num_threads());
62 else
64 fprintf(stderr, "%s", "");
68 fprintf(stderr, "Finished.\n");
70 return 0;