#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 #if __BERKELEY_UPC_RUNTIME__ #define POLL() bupc_poll() #else #define POLL() ((void)0) #endif #define NO_RESULT_CHECK 0 #define RESULT_CHECK 1 shared int failures = 0; upc_atomicdomain_t *d; static shared int sum[THREADS]; /* Parallel test number of loops. */ #ifndef LOOPCNT #define LOOPCNT 10 #endif #define ACCESS_OPS \ UPC_SET|UPC_GET|UPC_CSWAP #define ACCESS_TEST(_type,_code) \ static shared _type var_##_code; \ static _type evar_##_code, fvar_##_code, exp_var_##_code; \ void set_##_code(shared _type *sp, _type val, int check) \ { \ _type lval = val; \ _type *sval = (check==RESULT_CHECK) ? &fvar_##_code : NULL; \ upc_atomic_strict (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_strict (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 cswap_##_code(shared _type *sp, _type val, _type eval, \ int check) \ { \ _type lval = val; \ _type elval = eval; \ upc_atomic_strict (d, &fvar_##_code, \ UPC_CSWAP, sp, &elval, &lval); \ if (check == RESULT_CHECK && fvar_##_code != evar_##_code) \ { \ printf("ERROR: " #_code " UPC_CSWAP returned %d (%d)\n",\ (int)fvar_##_code, (int)evar_##_code); \ ++failures; \ } \ if (fvar_##_code == eval) \ evar_##_code = val; \ } \ void test_##_code(void) \ { \ int prev_failures = failures; \ int i; \ \ /* Create atomic domain. */ \ d = upc_all_atomicdomain_alloc (_code, ACCESS_OPS, 0); \ \ if (debug && !MYTHREAD) \ { \ printf ("+ UPC access atomics (" #_code ")\n"); \ fflush(stdout); \ } \ \ for (i=0; i= \ (unsigned long long) ebit) \ { \ notdone = 0; \ if (fvar_##_code == ebit) \ sum[MYTHREAD]++; \ thrno += THREADS; \ if (thrno >= (sizeof(_type) * 8)) \ notfull = 0; \ mbit = ((_type) 1) << thrno; \ ebit = ((_type) 1) << (thrno - 1); \ } \ else POLL(); /* required to ensure progress */ \ } \ } \ } \ upc_barrier; \ if (!MYTHREAD) \ { \ for (i=0; i