LLVM OpenMP 19.0.0git
kmp_atomic_float10_max_min.c
Go to the documentation of this file.
1// RUN: %libomp-compile -mlong-double-80 && %libomp-run
2// UNSUPPORTED: gcc
3// REQUIRES: x86-target-arch
4
5#include <stdio.h>
6#include <omp.h>
7
8// Used to detect architecture
9#include "../../src/kmp_platform.h"
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14typedef void* ident_t;
15extern void __kmpc_atomic_float10_max(ident_t *id_ref, int gtid,
16 long double *lhs, long double rhs);
17extern void __kmpc_atomic_float10_min(ident_t *id_ref, int gtid,
18 long double *lhs, long double rhs);
19extern long double __kmpc_atomic_float10_max_cpt(ident_t *id_ref, int gtid,
20 long double *lhs,
21 long double rhs, int flag);
22extern long double __kmpc_atomic_float10_min_cpt(ident_t *id_ref, int gtid,
23 long double *lhs,
24 long double rhs, int flag);
25#ifdef __cplusplus
26}
27#endif
28
29int main() {
30 int ret = 0;
31#if (KMP_ARCH_X86 || KMP_ARCH_X86_64) && !defined(_MSC_VER)
32 long double s = 012.3456; // small
33 long double e = 123.4567; // middle
34 long double d = 234.5678; // big
35 long double x = 123.4567; // object
36 long double v = 0.; // captured value
37
38// initialize OpenMP runtime library
40
41// max
42// #pragma omp atomic compare update
43// if (x < d) x = d;
44 __kmpc_atomic_float10_max(NULL, 0, &x, d);
45 if (x != d) {
46 ret++;
47 printf("Error max: %Lf != %Lf\n", x, d);
48 }
49 __kmpc_atomic_float10_max(NULL, 0, &x, s); // no-op
50 if (x != d) {
51 ret++;
52 printf("Error max: %Lf != %Lf\n", x, d);
53 }
54
55// min
56// #pragma omp atomic compare update
57// if (x > s) x = s;
58 __kmpc_atomic_float10_min(NULL, 0, &x, s);
59 if (x != s) {
60 ret++;
61 printf("Error min: %Lf != %Lf\n", x, s);
62 }
63 __kmpc_atomic_float10_min(NULL, 0, &x, e); // no-op
64 if (x != s) {
65 ret++;
66 printf("Error min: %Lf != %Lf\n", x, s);
67 }
68
69// max_cpt old
70// #pragma omp atomic compare update capture
71// { v = x; if (x < d) x = d; }
72 v = __kmpc_atomic_float10_max_cpt(NULL, 0, &x, d, 0);
73 if (x != d) {
74 ret++;
75 printf("Error max_cpt obj: %Lf != %Lf\n", x, d);
76 }
77 if (v != s) {
78 ret++;
79 printf("Error max_cpt cpt: %Lf != %Lf\n", v, s);
80 }
81 v = __kmpc_atomic_float10_max_cpt(NULL, 0, &x, e, 0); // no-op
82 if (x != d) {
83 ret++;
84 printf("Error max_cpt obj: %Lf != %Lf\n", x, d);
85 }
86 if (v != d) {
87 ret++;
88 printf("Error max_cpt cpt: %Lf != %Lf\n", v, d);
89 }
90
91// min_cpt old
92// #pragma omp atomic compare update capture
93// { v = x; if (x > d) x = d; }
94 v = __kmpc_atomic_float10_min_cpt(NULL, 0, &x, s, 0);
95 if (x != s) {
96 ret++;
97 printf("Error min_cpt obj: %Lf != %Lf\n", x, s);
98 }
99 if (v != d) {
100 ret++;
101 printf("Error min_cpt cpt: %Lf != %Lf\n", v, d);
102 }
103 v = __kmpc_atomic_float10_min_cpt(NULL, 0, &x, e, 0); // no-op
104 if (x != s) {
105 ret++;
106 printf("Error max_cpt obj: %Lf != %Lf\n", x, s);
107 }
108 if (v != s) {
109 ret++;
110 printf("Error max_cpt cpt: %Lf != %Lf\n", v, s);
111 }
112
113// max_cpt new
114// #pragma omp atomic compare update capture
115// { if (x < d) x = d; v = x; }
116 v = __kmpc_atomic_float10_max_cpt(NULL, 0, &x, d, 1);
117 if (x != d) {
118 ret++;
119 printf("Error max_cpt obj: %Lf != %Lf\n", x, d);
120 }
121 if (v != d) {
122 ret++;
123 printf("Error max_cpt cpt: %Lf != %Lf\n", v, d);
124 }
125 v = __kmpc_atomic_float10_max_cpt(NULL, 0, &x, e, 1); // no-op
126 if (x != d) {
127 ret++;
128 printf("Error max_cpt obj: %Lf != %Lf\n", x, d);
129 }
130 if (v != d) {
131 ret++;
132 printf("Error max_cpt cpt: %Lf != %Lf\n", v, d);
133 }
134
135// min_cpt new
136// #pragma omp atomic compare update capture
137// { if (x > d) x = d; v = x; }
138 v = __kmpc_atomic_float10_min_cpt(NULL, 0, &x, s, 1);
139 if (x != s) {
140 ret++;
141 printf("Error min_cpt obj: %Lf != %Lf\n", x, s);
142 }
143 if (v != s) {
144 ret++;
145 printf("Error min_cpt cpt: %Lf != %Lf\n", v, s);
146 }
147 v = __kmpc_atomic_float10_min_cpt(NULL, 0, &x, e, 1); // no-op
148 if (x != s) {
149 ret++;
150 printf("Error max_cpt obj: %Lf != %Lf\n", x, s);
151 }
152 if (v != s) {
153 ret++;
154 printf("Error max_cpt cpt: %Lf != %Lf\n", v, s);
155 }
156
157 if (ret == 0)
158 printf("passed\n");
159#else
160 printf("Unsupported architecture, skipping test...\n");
161#endif // (KMP_ARCH_X86 || KMP_ARCH_X86_64) && !defined(_MSC_VER)
162 return ret;
163}
void const char const char int ITT_FORMAT __itt_group_sync s
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d
long double __kmpc_atomic_float10_min_cpt(ident_t *id_ref, int gtid, long double *lhs, long double rhs, int flag)
long double __kmpc_atomic_float10_max_cpt(ident_t *id_ref, int gtid, long double *lhs, long double rhs, int flag)
void __kmpc_atomic_float10_min(ident_t *id_ref, int gtid, long double *lhs, long double rhs)
void * ident_t
void __kmpc_atomic_float10_max(ident_t *id_ref, int gtid, long double *lhs, long double rhs)
#define omp_set_num_threads
Definition: kmp_stub.cpp:34
return ret
volatile int flag