[Openmp-commits] [PATCH] D112456: [OpenMP][libomp] Fix omp_get_wtime.c test
Jonathan Peyton via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Mon Oct 25 07:46:36 PDT 2021
jlpeyton created this revision.
jlpeyton added reviewers: AndreyChurbanov, protze.joachim, ronlieb.
jlpeyton added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
jlpeyton requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.
Drop trying to test "precise" wall clock time and just test that successive calls to `omp_get_wtime()` are monotonically increasing.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D112456
Files:
openmp/runtime/test/api/omp_get_wtime.c
Index: openmp/runtime/test/api/omp_get_wtime.c
===================================================================
--- openmp/runtime/test/api/omp_get_wtime.c
+++ openmp/runtime/test/api/omp_get_wtime.c
@@ -4,73 +4,29 @@
#include "omp_testsuite.h"
#include "omp_my_sleep.h"
-#define NTIMES 100
-
-// This is the error % threshold. Be generous with the error threshold since
-// this test may be run in parallel with many other tests it may throw off the
-// sleep timing.
-#define THRESHOLD 100.0
-
-double test_omp_get_wtime(double desired_wait_time) {
- double start;
- double end;
- start = 0;
- end = 0;
+// Return 0 if success, 1 if failure
+//
+// Trying to test a precise elapsed wall clock time is impossible due to
+// non-deterministic workloads on the test machine and OS scheduling quirks
+// which may affect the timing of the test.
+//
+// Only test that a successive call to omp_get_wtime()
+// returns a larger (or equal) value than the previous call.
+int test_omp_get_wtime() {
+ double start, stop;
start = omp_get_wtime();
- my_sleep(desired_wait_time);
- end = omp_get_wtime();
- return end - start;
-}
-
-int compare_times(const void *lhs, const void *rhs) {
- const double *a = (const double *)lhs;
- const double *b = (const double *)rhs;
- return *a - *b;
+ my_sleep(0.05);
+ stop = omp_get_wtime();
+ if (start > stop)
+ return 1;
+ return 0;
}
int main() {
- int i, final_count;
- double percent_off;
- double *begin, *end, *ptr;
- double wait_time = 0.01;
- double average = 0.0;
- double n = 0.0;
- double *times = (double *)malloc(sizeof(double) * NTIMES);
-
- // Get each timing
- for (i = 0; i < NTIMES; i++) {
- times[i] = test_omp_get_wtime(wait_time);
- }
-
- // Remove approx the "worst" tenth of the timings
- qsort(times, NTIMES, sizeof(double), compare_times);
- begin = times;
- end = times + NTIMES;
- for (i = 0; i < NTIMES / 10; ++i) {
- if (i % 2 == 0)
- begin++;
- else
- end--;
- }
-
- // Get the average of the remaining timings
- for (ptr = begin, final_count = 0; ptr != end; ++ptr, ++final_count)
- average += times[i];
- average /= (double)final_count;
- free(times);
-
- // Calculate the percent off of desired wait time
- percent_off = (average - wait_time) / wait_time * 100.0;
- // Should always be positive, but just in case
- if (percent_off < 0)
- percent_off = -percent_off;
-
- if (percent_off > (double)THRESHOLD) {
- fprintf(stderr, "error: average of %d runs (%lf) is of by %lf%%\n", NTIMES,
- average, percent_off);
+ int i, errs = 0;
+ for (i = 0; i < REPETITIONS; ++i)
+ errs += test_omp_get_wtime();
+ if (errs)
return EXIT_FAILURE;
- }
- printf("pass: average of %d runs (%lf) is only off by %lf%%\n", NTIMES,
- average, percent_off);
return EXIT_SUCCESS;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112456.381994.patch
Type: text/x-patch
Size: 2844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20211025/fae1abc3/attachment-0001.bin>
More information about the Openmp-commits
mailing list