164 lines · c
1// RUN: %libomp-compile -mlong-double-80 && %libomp-run2// UNSUPPORTED: gcc3// REQUIRES: x86-target-arch4 5#include <stdio.h>6#include <omp.h>7 8// Used to detect architecture9#include "../../src/kmp_platform.h"10 11#ifdef __cplusplus12extern "C" {13#endif14typedef 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 __cplusplus26}27#endif28 29int main() {30 int ret = 0;31#if (KMP_ARCH_X86 || KMP_ARCH_X86_64) && !defined(_MSC_VER)32 long double s = 012.3456; // small33 long double e = 123.4567; // middle34 long double d = 234.5678; // big35 long double x = 123.4567; // object36 long double v = 0.; // captured value37 38// initialize OpenMP runtime library39 omp_set_num_threads(4);40 41// max42// #pragma omp atomic compare update43// 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-op50 if (x != d) {51 ret++;52 printf("Error max: %Lf != %Lf\n", x, d);53 }54 55// min56// #pragma omp atomic compare update57// 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-op64 if (x != s) {65 ret++;66 printf("Error min: %Lf != %Lf\n", x, s);67 }68 69// max_cpt old70// #pragma omp atomic compare update capture71// { 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-op82 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 old92// #pragma omp atomic compare update capture93// { 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-op104 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 new114// #pragma omp atomic compare update capture115// { 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-op126 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 new136// #pragma omp atomic compare update capture137// { 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-op148 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#else160 printf("Unsupported architecture, skipping test...\n");161#endif // (KMP_ARCH_X86 || KMP_ARCH_X86_64) && !defined(_MSC_VER)162 return ret;163}164