#ifndef __UPC_ATOMIC__ #error pre-defined __UPC_ATOMIC__ is undefined. #endif #if __UPC_ATOMIC__ != 1 #error pre-defined __UPC_ATOMIC__ is != 1. #endif #include #include #include #include #if DEBUG && !defined(NDEBUG) int debug = 1; #else int debug = 0; #endif #define NO_RESULT_CHECK 0 #define RESULT_CHECK 1 shared int failures = 0; upc_atomicdomain_t *d; #define BITWISE_OPS UPC_OR|UPC_XOR|UPC_AND|UPC_GET|UPC_SET #define BITWISE_TEST(_type,_code) \ static shared _type var_##_code; \ _type evar_##_code, fvar_##_code, op1_##_code; \ void set_##_code(shared _type *sp, _type val, int check) \ { \ _type lval = val; \ _type *sval = (check==RESULT_CHECK) ? &fvar_##_code : NULL; \ upc_atomic_relaxed (d, sval, UPC_SET, sp, &lval, NULL); \ if (check == RESULT_CHECK && fvar_##_code != evar_##_code) \ { \ printf("ERROR: " #_code " UPC_SET returned %d (%d)\n", \ (int)fvar_##_code, (int)evar_##_code); \ ++failures; \ } \ evar_##_code = val; \ } \ void get_##_code(shared _type *sp, int check) \ { \ upc_atomic_relaxed (d, &fvar_##_code, UPC_GET, \ sp, NULL, NULL); \ if (check == RESULT_CHECK && fvar_##_code != evar_##_code) \ { \ printf("ERROR: " #_code " UPC_GET returned %d (%d)\n", \ (int)fvar_##_code, (int)evar_##_code); \ ++failures; \ } \ evar_##_code = fvar_##_code; \ } \ void and_##_code(shared _type *sp, _type val, int check) \ { \ _type lval = val; \ _type *sval = (check==RESULT_CHECK) ? &fvar_##_code : NULL; \ upc_atomic_relaxed (d, sval, UPC_AND, sp, &lval, NULL); \ if (check == RESULT_CHECK && fvar_##_code != evar_##_code) \ { \ printf("ERROR [%d]: " #_code " UPC_AND returned %d (%d)\n",\ MYTHREAD, (int)fvar_##_code, (int)evar_##_code);\ ++failures; \ } \ evar_##_code = evar_##_code & val; \ } \ void or_##_code(shared _type *sp, _type val, int check) \ { \ _type lval = val; \ _type *sval = (check==RESULT_CHECK) ? &fvar_##_code : NULL; \ upc_atomic_relaxed (d, sval, UPC_OR, sp, &lval, NULL); \ if (check == RESULT_CHECK && fvar_##_code != evar_##_code) \ { \ printf("ERROR: " #_code " UPC_OR returned %d (%d)\n", \ (int)fvar_##_code, (int)evar_##_code); \ ++failures; \ } \ evar_##_code = evar_##_code | val; \ } \ void xor_##_code(shared _type *sp, _type val, int check) \ { \ _type lval = val; \ _type *sval = (check==RESULT_CHECK) ? &fvar_##_code : NULL; \ upc_atomic_relaxed (d, sval, UPC_XOR, sp, &lval, NULL); \ if (check == RESULT_CHECK && fvar_##_code != evar_##_code) \ { \ printf("ERROR: " #_code " UPC_XOR returned %d (%d)\n", \ (int)fvar_##_code, (int)evar_##_code); \ ++failures; \ } \ evar_##_code = evar_##_code ^ val; \ } \ void test_##_code(void) \ { \ int prev_failures = failures; \ int atomic_perf; \ int i; \ \ atomic_perf = upc_atomic_isfast (_code, BITWISE_OPS, &var_##_code); \ \ /* Create an atomic domain. */ \ d = upc_all_atomicdomain_alloc (_code, BITWISE_OPS, 0); \ \ /* Private tests */ \ if (debug && !MYTHREAD) \ { \ printf ("+ UPC bitwise atomics (" #_code ")\n"); \ fflush(stdout); \ } \ \ for (i=0; i