|
From: <sv...@va...> - 2008-03-12 16:48:03
|
Author: bart
Date: 2008-03-12 16:48:07 +0000 (Wed, 12 Mar 2008)
New Revision: 7650
Log:
Replaced positional command line arguments by command options.
Modified:
trunk/exp-drd/tests/omp_prime.c
Modified: trunk/exp-drd/tests/omp_prime.c
===================================================================
--- trunk/exp-drd/tests/omp_prime.c 2008-03-12 16:47:07 UTC (rev 7649)
+++ trunk/exp-drd/tests/omp_prime.c 2008-03-12 16:48:07 UTC (rev 7650)
@@ -9,6 +9,7 @@
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h> // getopt()
#include "../drd_clientreq.h"
@@ -35,11 +36,31 @@
{
int i;
int total = 0;
- const int n = argc > 1 ? atoi(argv[1]) : 300;
- const int num_threads = argc > 2 ? atoi(argv[2]) : 4;
+ int silent = 0;
+ int n;
+ int num_threads = 2;
+ int optchar;
int* primes;
int* pflag;
+ while ((optchar = getopt(argc, argv, "qt:")) != EOF)
+ {
+ switch (optchar)
+ {
+ case 'q': silent = 1; break;
+ case 't': num_threads = atoi(optarg); break;
+ default:
+ fprintf(stderr, "Error: unknown option '%c'.\n", optchar);
+ return 1;
+ }
+ }
+
+ if (optind + 1 != argc)
+ {
+ fprintf(stderr, "Error: wrong number of arguments.\n");
+ }
+ n = atoi(argv[optind]);
+
// Not the most user-friendly way to do error checking, but better than
// nothing.
assert(n > 2);
@@ -51,14 +72,6 @@
omp_set_num_threads(num_threads);
omp_set_dynamic(0);
-#if 1
- {
- int res;
- VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_TRACE_ADDR,
- &total, 0, 0, 0, 0);
- }
-#endif
-
for (i = 0; i < n; i++) {
pflag[i] = 1;
}
@@ -72,11 +85,14 @@
total++;
}
}
- printf("Number of prime numbers between 2 and %d: %d\n",
- n, total);
- for (i = 0; i < total; i++)
+ if (! silent)
{
- printf("%d\n", primes[i]);
+ printf("Number of prime numbers between 2 and %d: %d\n",
+ n, total);
+ for (i = 0; i < total; i++)
+ {
+ printf("%d\n", primes[i]);
+ }
}
free(pflag);
|