From af2fdbc8ca6593ab468e458b5a3f7e7be068b83a Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Wed, 10 Oct 2018 17:03:02 -0400 Subject: [PATCH 01/23] Prototype wait/test any and all (no some yet) Signed-off-by: David M. Ozog --- mpp/shmemx.h4.in | 69 +++++++++++++++ mpp/shmemx_c_func.h4.in | 23 +++++ src/shmem_synchronization.h | 124 +++++++++++++++++++++++++++ src/synchronization_c.c4 | 139 +++++++++++++++++++++++++++++++ test/unit/Makefile.am | 6 +- test/unit/shmem_test_all.c | 52 ++++++++++++ test/unit/shmem_test_any.c | 65 +++++++++++++++ test/unit/shmem_wait_until_all.c | 52 ++++++++++++ test/unit/shmem_wait_until_any.c | 73 ++++++++++++++++ 9 files changed, 602 insertions(+), 1 deletion(-) create mode 100644 test/unit/shmem_test_all.c create mode 100644 test/unit/shmem_test_any.c create mode 100644 test/unit/shmem_wait_until_all.c create mode 100644 test/unit/shmem_wait_until_any.c diff --git a/mpp/shmemx.h4.in b/mpp/shmemx.h4.in index 582b4d394..76f394b39 100644 --- a/mpp/shmemx.h4.in +++ b/mpp/shmemx.h4.in @@ -19,12 +19,18 @@ dnl vi: set ft=m4 */ include(shmem_bind_c.m4)dnl +include(shmem_bind_c11.m4)dnl +include(shmem_bind_cxx.m4)dnl #ifndef SHMEMX_H #define SHMEMX_H #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define HAVE_SHMEMX_WTIME /* Counting puts */ @@ -45,4 +51,67 @@ include(shmemx_c_func.h4)dnl /* Option to enable bounce buffering on a given context */ #define SHMEMX_CTX_BOUNCE_BUFFER (1l<<31) +/* C++ overloaded declarations */ +#ifdef __cplusplus +} /* extern "C" */ + +#if __cplusplus >= 201402L +#define SHMEM_CXX_ATTRIBUTE_DEPRECATED [[deprecated]] +#else +#define SHMEM_CXX_ATTRIBUTE_DEPRECATED +#endif + +define(`SHMEM_CXX_WAIT_UNTIL_ALL', +`static inline void shmemx_wait_until_all($2 *ivars, size_t nelems, int cmp, $2 cmp_value) { + shmemx_$1_wait_until_all(ivars, nelems, cmp, cmp_value); +}')dnl +SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_ALL') + +define(`SHMEM_CXX_WAIT_UNTIL_ANY', +`static inline size_t shmemx_wait_until_any($2 *ivars, size_t nelems, int * restrict status, int cmp, $2 cmp_value) { + shmemx_$1_wait_until_any(ivars, nelems, status, cmp, cmp_value); +}')dnl +SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_ANY') + +define(`SHMEM_CXX_TEST_ALL', +`static inline int shmemx_test_all($2 *ivars, size_t nelems, int cmp, $2 cmp_value) { + return shmemx_$1_test_all(ivars, nelems, cmp, cmp_value); +}')dnl +SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_TEST_ALL') + +define(`SHMEM_CXX_TEST_ANY', +`static inline size_t shmemx_test_any($2 *ivars, size_t nelems, int * restrict status, int cmp, $2 cmp_value) { + return shmemx_$1_test_any(ivars, nelems, status, cmp, cmp_value); +}')dnl +SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_TEST_ANY') + +/* C11 Generic Macros */ +#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(SHMEM_INTERNAL_INCLUDE)) + +define(`SHMEM_C11_GEN_WAIT_UNTIL_ALL', ` $2*: shmemx_$1_wait_until_all')dnl +#define shmemx_wait_until_all(...) \ + _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ +SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_WAIT_UNTIL_ALL', `, \') \ + )(__VA_ARGS__) + +define(`SHMEM_C11_GEN_WAIT_UNTIL_ANY', ` $2*: shmemx_$1_wait_until_any')dnl +#define shmemx_wait_until_any(...) \ + _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ +SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_WAIT_UNTIL_ANY', `, \') \ + )(__VA_ARGS__) + +define(`SHMEM_C11_GEN_TEST_ALL', ` $2*: shmemx_$1_test_all')dnl +#define shmemx_test_all(...) \ + _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ +SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_TEST_ALL', `, \') \ + )(__VA_ARGS__) + +define(`SHMEM_C11_GEN_TEST_ANY', ` $2*: shmemx_$1_test_any')dnl +#define shmemx_test_any(...) \ + _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ +SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_TEST_ANY', `, \') \ + )(__VA_ARGS__) + +#endif /* C11 */ + #endif /* SHMEMX_H */ diff --git a/mpp/shmemx_c_func.h4.in b/mpp/shmemx_c_func.h4.in index 3e3fa398d..3c23588ff 100644 --- a/mpp/shmemx_c_func.h4.in +++ b/mpp/shmemx_c_func.h4.in @@ -39,3 +39,26 @@ SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_pcntr_get_completed_read(shmem_ctx_ SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_pcntr_get_completed_target(uint64_t *cntr_value); SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_pcntr_get_all(shmem_ctx_t ctx, shmemx_pcntr_t *pcntr); +define(`SHMEM_C_WAIT_UNTIL_ALL', +`SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_$1_wait_until_all($2 *vars, size_t nelems, int cmp, $2 value);')dnl +SHMEM_BIND_C_SYNC(`SHMEM_C_WAIT_UNTIL_ALL') + +define(`SHMEM_C_WAIT_UNTIL_ANY', +`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_wait_until_any($2 *vars, size_t nelems, int * restrict status, int cmp, $2 value);')dnl +SHMEM_BIND_C_SYNC(`SHMEM_C_WAIT_UNTIL_ANY') + +/* Special case, only enabled when C++ and C11 bindings are disabled */ +#if ( !defined(__cplusplus) && \ + !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) ) || \ + defined(SHMEM_INTERNAL_INCLUDE) || defined(SHMEM_DECLARE_SPECIAL_CASES) +SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_wait_until_all(long *ivars, size_t nelems, int cmp, long value); +SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_wait_until_any(long *ivars, size_t nelems, int * restrict status, int cmp, long value); +#endif + +define(`SHMEM_C_TEST_ALL', +`SHMEM_FUNCTION_ATTRIBUTES int SHPRE()shmemx_$1_test_all($2 *vars, size_t nelems, int cmp, $2 value);')dnl +SHMEM_BIND_C_SYNC(`SHMEM_C_TEST_ALL') + +define(`SHMEM_C_TEST_ANY', +`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_test_any($2 *vars, size_t nelems, int * restrict status, int cmp, $2 value);')dnl +SHMEM_BIND_C_SYNC(`SHMEM_C_TEST_ANY') diff --git a/src/shmem_synchronization.h b/src/shmem_synchronization.h index f356fda1d..e077b6c86 100644 --- a/src/shmem_synchronization.h +++ b/src/shmem_synchronization.h @@ -101,6 +101,20 @@ shmem_internal_fence(shmem_ctx_t ctx) } \ } while(0) +#define SHMEM_WAIT_UNTIL_POLL_LIMIT(var, cond, value) \ + do { \ + int cmpret; \ + int poll_cntr = 100; \ + \ + COMP(cond, *(var), value, cmpret); \ + while (!cmpret && poll_cntr) { \ + shmem_transport_probe(); \ + SPINLOCK_BODY(); \ + COMP(cond, *(var), value, cmpret); \ + poll_cntr--; \ + } \ + } while(0) + #define SHMEM_WAIT_BLOCK(var, value) \ do { \ uint64_t target_cntr; \ @@ -129,6 +143,23 @@ shmem_internal_fence(shmem_ctx_t ctx) } \ } while(0) +#define SHMEM_WAIT_UNTIL_BLOCK_LIMIT(var, cond, value) \ + do { \ + uint64_t target_cntr; \ + int cmpret; \ + int poll_cntr = 10; \ + \ + COMP(cond, *(var), value, cmpret); \ + while (!cmpret && poll_cntr) { \ + target_cntr = shmem_transport_received_cntr_get(); \ + COMPILER_FENCE(); \ + COMP(cond, *(var), value, cmpret); \ + if (cmpret) break; \ + shmem_transport_received_cntr_wait(target_cntr + 1); \ + COMP(cond, *(var), value, cmpret); \ + } \ + } while(0) + #if defined(ENABLE_HARD_POLLING) #define SHMEM_WAIT(var, value) do { \ SHMEM_WAIT_POLL(var, value); \ @@ -142,6 +173,49 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_transport_syncmem(); \ } while (0) +#define SHMEM_WAIT_UNTIL_ALL(vars, nelems, cond, value) do { \ + for (int i = 0; i < nelems; i++) { \ + SHMEM_WAIT_UNTIL_POLL(&vars[i] cond, value); \ + } \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + } while (0) + +#define SHMEM_WAIT_UNTIL_ANY(vars, nelems, status, cond, value, ret) do { \ + ret = 0; \ + int i = 0; \ + size_t idx = 0; \ + if (status) { \ + for (i = 0; i < nelems; i++) { \ + if (!status[i]) { \ + idx = i; \ + break; \ + } \ + } \ + } \ + COMP(cond, vars[idx], value, ret); \ + if (i == nelems) { \ + ret = SIZE_MAX; \ + } \ + while (!ret) { \ + SHMEM_WAIT_UNTIL_POLL_LIMIT(&vars[idx % nelems], cond, value); \ + COMP(cond, vars[idx], value, ret); \ + if (ret) break; \ + for (i = idx+1; i < nelems; i++) { \ + if (status && !status[i%nelems]) { \ + idx = i % nelems; \ + break; \ + } \ + } \ + } \ + if (ret != SIZE_MAX) { \ + status[idx] = 1; \ + ret = idx; \ + } \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + } while (0) + #else #define SHMEM_WAIT(var, value) do { \ if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ @@ -162,6 +236,56 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ } while (0) + +#define SHMEM_WAIT_UNTIL_ALL(vars, nelems, cond, value) do { \ + if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ + for (int i = 0; i < nelems; i++) { \ + SHMEM_WAIT_UNTIL_BLOCK(&vars[i], cond, value); \ + } \ + } else { \ + for (int i = 0; i < nelems; i++) { \ + SHMEM_WAIT_UNTIL_POLL(&vars[i], cond, value); \ + } \ + } \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + } while (0) + +#define SHMEM_WAIT_UNTIL_ANY(vars, nelems, status, cond, value, ret) do { \ + ret = 0; \ + int i = 0; \ + size_t idx = 0; \ + if (status) { \ + for (i = 0; i < nelems; i++) { \ + if (!status[i]) { \ + idx = i; \ + break; \ + } \ + } \ + } \ + COMP(cond, vars[idx], value, ret); \ + if (i == nelems) { \ + ret = SIZE_MAX; \ + } \ + while (!ret) { \ + SHMEM_WAIT_UNTIL_BLOCK_LIMIT(&vars[idx % nelems], cond, value); \ + COMP(cond, vars[idx], value, ret); \ + if (ret) break; \ + for (i = idx+1; i < nelems; i++) { \ + if (status && !status[i%nelems]) { \ + idx = i % nelems; \ + break; \ + } \ + } \ + } \ + if (ret != SIZE_MAX) { \ + status[idx] = 1; \ + ret = idx; \ + } \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + } while (0) + #endif /* HARD_POLLING */ #endif diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index a292243f1..ec35062f5 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -26,6 +26,7 @@ include(shmem_bind_c.m4)dnl #define SHMEM_INTERNAL_INCLUDE #include "shmem.h" +#include "shmemx.h" #include "shmem_internal.h" #include "shmem_atomic.h" #include "shmem_synchronization.h" @@ -48,6 +49,11 @@ include(shmem_bind_c.m4)dnl #pragma weak shmem_wait_until = pshmem_wait_until #define shmem_wait_until pshmem_wait_until +#pragma weak shmemx_wait_until_all = pshmemx_wait_until_all +#define shmemx_wait_until_all pshmemx_wait_until_all +#pragma weak shmemx_wait_until_any = pshmemx_wait_until_any +#define shmemx_wait_until_any pshmemx_wait_until_any + define(`SHMEM_PROF_DEF_WAIT', `#pragma weak shmem_$1_wait = pshmem_$1_wait #define shmem_$1_wait pshmem_$1_wait')dnl @@ -58,11 +64,31 @@ define(`SHMEM_PROF_DEF_WAIT_UNTIL', #define shmem_$1_wait_until pshmem_$1_wait_until')dnl SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_WAIT_UNTIL') +define(`SHMEM_PROF_DEF_WAIT_UNTIL_ALL', +`#pragma weak shmemx_$1_wait_until_all = pshmemx_$1_wait_until_all +#define shmemx_$1_wait_until_all pshmemx_$1_wait_until_all')dnl +SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_WAIT_UNTIL_ALL') + +define(`SHMEM_PROF_DEF_WAIT_UNTIL_ANY', +`#pragma weak shmemx_$1_wait_until_any = pshmemx_$1_wait_until_any +#define shmemx_$1_wait_until_any pshmemx_$1_wait_until_any')dnl +SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_WAIT_UNTIL_ANY') + define(`SHMEM_PROF_DEF_TEST', `#pragma weak shmem_$1_test = pshmem_$1_test #define shmem_$1_test pshmem_$1_test')dnl SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_TEST') +define(`SHMEM_PROF_DEF_TEST_ALL', +`#pragma weak shmemx_$1_test_all = pshmemx_$1_test_all +#define shmemx_$1_test pshmemx_$1_test_all')dnl +SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_TEST_ALL') + +define(`SHMEM_PROF_DEF_TEST_ANY', +`#pragma weak shmemx_$1_test_any = pshmemx_$1_test_any +#define shmemx_$1_test pshmemx_$1_test_any')dnl +SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_TEST_ANY') + #endif /* ENABLE_PROFILING */ void SHMEM_FUNCTION_ATTRIBUTES @@ -122,6 +148,28 @@ shmem_wait_until(long *ivar, int cmp, long value) } +void SHMEM_FUNCTION_ATTRIBUTES +shmemx_wait_until_all(long *ivars, size_t nelems, int cmp, long value) +{ + SHMEM_ERR_CHECK_INITIALIZED(); + SHMEM_ERR_CHECK_SYMMETRIC(ivars, sizeof(long)); + SHMEM_ERR_CHECK_CMP_OP(cmp); + + SHMEM_WAIT_UNTIL_ALL(ivars, nelems, cmp, value); +} + +size_t SHMEM_FUNCTION_ATTRIBUTES +shmemx_wait_until_any(long *ivars, size_t nelems, int * restrict status, int cmp, long value) +{ + SHMEM_ERR_CHECK_INITIALIZED(); + SHMEM_ERR_CHECK_SYMMETRIC(ivars, sizeof(long)); + SHMEM_ERR_CHECK_CMP_OP(cmp); + + size_t ret; + SHMEM_WAIT_UNTIL_ANY(ivars, nelems, status, cmp, value, ret); + return ret; +} + #define SHMEM_DEF_WAIT(STYPE,TYPE) \ void SHMEM_FUNCTION_ATTRIBUTES \ shmem_##STYPE##_wait(TYPE *var, TYPE value) \ @@ -147,6 +195,34 @@ SHMEM_BIND_C_WAIT(`SHMEM_DEF_WAIT') SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL') +#define SHMEM_DEF_WAIT_UNTIL_ALL(STYPE,TYPE) \ + void SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_wait_until_all(TYPE *vars, size_t nelems, int cond, TYPE value) \ + { \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + \ + SHMEM_WAIT_UNTIL_ALL(vars, nelems, cond, value); \ + } + +SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') + +#define SHMEM_DEF_WAIT_UNTIL_ANY(STYPE,TYPE) \ + size_t SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_wait_until_any(TYPE *vars, size_t nelems, int * restrict status, int cond, TYPE value) \ + { \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + \ + size_t ret; \ + SHMEM_WAIT_UNTIL_ANY(vars, nelems, status, cond, value, ret); \ + return ret; \ + } + +SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') + #define SHMEM_DEF_TEST(STYPE,TYPE) \ int SHMEM_FUNCTION_ATTRIBUTES \ shmem_##STYPE##_test(TYPE *var, int cond, TYPE value) \ @@ -164,3 +240,66 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL') } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST') + +#define SHMEM_DEF_TEST_ALL(STYPE,TYPE) \ + int SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_test_all(TYPE *vars, size_t nelems, int cond, TYPE value) \ + { \ + int cmpret; \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + \ + for (int i = 0; i < nelems; i++) { \ + COMP(cond, vars[i], value, cmpret); \ + } \ + if (cmpret) { \ + shmem_internal_membar_load(); \ + } \ + return cmpret; \ + } + +SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') + +#define SHMEM_DEF_TEST_ANY(STYPE,TYPE) \ + size_t SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_test_any(TYPE *vars, size_t nelems, int * restrict status, int cond, TYPE value) \ + { \ + size_t cmpret = 0, idx = 0; \ + int i = 0; \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + \ + if (status) { \ + for (i = 0; i < nelems; i++) { \ + if (!status[i]) { \ + idx = i; \ + break; \ + } \ + } \ + } \ + COMP(cond, vars[idx], value, cmpret); \ + if (i == nelems) { \ + cmpret = SIZE_MAX; \ + } \ + while (!cmpret) { \ + COMP(cond, vars[idx], value, cmpret); \ + if (cmpret) break; \ + for (i = idx+1; i < nelems; i++) { \ + if (status && !status[i%nelems]) { \ + idx = i % nelems; \ + break; \ + } \ + } \ + if (i == nelems) cmpret = SIZE_MAX; \ + } \ + if (cmpret != SIZE_MAX) { \ + status[idx] = 1; \ + cmpret = idx; \ + } \ + shmem_internal_membar_load(); \ + return cmpret; \ + } + +SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 7649c6df8..202c9d58f 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -96,7 +96,11 @@ check_PROGRAMS = \ sync-size \ shmem_ctx_pipelined_reduce \ many-ctx \ - shmem_test + shmem_test \ + shmem_wait_until_all \ + shmem_wait_until_any \ + shmem_test_all \ + shmem_test_any # Temporarily disabled: Global exit test tends to fail with MPI-PMI if !USE_PMI_MPI diff --git a/test/unit/shmem_test_all.c b/test/unit/shmem_test_all.c new file mode 100644 index 000000000..acbf9b78e --- /dev/null +++ b/test/unit/shmem_test_all.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * This test is derived from an example provided in the OpenSHMEM 1.4 + * specification. Additional copyrights may apply. + * + */ + +#include +#include +#include + +int main(void) +{ + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); + + int *flags = shmem_calloc(npes, sizeof(int)); + + for (int i = 0; i < npes; i++) + shmem_p(&flags[mype], 1, i); + + while (!shmemx_test_all(flags, npes, SHMEM_CMP_EQ, 1)) {} + + shmem_free(flags); + shmem_finalize(); + return 0; +} diff --git a/test/unit/shmem_test_any.c b/test/unit/shmem_test_any.c new file mode 100644 index 000000000..bb30f6928 --- /dev/null +++ b/test/unit/shmem_test_any.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * This test is derived from an example provided in the OpenSHMEM 1.4 + * specification. Additional copyrights may apply. + * + */ + +#include +#include +#include + +int main(void) +{ + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); + + int *flags = shmem_calloc(npes, sizeof(int)); + int *status = calloc(npes, sizeof(int)); + int *processed = calloc(npes, sizeof(int)); + + for (int i = 0; i < npes; i++) + shmem_p(&flags[mype], 1, i); + + int ncompleted = 0, completed_idx; + + while (ncompleted < npes) { + completed_idx = shmemx_test_any(flags, npes, status, SHMEM_CMP_EQ, 1); + if (completed_idx != SIZE_MAX && !processed[completed_idx]) { + ncompleted++; + processed[completed_idx] = 1; + } else { + /* Overlap some computation here */ + } + } + + free(status); + shmem_free(flags); + shmem_finalize(); + return 0; +} diff --git a/test/unit/shmem_wait_until_all.c b/test/unit/shmem_wait_until_all.c new file mode 100644 index 000000000..2483a5edc --- /dev/null +++ b/test/unit/shmem_wait_until_all.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * This test is derived from an example provided in the OpenSHMEM 1.4 + * specification. Additional copyrights may apply. + * + */ + +#include +#include +#include + +int main(void) +{ + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); + + int *flags = shmem_calloc(npes, sizeof(int)); + + for (int i = 0; i < npes; i++) + shmem_p(&flags[mype], 1, i); + + shmemx_wait_until_all(flags, npes, SHMEM_CMP_EQ, 1); + + shmem_free(flags); + shmem_finalize(); + return 0; +} diff --git a/test/unit/shmem_wait_until_any.c b/test/unit/shmem_wait_until_any.c new file mode 100644 index 000000000..b04117521 --- /dev/null +++ b/test/unit/shmem_wait_until_any.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * This test is derived from an example provided in the OpenSHMEM 1.4 + * specification. Additional copyrights may apply. + * + */ + +#include +#include +#include +#include + +#define N 100 + +int main(void) +{ + int total_sum = 0; + + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); + + int *my_data = malloc(N * sizeof(int)); + int *all_data = shmem_malloc(N * npes * sizeof(int)); + + int *flags = shmem_calloc(npes, sizeof(int)); + int *status = calloc(npes, sizeof(int)); + + for (int i = 0; i < N; i++) + my_data[i] = mype*N + i; + + for (int i = 0; i < npes; i++) + shmem_put_nbi(&all_data[mype*N], my_data, N, i); + + shmem_fence(); + + for (int i = 0; i < npes; i++) + shmem_p(&flags[mype], 1, i); + + size_t completed_idx; + for (int i = 0; i < npes; i++) { + completed_idx = shmemx_wait_until_any(flags, npes, status, SHMEM_CMP_NE, 0); + for (int j = 0; j < N; j++) + total_sum += all_data[completed_idx * N + j]; + } + + shmem_finalize(); + return 0; +} From 7acc1a02c30d8ff54ae99c65273a0bc9339b2260 Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Mon, 15 Oct 2018 18:02:59 -0400 Subject: [PATCH 02/23] Add shmem_wait_until_some prototype and unit test Signed-off-by: David M. Ozog --- mpp/shmemx.h4.in | 12 +++++++ mpp/shmemx_c_func.h4.in | 5 +++ src/shmem_synchronization.h | 56 +++++++++++++++++++++++++++++++ src/synchronization_c.c4 | 34 +++++++++++++++++++ test/unit/Makefile.am | 1 + test/unit/shmem_wait_until_some.c | 51 ++++++++++++++++++++++++++++ 6 files changed, 159 insertions(+) create mode 100644 test/unit/shmem_wait_until_some.c diff --git a/mpp/shmemx.h4.in b/mpp/shmemx.h4.in index 76f394b39..6497ec025 100644 --- a/mpp/shmemx.h4.in +++ b/mpp/shmemx.h4.in @@ -73,6 +73,12 @@ define(`SHMEM_CXX_WAIT_UNTIL_ANY', }')dnl SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_ANY') +define(`SHMEM_CXX_WAIT_UNTIL_SOME', +`static inline size_t shmemx_wait_until_some($2 *ivars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, $2 cmp_value) { + shmemx_$1_wait_until_some(ivars, nelems, indices, status, cmp, cmp_value); +}')dnl +SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_SOME') + define(`SHMEM_CXX_TEST_ALL', `static inline int shmemx_test_all($2 *ivars, size_t nelems, int cmp, $2 cmp_value) { return shmemx_$1_test_all(ivars, nelems, cmp, cmp_value); @@ -100,6 +106,12 @@ define(`SHMEM_C11_GEN_WAIT_UNTIL_ANY', ` $2*: shmemx_$1_wait_until_any')d SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_WAIT_UNTIL_ANY', `, \') \ )(__VA_ARGS__) +define(`SHMEM_C11_GEN_WAIT_UNTIL_SOME', ` $2*: shmemx_$1_wait_until_SOME')dnl +#define shmemx_wait_until_SOME(...) \ + _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ +SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_WAIT_UNTIL_SOME', `, \') \ + )(__VA_ARGS__) + define(`SHMEM_C11_GEN_TEST_ALL', ` $2*: shmemx_$1_test_all')dnl #define shmemx_test_all(...) \ _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ diff --git a/mpp/shmemx_c_func.h4.in b/mpp/shmemx_c_func.h4.in index 3c23588ff..cd7a99d20 100644 --- a/mpp/shmemx_c_func.h4.in +++ b/mpp/shmemx_c_func.h4.in @@ -47,12 +47,17 @@ define(`SHMEM_C_WAIT_UNTIL_ANY', `SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_wait_until_any($2 *vars, size_t nelems, int * restrict status, int cmp, $2 value);')dnl SHMEM_BIND_C_SYNC(`SHMEM_C_WAIT_UNTIL_ANY') +define(`SHMEM_C_WAIT_UNTIL_SOME', +`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_wait_until_some($2 *vars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, $2 value);')dnl +SHMEM_BIND_C_SYNC(`SHMEM_C_WAIT_UNTIL_SOME') + /* Special case, only enabled when C++ and C11 bindings are disabled */ #if ( !defined(__cplusplus) && \ !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) ) || \ defined(SHMEM_INTERNAL_INCLUDE) || defined(SHMEM_DECLARE_SPECIAL_CASES) SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_wait_until_all(long *ivars, size_t nelems, int cmp, long value); SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_wait_until_any(long *ivars, size_t nelems, int * restrict status, int cmp, long value); +SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_wait_until_some(long *ivars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, long value); #endif define(`SHMEM_C_TEST_ALL', diff --git a/src/shmem_synchronization.h b/src/shmem_synchronization.h index e077b6c86..9f0020bff 100644 --- a/src/shmem_synchronization.h +++ b/src/shmem_synchronization.h @@ -216,6 +216,34 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_transport_syncmem(); \ } while (0) +#define SHMEM_WAIT_UNTIL_SOME(vars, nelems, indices, status, cond, value, ret) do { \ + ret = 0; \ + size_t i = 0, ncompleted = 0, no_wait_len = 0; \ + while (ncompleted == 0) { \ + for (i = 0; i < nelems; i++) { \ + if (status) { \ + if (!status[i]) { \ + SHMEM_WAIT_UNTIL_POLL_LIMIT(&vars[i], cond, value); \ + COMP(cond, vars[i], value, ret); \ + if (ret) { \ + indices[ncompleted++] = i; \ + status[i] = 1; \ + } \ + } else { \ + no_wait_len++; \ + } \ + } \ + } \ + if (no_wait_len == nelems) { \ + ncompleted = 0; \ + break; \ + } \ + } \ + ret = ncompleted; \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + } while (0) + #else #define SHMEM_WAIT(var, value) do { \ if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ @@ -286,6 +314,34 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_transport_syncmem(); \ } while (0) +#define SHMEM_WAIT_UNTIL_SOME(vars, nelems, indices, status, cond, value, ret) do { \ + ret = 0; \ + size_t i = 0, ncompleted = 0, no_wait_len = 0; \ + while (ncompleted == 0) { \ + for (i = 0; i < nelems; i++) { \ + if (status) { \ + if (!status[i]) { \ + SHMEM_WAIT_UNTIL_BLOCK_LIMIT(&vars[i], cond, value); \ + COMP(cond, vars[i], value, ret); \ + if (ret) { \ + indices[ncompleted++] = i; \ + status[i] = 1; \ + } \ + } else { \ + no_wait_len++; \ + } \ + } \ + } \ + if (no_wait_len == nelems) { \ + ncompleted = 0; \ + break; \ + } \ + } \ + ret = ncompleted; \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + } while (0) + #endif /* HARD_POLLING */ #endif diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index ec35062f5..43bfd8996 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -53,6 +53,8 @@ include(shmem_bind_c.m4)dnl #define shmemx_wait_until_all pshmemx_wait_until_all #pragma weak shmemx_wait_until_any = pshmemx_wait_until_any #define shmemx_wait_until_any pshmemx_wait_until_any +#pragma weak shmemx_wait_until_some = pshmemx_wait_until_some +#define shmemx_wait_until_some pshmemx_wait_until_some define(`SHMEM_PROF_DEF_WAIT', `#pragma weak shmem_$1_wait = pshmem_$1_wait @@ -74,6 +76,11 @@ define(`SHMEM_PROF_DEF_WAIT_UNTIL_ANY', #define shmemx_$1_wait_until_any pshmemx_$1_wait_until_any')dnl SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_WAIT_UNTIL_ANY') +define(`SHMEM_PROF_DEF_WAIT_UNTIL_SOME', +`#pragma weak shmemx_$1_wait_until_some = pshmemx_$1_wait_until_some +#define shmemx_$1_wait_until_some pshmemx_$1_wait_until_some')dnl +SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_WAIT_UNTIL_SOME') + define(`SHMEM_PROF_DEF_TEST', `#pragma weak shmem_$1_test = pshmem_$1_test #define shmem_$1_test pshmem_$1_test')dnl @@ -170,6 +177,18 @@ shmemx_wait_until_any(long *ivars, size_t nelems, int * restrict status, int cmp return ret; } +size_t SHMEM_FUNCTION_ATTRIBUTES +shmemx_wait_until_some(long *ivars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, long value) +{ + SHMEM_ERR_CHECK_INITIALIZED(); + SHMEM_ERR_CHECK_SYMMETRIC(ivars, sizeof(long)); + SHMEM_ERR_CHECK_CMP_OP(cmp); + + size_t ret; + SHMEM_WAIT_UNTIL_SOME(ivars, nelems, indices, status, cmp, value, ret); + return ret; +} + #define SHMEM_DEF_WAIT(STYPE,TYPE) \ void SHMEM_FUNCTION_ATTRIBUTES \ shmem_##STYPE##_wait(TYPE *var, TYPE value) \ @@ -223,6 +242,21 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') +#define SHMEM_DEF_WAIT_UNTIL_SOME(STYPE,TYPE) \ + size_t SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_wait_until_some(TYPE *vars, size_t nelems, size_t * restrict indices, int * restrict status, int cond, TYPE value) \ + { \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + \ + size_t ret; \ + SHMEM_WAIT_UNTIL_SOME(vars, nelems, indices, status, cond, value, ret); \ + return ret; \ + } + +SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_SOME') + #define SHMEM_DEF_TEST(STYPE,TYPE) \ int SHMEM_FUNCTION_ATTRIBUTES \ shmem_##STYPE##_test(TYPE *var, int cond, TYPE value) \ diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 202c9d58f..be0e52875 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -99,6 +99,7 @@ check_PROGRAMS = \ shmem_test \ shmem_wait_until_all \ shmem_wait_until_any \ + shmem_wait_until_some \ shmem_test_all \ shmem_test_any diff --git a/test/unit/shmem_wait_until_some.c b/test/unit/shmem_wait_until_some.c new file mode 100644 index 000000000..ac1088659 --- /dev/null +++ b/test/unit/shmem_wait_until_some.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +#define N 100 + +int main(void) +{ + int total_sum = 0; + + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); + + int *my_data = malloc(N * sizeof(int)); + int *all_data = shmem_malloc(N * npes * sizeof(int)); + + int *flags = shmem_calloc(npes, sizeof(int)); + size_t *indices = malloc(npes * sizeof(size_t)); + int *status = calloc(npes, sizeof(int)); + + for (int i = 0; i < N; i++) + my_data[i] = mype*N + i; + + for (int i = 0; i < npes; i++) + shmem_put_nbi(&all_data[mype*N], my_data, N, i); + + shmem_fence(); + + for (int i = 0; i < npes; i++) + shmem_p(&flags[mype], 1, i); + + size_t ncompleted; + while ((ncompleted = shmemx_int_wait_until_some(flags, npes, indices, + status, SHMEM_CMP_NE, 0))) { + for (size_t i = 0; i < ncompleted; i++) { + for (size_t j = 0; j < N; j++) + total_sum += all_data[indices[i]*N + j]; + } + } + + /* check result */ + int M = N * npes - 1; + if (total_sum != M * (M + 1) / 2) { + shmem_global_exit(1); + } + + shmem_finalize(); + return 0; +} From fa5cea61226fb2ed1a3789ee7555868da42c187f Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Tue, 16 Oct 2018 14:30:35 +0000 Subject: [PATCH 03/23] Change wait/test any/all/some tests to use C API Also, check that adding -std=c99 fixes problem with "restrict" qualifier in Cray tests through Travis. Signed-off-by: David M. Ozog --- scripts/travis/cray_tests.sh | 2 +- test/unit/shmem_test_all.c | 4 ++-- test/unit/shmem_test_any.c | 4 ++-- test/unit/shmem_wait_until_all.c | 4 ++-- test/unit/shmem_wait_until_any.c | 6 +++--- test/unit/shmem_wait_until_some.c | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/travis/cray_tests.sh b/scripts/travis/cray_tests.sh index 003a71347..1c7e1c1fe 100755 --- a/scripts/travis/cray_tests.sh +++ b/scripts/travis/cray_tests.sh @@ -2,7 +2,7 @@ #export CUSTOM_SHMEM_DIR="" #export CRAY_TESTS_DIR=" Date: Tue, 16 Oct 2018 12:07:13 -0400 Subject: [PATCH 04/23] Add shmem_test_some prototype and some cleanup Signed-off-by: David M. Ozog --- configure.ac | 6 +- mpp/shmemx.h4.in | 12 +++ mpp/shmemx_c_func.h4.in | 13 +-- src/shmem_synchronization.h | 205 +++++------------------------------- src/synchronization_c.c4 | 141 +++++++++++++++++-------- test/unit/Makefile.am | 3 +- test/unit/shmem_test_some.c | 50 +++++++++ 7 files changed, 200 insertions(+), 230 deletions(-) create mode 100644 test/unit/shmem_test_some.c diff --git a/configure.ac b/configure.ac index 074c823b0..060457e42 100755 --- a/configure.ac +++ b/configure.ac @@ -789,16 +789,16 @@ AS_IF([test "$transport_portals4" != "yes" -a "$transport_ofi" != "yes"], [AC_MSG_WARN([No transport found, resulting library will be unable to exchange messages])]) AS_IF([test "$shmem_cv_c11_works" != "yes"], - [AC_MSG_WARN([C compiler does not support _Generic, unabled to verify and test C11 bindings])]) + [AC_MSG_WARN([C compiler does not support _Generic, unable to verify and test C11 bindings])]) AS_IF([test "$enable_c11_checks" == "no"], [AC_MSG_WARN([C11 _Generic type checks disabled, not verifying type coverage of C11 bindings])]) AS_IF([test "$enable_cxx" == "no"], - [AC_MSG_WARN([No C++ compiler or C++ disabled, unabled to verify and test C++ bindings])]) + [AC_MSG_WARN([No C++ compiler or C++ disabled, unable to verify and test C++ bindings])]) AS_IF([test "$enable_fortran" == "no"], - [AC_MSG_WARN([No Fortran compiler or Fortran disabled, unabled to test Fortran bindings])]) + [AC_MSG_WARN([No Fortran compiler or Fortran disabled, unable to test Fortran bindings])]) AS_IF([test "$enable_fortran" != "no"], [AC_MSG_WARN([Fortran bindings have been deprecated as of OpenSHMEM v1.4])]) diff --git a/mpp/shmemx.h4.in b/mpp/shmemx.h4.in index 6497ec025..eb16bda08 100644 --- a/mpp/shmemx.h4.in +++ b/mpp/shmemx.h4.in @@ -91,6 +91,12 @@ define(`SHMEM_CXX_TEST_ANY', }')dnl SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_TEST_ANY') +define(`SHMEM_CXX_TEST_SOME', +`static inline size_t shmemx_test_some($2 *ivars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, $2 cmp_value) { + return shmemx_$1_test_some(ivars, nelems, indices, status, cmp, cmp_value); +}')dnl +SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_TEST_SOME') + /* C11 Generic Macros */ #elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(SHMEM_INTERNAL_INCLUDE)) @@ -124,6 +130,12 @@ define(`SHMEM_C11_GEN_TEST_ANY', ` $2*: shmemx_$1_test_any')dnl SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_TEST_ANY', `, \') \ )(__VA_ARGS__) +define(`SHMEM_C11_GEN_TEST_SOME', ` $2*: shmemx_$1_test_some')dnl +#define shmemx_test_some(...) \ + _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ +SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_TEST_SOME', `, \') \ + )(__VA_ARGS__) + #endif /* C11 */ #endif /* SHMEMX_H */ diff --git a/mpp/shmemx_c_func.h4.in b/mpp/shmemx_c_func.h4.in index cd7a99d20..60333b8ec 100644 --- a/mpp/shmemx_c_func.h4.in +++ b/mpp/shmemx_c_func.h4.in @@ -51,15 +51,6 @@ define(`SHMEM_C_WAIT_UNTIL_SOME', `SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_wait_until_some($2 *vars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, $2 value);')dnl SHMEM_BIND_C_SYNC(`SHMEM_C_WAIT_UNTIL_SOME') -/* Special case, only enabled when C++ and C11 bindings are disabled */ -#if ( !defined(__cplusplus) && \ - !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) ) || \ - defined(SHMEM_INTERNAL_INCLUDE) || defined(SHMEM_DECLARE_SPECIAL_CASES) -SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_wait_until_all(long *ivars, size_t nelems, int cmp, long value); -SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_wait_until_any(long *ivars, size_t nelems, int * restrict status, int cmp, long value); -SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_wait_until_some(long *ivars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, long value); -#endif - define(`SHMEM_C_TEST_ALL', `SHMEM_FUNCTION_ATTRIBUTES int SHPRE()shmemx_$1_test_all($2 *vars, size_t nelems, int cmp, $2 value);')dnl SHMEM_BIND_C_SYNC(`SHMEM_C_TEST_ALL') @@ -67,3 +58,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_C_TEST_ALL') define(`SHMEM_C_TEST_ANY', `SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_test_any($2 *vars, size_t nelems, int * restrict status, int cmp, $2 value);')dnl SHMEM_BIND_C_SYNC(`SHMEM_C_TEST_ANY') + +define(`SHMEM_C_TEST_SOME', +`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_test_some($2 *vars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, $2 value);')dnl +SHMEM_BIND_C_SYNC(`SHMEM_C_TEST_SOME') diff --git a/src/shmem_synchronization.h b/src/shmem_synchronization.h index 9f0020bff..4f5afa283 100644 --- a/src/shmem_synchronization.h +++ b/src/shmem_synchronization.h @@ -101,20 +101,6 @@ shmem_internal_fence(shmem_ctx_t ctx) } \ } while(0) -#define SHMEM_WAIT_UNTIL_POLL_LIMIT(var, cond, value) \ - do { \ - int cmpret; \ - int poll_cntr = 100; \ - \ - COMP(cond, *(var), value, cmpret); \ - while (!cmpret && poll_cntr) { \ - shmem_transport_probe(); \ - SPINLOCK_BODY(); \ - COMP(cond, *(var), value, cmpret); \ - poll_cntr--; \ - } \ - } while(0) - #define SHMEM_WAIT_BLOCK(var, value) \ do { \ uint64_t target_cntr; \ @@ -143,23 +129,6 @@ shmem_internal_fence(shmem_ctx_t ctx) } \ } while(0) -#define SHMEM_WAIT_UNTIL_BLOCK_LIMIT(var, cond, value) \ - do { \ - uint64_t target_cntr; \ - int cmpret; \ - int poll_cntr = 10; \ - \ - COMP(cond, *(var), value, cmpret); \ - while (!cmpret && poll_cntr) { \ - target_cntr = shmem_transport_received_cntr_get(); \ - COMPILER_FENCE(); \ - COMP(cond, *(var), value, cmpret); \ - if (cmpret) break; \ - shmem_transport_received_cntr_wait(target_cntr + 1); \ - COMP(cond, *(var), value, cmpret); \ - } \ - } while(0) - #if defined(ENABLE_HARD_POLLING) #define SHMEM_WAIT(var, value) do { \ SHMEM_WAIT_POLL(var, value); \ @@ -173,78 +142,22 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_transport_syncmem(); \ } while (0) -#define SHMEM_WAIT_UNTIL_ALL(vars, nelems, cond, value) do { \ - for (int i = 0; i < nelems; i++) { \ - SHMEM_WAIT_UNTIL_POLL(&vars[i] cond, value); \ - } \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) - -#define SHMEM_WAIT_UNTIL_ANY(vars, nelems, status, cond, value, ret) do { \ - ret = 0; \ - int i = 0; \ - size_t idx = 0; \ - if (status) { \ - for (i = 0; i < nelems; i++) { \ - if (!status[i]) { \ - idx = i; \ - break; \ - } \ - } \ - } \ - COMP(cond, vars[idx], value, ret); \ - if (i == nelems) { \ - ret = SIZE_MAX; \ - } \ - while (!ret) { \ - SHMEM_WAIT_UNTIL_POLL_LIMIT(&vars[idx % nelems], cond, value); \ - COMP(cond, vars[idx], value, ret); \ - if (ret) break; \ - for (i = idx+1; i < nelems; i++) { \ - if (status && !status[i%nelems]) { \ - idx = i % nelems; \ - break; \ - } \ - } \ - } \ - if (ret != SIZE_MAX) { \ - status[idx] = 1; \ - ret = idx; \ - } \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) +#define SHMEM_WAIT_UNTIL_THROTTLE(var, cond, value) \ + do { \ + int cmpret; \ + int poll_cntr = 100; \ + \ + COMP(cond, *(var), value, cmpret); \ + while (!cmpret && poll_cntr) { \ + shmem_transport_probe(); \ + SPINLOCK_BODY(); \ + COMP(cond, *(var), value, cmpret); \ + poll_cntr--; \ + } \ + } while(0) -#define SHMEM_WAIT_UNTIL_SOME(vars, nelems, indices, status, cond, value, ret) do { \ - ret = 0; \ - size_t i = 0, ncompleted = 0, no_wait_len = 0; \ - while (ncompleted == 0) { \ - for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - SHMEM_WAIT_UNTIL_POLL_LIMIT(&vars[i], cond, value); \ - COMP(cond, vars[i], value, ret); \ - if (ret) { \ - indices[ncompleted++] = i; \ - status[i] = 1; \ - } \ - } else { \ - no_wait_len++; \ - } \ - } \ - } \ - if (no_wait_len == nelems) { \ - ncompleted = 0; \ - break; \ - } \ - } \ - ret = ncompleted; \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) +#else /* !defined(ENABLE_HARD_POLLING) */ -#else #define SHMEM_WAIT(var, value) do { \ if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ SHMEM_WAIT_BLOCK(var, value); \ @@ -265,82 +178,22 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_transport_syncmem(); \ } while (0) -#define SHMEM_WAIT_UNTIL_ALL(vars, nelems, cond, value) do { \ - if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ - for (int i = 0; i < nelems; i++) { \ - SHMEM_WAIT_UNTIL_BLOCK(&vars[i], cond, value); \ - } \ - } else { \ - for (int i = 0; i < nelems; i++) { \ - SHMEM_WAIT_UNTIL_POLL(&vars[i], cond, value); \ - } \ +#define SHMEM_WAIT_UNTIL_THROTTLE(var, cond, value) \ + do { \ + uint64_t target_cntr; \ + int cmpret; \ + int poll_cntr = 10; \ + \ + COMP(cond, *(var), value, cmpret); \ + while (!cmpret && poll_cntr) { \ + target_cntr = shmem_transport_received_cntr_get(); \ + COMPILER_FENCE(); \ + COMP(cond, *(var), value, cmpret); \ + if (cmpret) break; \ + shmem_transport_received_cntr_wait(target_cntr + 1); \ + COMP(cond, *(var), value, cmpret); \ } \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) - -#define SHMEM_WAIT_UNTIL_ANY(vars, nelems, status, cond, value, ret) do { \ - ret = 0; \ - int i = 0; \ - size_t idx = 0; \ - if (status) { \ - for (i = 0; i < nelems; i++) { \ - if (!status[i]) { \ - idx = i; \ - break; \ - } \ - } \ - } \ - COMP(cond, vars[idx], value, ret); \ - if (i == nelems) { \ - ret = SIZE_MAX; \ - } \ - while (!ret) { \ - SHMEM_WAIT_UNTIL_BLOCK_LIMIT(&vars[idx % nelems], cond, value); \ - COMP(cond, vars[idx], value, ret); \ - if (ret) break; \ - for (i = idx+1; i < nelems; i++) { \ - if (status && !status[i%nelems]) { \ - idx = i % nelems; \ - break; \ - } \ - } \ - } \ - if (ret != SIZE_MAX) { \ - status[idx] = 1; \ - ret = idx; \ - } \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) - -#define SHMEM_WAIT_UNTIL_SOME(vars, nelems, indices, status, cond, value, ret) do { \ - ret = 0; \ - size_t i = 0, ncompleted = 0, no_wait_len = 0; \ - while (ncompleted == 0) { \ - for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - SHMEM_WAIT_UNTIL_BLOCK_LIMIT(&vars[i], cond, value); \ - COMP(cond, vars[i], value, ret); \ - if (ret) { \ - indices[ncompleted++] = i; \ - status[i] = 1; \ - } \ - } else { \ - no_wait_len++; \ - } \ - } \ - } \ - if (no_wait_len == nelems) { \ - ncompleted = 0; \ - break; \ - } \ - } \ - ret = ncompleted; \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) + } while(0) #endif /* HARD_POLLING */ diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index 43bfd8996..5680ed03d 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -96,6 +96,11 @@ define(`SHMEM_PROF_DEF_TEST_ANY', #define shmemx_$1_test pshmemx_$1_test_any')dnl SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_TEST_ANY') +define(`SHMEM_PROF_DEF_TEST_SOME', +`#pragma weak shmemx_$1_test_some = pshmemx_$1_test_some +#define shmemx_$1_test_some pshmemx_$1_test_some')dnl +SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_TEST_SOME') + #endif /* ENABLE_PROFILING */ void SHMEM_FUNCTION_ATTRIBUTES @@ -134,6 +139,7 @@ shmem_ctx_fence(shmem_ctx_t ctx) } +/* This legacy wait API is ignored when using C11 generic bindings: */ void SHMEM_FUNCTION_ATTRIBUTES shmem_wait(long *ivar, long cmp_value) { @@ -143,7 +149,6 @@ shmem_wait(long *ivar, long cmp_value) SHMEM_WAIT(ivar, cmp_value); } - void SHMEM_FUNCTION_ATTRIBUTES shmem_wait_until(long *ivar, int cmp, long value) { @@ -155,40 +160,7 @@ shmem_wait_until(long *ivar, int cmp, long value) } -void SHMEM_FUNCTION_ATTRIBUTES -shmemx_wait_until_all(long *ivars, size_t nelems, int cmp, long value) -{ - SHMEM_ERR_CHECK_INITIALIZED(); - SHMEM_ERR_CHECK_SYMMETRIC(ivars, sizeof(long)); - SHMEM_ERR_CHECK_CMP_OP(cmp); - - SHMEM_WAIT_UNTIL_ALL(ivars, nelems, cmp, value); -} - -size_t SHMEM_FUNCTION_ATTRIBUTES -shmemx_wait_until_any(long *ivars, size_t nelems, int * restrict status, int cmp, long value) -{ - SHMEM_ERR_CHECK_INITIALIZED(); - SHMEM_ERR_CHECK_SYMMETRIC(ivars, sizeof(long)); - SHMEM_ERR_CHECK_CMP_OP(cmp); - - size_t ret; - SHMEM_WAIT_UNTIL_ANY(ivars, nelems, status, cmp, value, ret); - return ret; -} - -size_t SHMEM_FUNCTION_ATTRIBUTES -shmemx_wait_until_some(long *ivars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, long value) -{ - SHMEM_ERR_CHECK_INITIALIZED(); - SHMEM_ERR_CHECK_SYMMETRIC(ivars, sizeof(long)); - SHMEM_ERR_CHECK_CMP_OP(cmp); - - size_t ret; - SHMEM_WAIT_UNTIL_SOME(ivars, nelems, indices, status, cmp, value, ret); - return ret; -} - +/* Non-legacy wait/test API: */ #define SHMEM_DEF_WAIT(STYPE,TYPE) \ void SHMEM_FUNCTION_ATTRIBUTES \ shmem_##STYPE##_wait(TYPE *var, TYPE value) \ @@ -222,7 +194,17 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - SHMEM_WAIT_UNTIL_ALL(vars, nelems, cond, value); \ + if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ + for (int i = 0; i < nelems; i++) { \ + SHMEM_WAIT_UNTIL_BLOCK(&vars[i], cond, value); \ + } \ + } else { \ + for (int i = 0; i < nelems; i++) { \ + SHMEM_WAIT_UNTIL_POLL(&vars[i], cond, value); \ + } \ + } \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') @@ -234,9 +216,36 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ - \ - size_t ret; \ - SHMEM_WAIT_UNTIL_ANY(vars, nelems, status, cond, value, ret); \ + size_t ret = 0, idx = 0, i = 0; \ + if (status) { \ + for (i = 0; i < nelems; i++) { \ + if (!status[i]) { \ + idx = i; \ + break; \ + } \ + } \ + } \ + COMP(cond, vars[idx], value, ret); \ + if (i == nelems) { \ + ret = SIZE_MAX; \ + } \ + while (!ret) { \ + SHMEM_WAIT_UNTIL_THROTTLE(&vars[idx % nelems], cond, value); \ + COMP(cond, vars[idx], value, ret); \ + if (ret) break; \ + for (i = idx+1; i < nelems; i++) { \ + if (status && !status[i%nelems]) { \ + idx = i % nelems; \ + break; \ + } \ + } \ + } \ + if (ret != SIZE_MAX) { \ + status[idx] = 1; \ + ret = idx; \ + } \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ return ret; \ } @@ -250,8 +259,31 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t ret; \ - SHMEM_WAIT_UNTIL_SOME(vars, nelems, indices, status, cond, value, ret); \ + size_t ret = 0, i = 0, ncompleted = 0, npasses = 0, no_wait_len = 0; \ + while (ncompleted == 0) { \ + for (i = 0; i < nelems; i++) { \ + if (status) { \ + if (!status[i]) { \ + SHMEM_WAIT_UNTIL_THROTTLE(&vars[i], cond, value); \ + COMP(cond, vars[i], value, ret); \ + if (ret) { \ + indices[ncompleted++] = i; \ + status[i] = 1; \ + } \ + } else { \ + no_wait_len++; \ + } \ + } \ + } \ + if (no_wait_len == nelems && npasses == 0) { \ + shmem_internal_assert(ncompleted == 0); \ + break; \ + } \ + npasses++; \ + } \ + ret = ncompleted; \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ return ret; \ } @@ -337,3 +369,30 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') + +#define SHMEM_DEF_TEST_SOME(STYPE,TYPE) \ + size_t SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_test_some(TYPE *vars, size_t nelems, size_t * restrict indices, int * restrict status, int cond, TYPE value) \ + { \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + size_t cmpret = 0, i = 0, ncompleted = 0; \ + for (i = 0; i < nelems; i++) { \ + if (status && !status[i]) { \ + SHMEM_WAIT_UNTIL_THROTTLE(&vars[i], cond, value); \ + COMP(cond, vars[i], value, cmpret); \ + if (cmpret) { \ + indices[ncompleted++] = i; \ + status[i] = 1; \ + } \ + } \ + } \ + cmpret = ncompleted; \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + return cmpret; \ + } + +SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_SOME') + diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index be0e52875..b2419a1a8 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -101,7 +101,8 @@ check_PROGRAMS = \ shmem_wait_until_any \ shmem_wait_until_some \ shmem_test_all \ - shmem_test_any + shmem_test_any \ + shmem_test_some # Temporarily disabled: Global exit test tends to fail with MPI-PMI if !USE_PMI_MPI diff --git a/test/unit/shmem_test_some.c b/test/unit/shmem_test_some.c new file mode 100644 index 000000000..14037d772 --- /dev/null +++ b/test/unit/shmem_test_some.c @@ -0,0 +1,50 @@ +#include +#include +#include + +#define N 100 + +int main(void) +{ + int total_sum = 0; + + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); + + int *my_data = malloc(N * sizeof(int)); + int *all_data = shmem_malloc(N * npes * sizeof(int)); + + int *flags = shmem_calloc(npes, sizeof(int)); + size_t *indices = calloc(npes, sizeof(size_t)); + int *status = calloc(npes, sizeof(int)); + + for (int i = 0; i < N; i++) + my_data[i] = mype*N + i; + + for (int i = 0; i < npes; i++) + shmem_int_put_nbi(&all_data[mype*N], my_data, N, i); + + shmem_fence(); + + for (int i = 0; i < npes; i++) + shmem_int_p(&flags[mype], 1, i); + + int ncompleted = 0; + + while (ncompleted < npes) { + int ntested = shmemx_int_test_some(flags, npes, indices, status, SHMEM_CMP_NE, 0); + if (ntested > 0) { + for (int i = 0; i < ntested; i++) { + for (int j = 0; j < N; j++) + total_sum += all_data[indices[i]*N + j]; + } + ncompleted += ntested; + } else { + /* Overlap some computation here */ + } + } + + shmem_finalize(); + return 0; +} From 5ed7b7d9d1639bbfba28416be7c13ac4947b3b31 Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Tue, 16 Oct 2018 15:57:09 -0400 Subject: [PATCH 05/23] Removing wait/test polling stuff & fix correctness Signed-off-by: David M. Ozog --- src/shmem_synchronization.h | 31 ------- src/synchronization_c.c4 | 166 +++++++++++++++++++----------------- test/unit/shmem_test_all.c | 1 - test/unit/shmem_test_any.c | 3 +- 4 files changed, 91 insertions(+), 110 deletions(-) diff --git a/src/shmem_synchronization.h b/src/shmem_synchronization.h index 4f5afa283..c117660fe 100644 --- a/src/shmem_synchronization.h +++ b/src/shmem_synchronization.h @@ -142,20 +142,6 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_transport_syncmem(); \ } while (0) -#define SHMEM_WAIT_UNTIL_THROTTLE(var, cond, value) \ - do { \ - int cmpret; \ - int poll_cntr = 100; \ - \ - COMP(cond, *(var), value, cmpret); \ - while (!cmpret && poll_cntr) { \ - shmem_transport_probe(); \ - SPINLOCK_BODY(); \ - COMP(cond, *(var), value, cmpret); \ - poll_cntr--; \ - } \ - } while(0) - #else /* !defined(ENABLE_HARD_POLLING) */ #define SHMEM_WAIT(var, value) do { \ @@ -178,23 +164,6 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_transport_syncmem(); \ } while (0) -#define SHMEM_WAIT_UNTIL_THROTTLE(var, cond, value) \ - do { \ - uint64_t target_cntr; \ - int cmpret; \ - int poll_cntr = 10; \ - \ - COMP(cond, *(var), value, cmpret); \ - while (!cmpret && poll_cntr) { \ - target_cntr = shmem_transport_received_cntr_get(); \ - COMPILER_FENCE(); \ - COMP(cond, *(var), value, cmpret); \ - if (cmpret) break; \ - shmem_transport_received_cntr_wait(target_cntr + 1); \ - COMP(cond, *(var), value, cmpret); \ - } \ - } while(0) - #endif /* HARD_POLLING */ #endif diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index 5680ed03d..328aa75e0 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -48,7 +48,6 @@ include(shmem_bind_c.m4)dnl #define shmem_wait pshmem_wait #pragma weak shmem_wait_until = pshmem_wait_until #define shmem_wait_until pshmem_wait_until - #pragma weak shmemx_wait_until_all = pshmemx_wait_until_all #define shmemx_wait_until_all pshmemx_wait_until_all #pragma weak shmemx_wait_until_any = pshmemx_wait_until_any @@ -56,6 +55,15 @@ include(shmem_bind_c.m4)dnl #pragma weak shmemx_wait_until_some = pshmemx_wait_until_some #define shmemx_wait_until_some pshmemx_wait_until_some +#pragma weak shmem_test = pshmem_test +#define shmem_test pshmem_test +#pragma weak shmemx_test_all = pshmemx_test_all +#define shmemx_test_all pshmemx_test_all +#pragma weak shmemx_test_any = pshmemx_test_any +#define shmemx_test_any pshmemx_test_any +#pragma weak shmemx_test_some = pshmemx_test_some +#define shmemx_test_some pshmemx_test_some + define(`SHMEM_PROF_DEF_WAIT', `#pragma weak shmem_$1_wait = pshmem_$1_wait #define shmem_$1_wait pshmem_$1_wait')dnl @@ -194,17 +202,20 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ - for (int i = 0; i < nelems; i++) { \ - SHMEM_WAIT_UNTIL_BLOCK(&vars[i], cond, value); \ - } \ - } else { \ - for (int i = 0; i < nelems; i++) { \ - SHMEM_WAIT_UNTIL_POLL(&vars[i], cond, value); \ + size_t ret = 0, i = 0, ncompleted = 0; \ + size_t *completed = calloc(nelems, sizeof(size_t)); \ + while (ncompleted < nelems) { \ + for (i = 0; i < nelems; i++) { \ + COMP(cond, vars[i], value, ret); \ + if (!completed[i] && ret) { \ + completed[i] = 1; \ + ncompleted++; \ + } \ } \ } \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ + free(completed); \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') @@ -216,34 +227,31 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ - size_t ret = 0, idx = 0, i = 0; \ - if (status) { \ + \ + size_t ret = 0, i = 0, npasses = 0, no_wait_len = 0; \ + while (!ret) { \ for (i = 0; i < nelems; i++) { \ - if (!status[i]) { \ - idx = i; \ - break; \ + if (status) { \ + if (!status[i]) { \ + COMP(cond, vars[i], value, ret); \ + } else { \ + no_wait_len++; \ + } \ + } else { \ + COMP(cond, vars[i], value, ret); \ } \ - } \ - } \ - COMP(cond, vars[idx], value, ret); \ - if (i == nelems) { \ - ret = SIZE_MAX; \ - } \ - while (!ret) { \ - SHMEM_WAIT_UNTIL_THROTTLE(&vars[idx % nelems], cond, value); \ - COMP(cond, vars[idx], value, ret); \ - if (ret) break; \ - for (i = idx+1; i < nelems; i++) { \ - if (status && !status[i%nelems]) { \ - idx = i % nelems; \ + if (ret) { \ + if (status) status[i] = 1; \ break; \ } \ } \ + if (no_wait_len == nelems && npasses == 0) { \ + ret = SIZE_MAX; \ + } \ + shmem_transport_probe(); \ + npasses++; \ } \ - if (ret != SIZE_MAX) { \ - status[idx] = 1; \ - ret = idx; \ - } \ + if (ret != SIZE_MAX) ret = i; \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ return ret; \ @@ -264,21 +272,23 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') for (i = 0; i < nelems; i++) { \ if (status) { \ if (!status[i]) { \ - SHMEM_WAIT_UNTIL_THROTTLE(&vars[i], cond, value); \ COMP(cond, vars[i], value, ret); \ - if (ret) { \ - indices[ncompleted++] = i; \ - status[i] = 1; \ - } \ } else { \ no_wait_len++; \ } \ + } else { \ + COMP(cond, vars[i], value, ret); \ + } \ + if (ret) { \ + if (status) status[i] = 1; \ + indices[ncompleted++] = i; \ } \ } \ if (no_wait_len == nelems && npasses == 0) { \ shmem_internal_assert(ncompleted == 0); \ break; \ } \ + shmem_transport_probe(); \ npasses++; \ } \ ret = ncompleted; \ @@ -293,16 +303,16 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_SOME') int SHMEM_FUNCTION_ATTRIBUTES \ shmem_##STYPE##_test(TYPE *var, int cond, TYPE value) \ { \ - int cmpret; \ + int ret; \ SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(var, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - COMP(cond, *(var), value, cmpret); \ - if (cmpret) { \ + COMP(cond, *(var), value, ret); \ + if (ret) { \ shmem_internal_membar_load(); \ } \ - return cmpret; \ + return ret; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST') @@ -311,18 +321,21 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST') int SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_test_all(TYPE *vars, size_t nelems, int cond, TYPE value) \ { \ - int cmpret; \ + int ret, ncompleted = 0; \ SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ for (int i = 0; i < nelems; i++) { \ - COMP(cond, vars[i], value, cmpret); \ + COMP(cond, vars[i], value, ret); \ + if (ret) ncompleted++; \ } \ - if (cmpret) { \ - shmem_internal_membar_load(); \ + shmem_internal_membar_load(); \ + if (ncompleted == nelems) { \ + return 1; \ + } else { \ + return 0; \ } \ - return cmpret; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') @@ -331,41 +344,31 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') size_t SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_test_any(TYPE *vars, size_t nelems, int * restrict status, int cond, TYPE value) \ { \ - size_t cmpret = 0, idx = 0; \ - int i = 0; \ SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - if (status) { \ - for (i = 0; i < nelems; i++) { \ + size_t ret = 0, i = 0; \ + for (i = 0; i < nelems; i++) { \ + if (status) { \ if (!status[i]) { \ - idx = i; \ - break; \ + COMP(cond, vars[i], value, ret); \ } \ + } else { \ + COMP(cond, vars[i], value, ret); \ } \ - } \ - COMP(cond, vars[idx], value, cmpret); \ - if (i == nelems) { \ - cmpret = SIZE_MAX; \ - } \ - while (!cmpret) { \ - COMP(cond, vars[idx], value, cmpret); \ - if (cmpret) break; \ - for (i = idx+1; i < nelems; i++) { \ - if (status && !status[i%nelems]) { \ - idx = i % nelems; \ - break; \ - } \ + if (ret) { \ + if (status) status[i] = 1; \ + break; \ } \ - if (i == nelems) cmpret = SIZE_MAX; \ } \ - if (cmpret != SIZE_MAX) { \ - status[idx] = 1; \ - cmpret = idx; \ + if (i == nelems) { \ + ret = SIZE_MAX; \ + } else { \ + ret = i; \ } \ shmem_internal_membar_load(); \ - return cmpret; \ + return ret; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') @@ -377,21 +380,30 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ - size_t cmpret = 0, i = 0, ncompleted = 0; \ + \ + size_t ret = 0, i = 0, ncompleted = 0, no_wait_len = 0; \ for (i = 0; i < nelems; i++) { \ - if (status && !status[i]) { \ - SHMEM_WAIT_UNTIL_THROTTLE(&vars[i], cond, value); \ - COMP(cond, vars[i], value, cmpret); \ - if (cmpret) { \ - indices[ncompleted++] = i; \ - status[i] = 1; \ + if (status) { \ + if (!status[i]) { \ + COMP(cond, vars[i], value, ret); \ + } else { \ + no_wait_len++; \ } \ + } else { \ + COMP(cond, vars[i], value, ret); \ } \ + if (ret) { \ + if (status) status[i] = 1; \ + indices[ncompleted++] = i; \ + } \ + } \ + if (no_wait_len == nelems) { \ + shmem_internal_assert(ncompleted == 0); \ } \ - cmpret = ncompleted; \ + ret = ncompleted; \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ - return cmpret; \ + return ret; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_SOME') diff --git a/test/unit/shmem_test_all.c b/test/unit/shmem_test_all.c index 55f11bcb3..6f50c9218 100644 --- a/test/unit/shmem_test_all.c +++ b/test/unit/shmem_test_all.c @@ -29,7 +29,6 @@ * */ -#include #include #include diff --git a/test/unit/shmem_test_any.c b/test/unit/shmem_test_any.c index 8e77aa269..8fab15d3c 100644 --- a/test/unit/shmem_test_any.c +++ b/test/unit/shmem_test_any.c @@ -46,7 +46,8 @@ int main(void) for (int i = 0; i < npes; i++) shmem_int_p(&flags[mype], 1, i); - int ncompleted = 0, completed_idx; + int ncompleted = 0; + size_t completed_idx; while (ncompleted < npes) { completed_idx = shmemx_int_test_any(flags, npes, status, SHMEM_CMP_EQ, 1); From 338f183cbe82065bc1f8d9175dad5113b539f1cd Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Tue, 16 Oct 2018 20:36:29 +0000 Subject: [PATCH 06/23] Remove pragma weak symbols for wait/test pshmem And other miscellaneous cleanup Signed-off-by: David M. Ozog --- mpp/shmemx.h4.in | 6 - src/shmem_synchronization.h | 4 +- src/synchronization_c.c4 | 287 ++++++++++++++---------------- test/unit/shmem_test_some.c | 6 + test/unit/shmem_wait_until_all.c | 1 - test/unit/shmem_wait_until_any.c | 7 +- test/unit/shmem_wait_until_some.c | 1 - 7 files changed, 150 insertions(+), 162 deletions(-) diff --git a/mpp/shmemx.h4.in b/mpp/shmemx.h4.in index eb16bda08..dbf03464e 100644 --- a/mpp/shmemx.h4.in +++ b/mpp/shmemx.h4.in @@ -55,12 +55,6 @@ include(shmemx_c_func.h4)dnl #ifdef __cplusplus } /* extern "C" */ -#if __cplusplus >= 201402L -#define SHMEM_CXX_ATTRIBUTE_DEPRECATED [[deprecated]] -#else -#define SHMEM_CXX_ATTRIBUTE_DEPRECATED -#endif - define(`SHMEM_CXX_WAIT_UNTIL_ALL', `static inline void shmemx_wait_until_all($2 *ivars, size_t nelems, int cmp, $2 cmp_value) { shmemx_$1_wait_until_all(ivars, nelems, cmp, cmp_value); diff --git a/src/shmem_synchronization.h b/src/shmem_synchronization.h index c117660fe..f356fda1d 100644 --- a/src/shmem_synchronization.h +++ b/src/shmem_synchronization.h @@ -142,8 +142,7 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_transport_syncmem(); \ } while (0) -#else /* !defined(ENABLE_HARD_POLLING) */ - +#else #define SHMEM_WAIT(var, value) do { \ if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ SHMEM_WAIT_BLOCK(var, value); \ @@ -163,7 +162,6 @@ shmem_internal_fence(shmem_ctx_t ctx) shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ } while (0) - #endif /* HARD_POLLING */ #endif diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index 328aa75e0..a1a5e7e88 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -26,7 +26,6 @@ include(shmem_bind_c.m4)dnl #define SHMEM_INTERNAL_INCLUDE #include "shmem.h" -#include "shmemx.h" #include "shmem_internal.h" #include "shmem_atomic.h" #include "shmem_synchronization.h" @@ -48,21 +47,6 @@ include(shmem_bind_c.m4)dnl #define shmem_wait pshmem_wait #pragma weak shmem_wait_until = pshmem_wait_until #define shmem_wait_until pshmem_wait_until -#pragma weak shmemx_wait_until_all = pshmemx_wait_until_all -#define shmemx_wait_until_all pshmemx_wait_until_all -#pragma weak shmemx_wait_until_any = pshmemx_wait_until_any -#define shmemx_wait_until_any pshmemx_wait_until_any -#pragma weak shmemx_wait_until_some = pshmemx_wait_until_some -#define shmemx_wait_until_some pshmemx_wait_until_some - -#pragma weak shmem_test = pshmem_test -#define shmem_test pshmem_test -#pragma weak shmemx_test_all = pshmemx_test_all -#define shmemx_test_all pshmemx_test_all -#pragma weak shmemx_test_any = pshmemx_test_any -#define shmemx_test_any pshmemx_test_any -#pragma weak shmemx_test_some = pshmemx_test_some -#define shmemx_test_some pshmemx_test_some define(`SHMEM_PROF_DEF_WAIT', `#pragma weak shmem_$1_wait = pshmem_$1_wait @@ -96,12 +80,12 @@ SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_TEST') define(`SHMEM_PROF_DEF_TEST_ALL', `#pragma weak shmemx_$1_test_all = pshmemx_$1_test_all -#define shmemx_$1_test pshmemx_$1_test_all')dnl +#define shmemx_$1_test_all pshmemx_$1_test_all')dnl SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_TEST_ALL') define(`SHMEM_PROF_DEF_TEST_ANY', `#pragma weak shmemx_$1_test_any = pshmemx_$1_test_any -#define shmemx_$1_test pshmemx_$1_test_any')dnl +#define shmemx_$1_test_any pshmemx_$1_test_any')dnl SHMEM_BIND_C_SYNC(`SHMEM_PROF_DEF_TEST_ANY') define(`SHMEM_PROF_DEF_TEST_SOME', @@ -220,81 +204,83 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL') SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') -#define SHMEM_DEF_WAIT_UNTIL_ANY(STYPE,TYPE) \ - size_t SHMEM_FUNCTION_ATTRIBUTES \ - shmemx_##STYPE##_wait_until_any(TYPE *vars, size_t nelems, int * restrict status, int cond, TYPE value) \ - { \ - SHMEM_ERR_CHECK_INITIALIZED(); \ - SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ - SHMEM_ERR_CHECK_CMP_OP(cond); \ - \ - size_t ret = 0, i = 0, npasses = 0, no_wait_len = 0; \ - while (!ret) { \ - for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - COMP(cond, vars[i], value, ret); \ - } else { \ - no_wait_len++; \ - } \ - } else { \ - COMP(cond, vars[i], value, ret); \ - } \ - if (ret) { \ - if (status) status[i] = 1; \ - break; \ - } \ - } \ - if (no_wait_len == nelems && npasses == 0) { \ - ret = SIZE_MAX; \ - } \ - shmem_transport_probe(); \ - npasses++; \ - } \ - if (ret != SIZE_MAX) ret = i; \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - return ret; \ +#define SHMEM_DEF_WAIT_UNTIL_ANY(STYPE,TYPE) \ + size_t SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_wait_until_any(TYPE *vars, size_t nelems, \ + int * restrict status, int cond, TYPE value) \ + { \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + \ + size_t ret = 0, i = 0, npasses = 0, no_wait_len = 0; \ + while (!ret) { \ + for (i = 0; i < nelems; i++) { \ + if (status) { \ + if (!status[i]) { \ + COMP(cond, vars[i], value, ret); \ + } else { \ + no_wait_len++; \ + } \ + } else { \ + COMP(cond, vars[i], value, ret); \ + } \ + if (ret) { \ + if (status) status[i] = 1; \ + break; \ + } \ + } \ + if (no_wait_len == nelems && npasses == 0) { \ + ret = SIZE_MAX; \ + } \ + shmem_transport_probe(); \ + npasses++; \ + } \ + if (ret != SIZE_MAX) ret = i; \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + return ret; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') -#define SHMEM_DEF_WAIT_UNTIL_SOME(STYPE,TYPE) \ - size_t SHMEM_FUNCTION_ATTRIBUTES \ - shmemx_##STYPE##_wait_until_some(TYPE *vars, size_t nelems, size_t * restrict indices, int * restrict status, int cond, TYPE value) \ - { \ - SHMEM_ERR_CHECK_INITIALIZED(); \ - SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ - SHMEM_ERR_CHECK_CMP_OP(cond); \ - \ - size_t ret = 0, i = 0, ncompleted = 0, npasses = 0, no_wait_len = 0; \ - while (ncompleted == 0) { \ - for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - COMP(cond, vars[i], value, ret); \ - } else { \ - no_wait_len++; \ - } \ - } else { \ - COMP(cond, vars[i], value, ret); \ - } \ - if (ret) { \ - if (status) status[i] = 1; \ - indices[ncompleted++] = i; \ - } \ - } \ - if (no_wait_len == nelems && npasses == 0) { \ - shmem_internal_assert(ncompleted == 0); \ - break; \ - } \ - shmem_transport_probe(); \ - npasses++; \ - } \ - ret = ncompleted; \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - return ret; \ +#define SHMEM_DEF_WAIT_UNTIL_SOME(STYPE,TYPE) \ + size_t SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_wait_until_some(TYPE *vars, size_t nelems, size_t * restrict indices, \ + int * restrict status, int cond, TYPE value) \ + { \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + \ + size_t ret = 0, i = 0, ncompleted = 0, npasses = 0, no_wait_len = 0; \ + while (ncompleted == 0) { \ + for (i = 0; i < nelems; i++) { \ + if (status) { \ + if (!status[i]) { \ + COMP(cond, vars[i], value, ret); \ + } else { \ + no_wait_len++; \ + } \ + } else { \ + COMP(cond, vars[i], value, ret); \ + } \ + if (ret) { \ + if (status) status[i] = 1; \ + indices[ncompleted++] = i; \ + } \ + } \ + if (no_wait_len == nelems && npasses == 0) { \ + shmem_internal_assert(ncompleted == 0); \ + break; \ + } \ + shmem_transport_probe(); \ + npasses++; \ + } \ + ret = ncompleted; \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + return ret; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_SOME') @@ -340,71 +326,72 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST') SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') -#define SHMEM_DEF_TEST_ANY(STYPE,TYPE) \ - size_t SHMEM_FUNCTION_ATTRIBUTES \ - shmemx_##STYPE##_test_any(TYPE *vars, size_t nelems, int * restrict status, int cond, TYPE value) \ - { \ - SHMEM_ERR_CHECK_INITIALIZED(); \ - SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ - SHMEM_ERR_CHECK_CMP_OP(cond); \ - \ - size_t ret = 0, i = 0; \ - for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - COMP(cond, vars[i], value, ret); \ - } \ - } else { \ - COMP(cond, vars[i], value, ret); \ - } \ - if (ret) { \ - if (status) status[i] = 1; \ - break; \ - } \ - } \ - if (i == nelems) { \ - ret = SIZE_MAX; \ - } else { \ - ret = i; \ - } \ - shmem_internal_membar_load(); \ - return ret; \ +#define SHMEM_DEF_TEST_ANY(STYPE,TYPE) \ + size_t SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_test_any(TYPE *vars, size_t nelems, int * restrict status, \ + int cond, TYPE value) \ + { \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + \ + size_t ret = 0, i = 0; \ + for (i = 0; i < nelems; i++) { \ + if (status) { \ + if (!status[i]) { \ + COMP(cond, vars[i], value, ret); \ + } \ + } else { \ + COMP(cond, vars[i], value, ret); \ + } \ + if (ret) { \ + if (status) status[i] = 1; \ + break; \ + } \ + } \ + if (i == nelems) { \ + ret = SIZE_MAX; \ + } else { \ + ret = i; \ + } \ + shmem_internal_membar_load(); \ + return ret; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') -#define SHMEM_DEF_TEST_SOME(STYPE,TYPE) \ - size_t SHMEM_FUNCTION_ATTRIBUTES \ - shmemx_##STYPE##_test_some(TYPE *vars, size_t nelems, size_t * restrict indices, int * restrict status, int cond, TYPE value) \ - { \ - SHMEM_ERR_CHECK_INITIALIZED(); \ - SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ - SHMEM_ERR_CHECK_CMP_OP(cond); \ - \ - size_t ret = 0, i = 0, ncompleted = 0, no_wait_len = 0; \ - for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - COMP(cond, vars[i], value, ret); \ - } else { \ - no_wait_len++; \ - } \ - } else { \ - COMP(cond, vars[i], value, ret); \ - } \ - if (ret) { \ - if (status) status[i] = 1; \ - indices[ncompleted++] = i; \ - } \ - } \ - if (no_wait_len == nelems) { \ - shmem_internal_assert(ncompleted == 0); \ - } \ - ret = ncompleted; \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - return ret; \ +#define SHMEM_DEF_TEST_SOME(STYPE,TYPE) \ + size_t SHMEM_FUNCTION_ATTRIBUTES \ + shmemx_##STYPE##_test_some(TYPE *vars, size_t nelems, size_t * restrict indices, \ + int * restrict status, int cond, TYPE value) \ + { \ + SHMEM_ERR_CHECK_INITIALIZED(); \ + SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ + SHMEM_ERR_CHECK_CMP_OP(cond); \ + \ + size_t ret = 0, i = 0, ncompleted = 0, no_wait_len = 0; \ + for (i = 0; i < nelems; i++) { \ + if (status) { \ + if (!status[i]) { \ + COMP(cond, vars[i], value, ret); \ + } else { \ + no_wait_len++; \ + } \ + } else { \ + COMP(cond, vars[i], value, ret); \ + } \ + if (ret) { \ + if (status) status[i] = 1; \ + indices[ncompleted++] = i; \ + } \ + } \ + if (no_wait_len == nelems) { \ + shmem_internal_assert(ncompleted == 0); \ + } \ + ret = ncompleted; \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + return ret; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_SOME') - diff --git a/test/unit/shmem_test_some.c b/test/unit/shmem_test_some.c index 14037d772..521a0ef33 100644 --- a/test/unit/shmem_test_some.c +++ b/test/unit/shmem_test_some.c @@ -45,6 +45,12 @@ int main(void) } } + /* check result */ + int M = N * npes - 1; + if (total_sum != M * (M + 1) / 2) { + shmem_global_exit(1); + } + shmem_finalize(); return 0; } diff --git a/test/unit/shmem_wait_until_all.c b/test/unit/shmem_wait_until_all.c index 0ea330132..0027c5d82 100644 --- a/test/unit/shmem_wait_until_all.c +++ b/test/unit/shmem_wait_until_all.c @@ -29,7 +29,6 @@ * */ -#include #include #include diff --git a/test/unit/shmem_wait_until_any.c b/test/unit/shmem_wait_until_any.c index 5607dff8d..8832570c3 100644 --- a/test/unit/shmem_wait_until_any.c +++ b/test/unit/shmem_wait_until_any.c @@ -32,7 +32,6 @@ #include #include #include -#include #define N 100 @@ -68,6 +67,12 @@ int main(void) total_sum += all_data[completed_idx * N + j]; } + /* check result */ + int M = N * npes - 1; + if (total_sum != M * (M + 1) / 2) { + shmem_global_exit(1); + } + shmem_finalize(); return 0; } diff --git a/test/unit/shmem_wait_until_some.c b/test/unit/shmem_wait_until_some.c index 974c10dbd..a1ee688b7 100644 --- a/test/unit/shmem_wait_until_some.c +++ b/test/unit/shmem_wait_until_some.c @@ -1,7 +1,6 @@ #include #include #include -#include #define N 100 From 647db7b35efe041db5af87f337b49b3dfd6087e4 Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Tue, 16 Oct 2018 17:36:43 -0400 Subject: [PATCH 07/23] Move wait/test all/any/some tests to 'shmemx' dir Signed-off-by: David M. Ozog --- test/shmemx/Makefile.am | 8 +++++++- test/{unit/shmem_test_all.c => shmemx/shmemx_test_all.c} | 0 test/{unit/shmem_test_any.c => shmemx/shmemx_test_any.c} | 0 .../{unit/shmem_test_some.c => shmemx/shmemx_test_some.c} | 0 .../shmemx_wait_until_all.c} | 0 .../shmemx_wait_until_any.c} | 0 .../shmemx_wait_until_some.c} | 0 test/unit/Makefile.am | 8 +------- 8 files changed, 8 insertions(+), 8 deletions(-) rename test/{unit/shmem_test_all.c => shmemx/shmemx_test_all.c} (100%) rename test/{unit/shmem_test_any.c => shmemx/shmemx_test_any.c} (100%) rename test/{unit/shmem_test_some.c => shmemx/shmemx_test_some.c} (100%) rename test/{unit/shmem_wait_until_all.c => shmemx/shmemx_wait_until_all.c} (100%) rename test/{unit/shmem_wait_until_any.c => shmemx/shmemx_wait_until_any.c} (100%) rename test/{unit/shmem_wait_until_some.c => shmemx/shmemx_wait_until_some.c} (100%) diff --git a/test/shmemx/Makefile.am b/test/shmemx/Makefile.am index 213389775..a8d0ae604 100644 --- a/test/shmemx/Makefile.am +++ b/test/shmemx/Makefile.am @@ -11,7 +11,13 @@ # information, see the LICENSE file in the top level directory of the # distribution. -check_PROGRAMS = +check_PROGRAMS = \ + shmemx_wait_until_all \ + shmemx_wait_until_any \ + shmemx_wait_until_some \ + shmemx_test_all \ + shmemx_test_any \ + shmemx_test_some if ENABLE_PROFILING check_PROGRAMS += \ diff --git a/test/unit/shmem_test_all.c b/test/shmemx/shmemx_test_all.c similarity index 100% rename from test/unit/shmem_test_all.c rename to test/shmemx/shmemx_test_all.c diff --git a/test/unit/shmem_test_any.c b/test/shmemx/shmemx_test_any.c similarity index 100% rename from test/unit/shmem_test_any.c rename to test/shmemx/shmemx_test_any.c diff --git a/test/unit/shmem_test_some.c b/test/shmemx/shmemx_test_some.c similarity index 100% rename from test/unit/shmem_test_some.c rename to test/shmemx/shmemx_test_some.c diff --git a/test/unit/shmem_wait_until_all.c b/test/shmemx/shmemx_wait_until_all.c similarity index 100% rename from test/unit/shmem_wait_until_all.c rename to test/shmemx/shmemx_wait_until_all.c diff --git a/test/unit/shmem_wait_until_any.c b/test/shmemx/shmemx_wait_until_any.c similarity index 100% rename from test/unit/shmem_wait_until_any.c rename to test/shmemx/shmemx_wait_until_any.c diff --git a/test/unit/shmem_wait_until_some.c b/test/shmemx/shmemx_wait_until_some.c similarity index 100% rename from test/unit/shmem_wait_until_some.c rename to test/shmemx/shmemx_wait_until_some.c diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index b2419a1a8..7649c6df8 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -96,13 +96,7 @@ check_PROGRAMS = \ sync-size \ shmem_ctx_pipelined_reduce \ many-ctx \ - shmem_test \ - shmem_wait_until_all \ - shmem_wait_until_any \ - shmem_wait_until_some \ - shmem_test_all \ - shmem_test_any \ - shmem_test_some + shmem_test # Temporarily disabled: Global exit test tends to fail with MPI-PMI if !USE_PMI_MPI From af371db1d72891edc2ec5b7c2e4532691e0f1965 Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Wed, 17 Oct 2018 02:37:10 +0000 Subject: [PATCH 08/23] Fix bug in wait/test some routines Signed-off-by: David M. Ozog --- src/synchronization_c.c4 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index a1a5e7e88..5f75543fc 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -268,6 +268,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') if (ret) { \ if (status) status[i] = 1; \ indices[ncompleted++] = i; \ + ret = 0; \ } \ } \ if (no_wait_len == nelems && npasses == 0) { \ @@ -383,6 +384,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') if (ret) { \ if (status) status[i] = 1; \ indices[ncompleted++] = i; \ + ret = 0; \ } \ } \ if (no_wait_len == nelems) { \ From 46af8bec79a40ca52a797a36d872c1586dc58b7a Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Wed, 17 Oct 2018 10:34:20 -0400 Subject: [PATCH 09/23] Add C11 tests for shmemx wait/test any/all/some Signed-off-by: David M. Ozog --- mpp/shmemx.h4.in | 4 +- test/shmemx/Makefile.am | 4 +- test/shmemx/c11_test_shmemx_test.c | 144 ++++++++++++++++++++++ test/shmemx/c11_test_shmemx_wait_until.c | 145 +++++++++++++++++++++++ 4 files changed, 294 insertions(+), 3 deletions(-) create mode 100644 test/shmemx/c11_test_shmemx_test.c create mode 100644 test/shmemx/c11_test_shmemx_wait_until.c diff --git a/mpp/shmemx.h4.in b/mpp/shmemx.h4.in index dbf03464e..31a1fb1a4 100644 --- a/mpp/shmemx.h4.in +++ b/mpp/shmemx.h4.in @@ -106,8 +106,8 @@ define(`SHMEM_C11_GEN_WAIT_UNTIL_ANY', ` $2*: shmemx_$1_wait_until_any')d SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_WAIT_UNTIL_ANY', `, \') \ )(__VA_ARGS__) -define(`SHMEM_C11_GEN_WAIT_UNTIL_SOME', ` $2*: shmemx_$1_wait_until_SOME')dnl -#define shmemx_wait_until_SOME(...) \ +define(`SHMEM_C11_GEN_WAIT_UNTIL_SOME', ` $2*: shmemx_$1_wait_until_some')dnl +#define shmemx_wait_until_some(...) \ _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_WAIT_UNTIL_SOME', `, \') \ )(__VA_ARGS__) diff --git a/test/shmemx/Makefile.am b/test/shmemx/Makefile.am index a8d0ae604..33d586ba7 100644 --- a/test/shmemx/Makefile.am +++ b/test/shmemx/Makefile.am @@ -17,7 +17,9 @@ check_PROGRAMS = \ shmemx_wait_until_some \ shmemx_test_all \ shmemx_test_any \ - shmemx_test_some + shmemx_test_some \ + c11_test_shmemx_wait_until \ + c11_test_shmemx_test if ENABLE_PROFILING check_PROGRAMS += \ diff --git a/test/shmemx/c11_test_shmemx_test.c b/test/shmemx/c11_test_shmemx_test.c new file mode 100644 index 000000000..b1414a881 --- /dev/null +++ b/test/shmemx/c11_test_shmemx_test.c @@ -0,0 +1,144 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + +#define TEST_SHMEM_TEST_ALL(TYPE) \ + do { \ + static TYPE remote = 0; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + shmem_p(&remote, (TYPE)mype+1, (mype + 1) % npes); \ + while (!shmemx_test_all(&remote, 1, SHMEM_CMP_NE, 0)) ; \ + if (remote != (TYPE)((mype + npes - 1) % npes)+1) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_TEST_ALL(%s)\n", mype, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +#define TEST_SHMEM_TEST_ANY(TYPE) \ + do { \ + static TYPE remote = 0; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + int status = 0; \ + shmem_p(&remote, (TYPE)mype+1, (mype + 1) % npes); \ + while (shmemx_test_any(&remote, 1, &status, SHMEM_CMP_NE, 0) == SIZE_MAX); \ + if (remote != (TYPE)((mype + npes - 1) % npes)+1) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_TEST_ANY(%s)\n", mype, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +#define TEST_SHMEM_TEST_SOME(TYPE) \ + do { \ + static TYPE remote = 0; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + int status = 0; \ + size_t indices; \ + shmem_p(&remote, (TYPE)mype+1, (mype + 1) % npes); \ + while (!shmemx_test_some(&remote, 1, &indices, &status, SHMEM_CMP_NE, 0)); \ + if (remote != (TYPE)((mype + npes - 1) % npes)+1) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_TEST_SOME(%s)\n", mype, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +#else +#define TEST_SHMEM_TEST_ALL(TYPE) +#define TEST_SHMEM_TEST_ANY(TYPE) +#define TEST_SHMEM_TEST_SOME(TYPE) + +#endif + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_TEST_ALL(short); + TEST_SHMEM_TEST_ALL(int); + TEST_SHMEM_TEST_ALL(long); + TEST_SHMEM_TEST_ALL(long long); + TEST_SHMEM_TEST_ALL(unsigned short); + TEST_SHMEM_TEST_ALL(unsigned int); + TEST_SHMEM_TEST_ALL(unsigned long); + TEST_SHMEM_TEST_ALL(unsigned long long); + TEST_SHMEM_TEST_ALL(int32_t); + TEST_SHMEM_TEST_ALL(int64_t); + TEST_SHMEM_TEST_ALL(uint32_t); + TEST_SHMEM_TEST_ALL(uint64_t); + TEST_SHMEM_TEST_ALL(size_t); + TEST_SHMEM_TEST_ALL(ptrdiff_t); + + TEST_SHMEM_TEST_ANY(short); + TEST_SHMEM_TEST_ANY(int); + TEST_SHMEM_TEST_ANY(long); + TEST_SHMEM_TEST_ANY(long long); + TEST_SHMEM_TEST_ANY(unsigned short); + TEST_SHMEM_TEST_ANY(unsigned int); + TEST_SHMEM_TEST_ANY(unsigned long); + TEST_SHMEM_TEST_ANY(unsigned long long); + TEST_SHMEM_TEST_ANY(int32_t); + TEST_SHMEM_TEST_ANY(int64_t); + TEST_SHMEM_TEST_ANY(uint32_t); + TEST_SHMEM_TEST_ANY(uint64_t); + TEST_SHMEM_TEST_ANY(size_t); + TEST_SHMEM_TEST_ANY(ptrdiff_t); + + TEST_SHMEM_TEST_SOME(short); + TEST_SHMEM_TEST_SOME(int); + TEST_SHMEM_TEST_SOME(long); + TEST_SHMEM_TEST_SOME(long long); + TEST_SHMEM_TEST_SOME(unsigned short); + TEST_SHMEM_TEST_SOME(unsigned int); + TEST_SHMEM_TEST_SOME(unsigned long); + TEST_SHMEM_TEST_SOME(unsigned long long); + TEST_SHMEM_TEST_SOME(int32_t); + TEST_SHMEM_TEST_SOME(int64_t); + TEST_SHMEM_TEST_SOME(uint32_t); + TEST_SHMEM_TEST_SOME(uint64_t); + TEST_SHMEM_TEST_SOME(size_t); + TEST_SHMEM_TEST_SOME(ptrdiff_t); + shmem_finalize(); + return rc; +} diff --git a/test/shmemx/c11_test_shmemx_wait_until.c b/test/shmemx/c11_test_shmemx_wait_until.c new file mode 100644 index 000000000..41798471d --- /dev/null +++ b/test/shmemx/c11_test_shmemx_wait_until.c @@ -0,0 +1,145 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + +#define TEST_SHMEM_WAIT_UNTIL_ALL(TYPE) \ + do { \ + static TYPE remote = 0; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + shmem_p(&remote, (TYPE)mype+1, (mype + 1) % npes); \ + shmemx_wait_until_all(&remote, 1, SHMEM_CMP_NE, 0); \ + if (remote != (TYPE)((mype + npes - 1) % npes)+1) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_WAIT_UNTIL_ALL(%s)\n", mype, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +#define TEST_SHMEM_WAIT_UNTIL_ANY(TYPE) \ + do { \ + static TYPE remote = 0; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + int status = 0; \ + shmem_p(&remote, (TYPE)mype+1, (mype + 1) % npes); \ + shmemx_wait_until_any(&remote, 1, &status, SHMEM_CMP_NE, 0); \ + if (remote != (TYPE)((mype + npes - 1) % npes)+1) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_WAIT_UNTIL_ANY(%s)\n", mype, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +#define TEST_SHMEM_WAIT_UNTIL_SOME(TYPE) \ + do { \ + static TYPE remote = 0; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + int status = 0; \ + size_t indices; \ + shmem_p(&remote, (TYPE)mype+1, (mype + 1) % npes); \ + shmemx_wait_until_some(&remote, 1, &indices, &status, SHMEM_CMP_NE, 0); \ + if (remote != (TYPE)((mype + npes - 1) % npes)+1) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_WAIT_UNTIL_SOME(%s)\n", mype, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +#else +#define TEST_SHMEM_WAIT_UNTIL_ALL(TYPE) +#define TEST_SHMEM_WAIT_UNTIL_ANY(TYPE) +#define TEST_SHMEM_WAIT_UNTIL_SOME(TYPE) + +#endif + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_WAIT_UNTIL_ALL(short); + TEST_SHMEM_WAIT_UNTIL_ALL(int); + TEST_SHMEM_WAIT_UNTIL_ALL(long); + TEST_SHMEM_WAIT_UNTIL_ALL(long long); + TEST_SHMEM_WAIT_UNTIL_ALL(unsigned short); + TEST_SHMEM_WAIT_UNTIL_ALL(unsigned int); + TEST_SHMEM_WAIT_UNTIL_ALL(unsigned long); + TEST_SHMEM_WAIT_UNTIL_ALL(unsigned long long); + TEST_SHMEM_WAIT_UNTIL_ALL(int32_t); + TEST_SHMEM_WAIT_UNTIL_ALL(int64_t); + TEST_SHMEM_WAIT_UNTIL_ALL(uint32_t); + TEST_SHMEM_WAIT_UNTIL_ALL(uint64_t); + TEST_SHMEM_WAIT_UNTIL_ALL(size_t); + TEST_SHMEM_WAIT_UNTIL_ALL(ptrdiff_t); + + TEST_SHMEM_WAIT_UNTIL_ANY(short); + TEST_SHMEM_WAIT_UNTIL_ANY(int); + TEST_SHMEM_WAIT_UNTIL_ANY(long); + TEST_SHMEM_WAIT_UNTIL_ANY(long long); + TEST_SHMEM_WAIT_UNTIL_ANY(unsigned short); + TEST_SHMEM_WAIT_UNTIL_ANY(unsigned int); + TEST_SHMEM_WAIT_UNTIL_ANY(unsigned long); + TEST_SHMEM_WAIT_UNTIL_ANY(unsigned long long); + TEST_SHMEM_WAIT_UNTIL_ANY(int32_t); + TEST_SHMEM_WAIT_UNTIL_ANY(int64_t); + TEST_SHMEM_WAIT_UNTIL_ANY(uint32_t); + TEST_SHMEM_WAIT_UNTIL_ANY(uint64_t); + TEST_SHMEM_WAIT_UNTIL_ANY(size_t); + TEST_SHMEM_WAIT_UNTIL_ANY(ptrdiff_t); + + TEST_SHMEM_WAIT_UNTIL_SOME(short); + TEST_SHMEM_WAIT_UNTIL_SOME(int); + TEST_SHMEM_WAIT_UNTIL_SOME(long); + TEST_SHMEM_WAIT_UNTIL_SOME(long long); + TEST_SHMEM_WAIT_UNTIL_SOME(unsigned short); + TEST_SHMEM_WAIT_UNTIL_SOME(unsigned int); + TEST_SHMEM_WAIT_UNTIL_SOME(unsigned long); + TEST_SHMEM_WAIT_UNTIL_SOME(unsigned long long); + TEST_SHMEM_WAIT_UNTIL_SOME(int32_t); + TEST_SHMEM_WAIT_UNTIL_SOME(int64_t); + TEST_SHMEM_WAIT_UNTIL_SOME(uint32_t); + TEST_SHMEM_WAIT_UNTIL_SOME(uint64_t); + TEST_SHMEM_WAIT_UNTIL_SOME(size_t); + TEST_SHMEM_WAIT_UNTIL_SOME(ptrdiff_t); + + shmem_finalize(); + return rc; +} From de2b5eeb4289ac164a62d1ec3c8ea5f67f9ac0c9 Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Mon, 22 Oct 2018 13:31:53 -0400 Subject: [PATCH 10/23] remove 'processed' array from test_any unit test Signed-off-by: David M. Ozog --- test/shmemx/shmemx_test_any.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/shmemx/shmemx_test_any.c b/test/shmemx/shmemx_test_any.c index 8fab15d3c..6bf8d896d 100644 --- a/test/shmemx/shmemx_test_any.c +++ b/test/shmemx/shmemx_test_any.c @@ -41,7 +41,6 @@ int main(void) int *flags = shmem_calloc(npes, sizeof(int)); int *status = calloc(npes, sizeof(int)); - int *processed = calloc(npes, sizeof(int)); for (int i = 0; i < npes; i++) shmem_int_p(&flags[mype], 1, i); @@ -51,9 +50,8 @@ int main(void) while (ncompleted < npes) { completed_idx = shmemx_int_test_any(flags, npes, status, SHMEM_CMP_EQ, 1); - if (completed_idx != SIZE_MAX && !processed[completed_idx]) { + if (completed_idx != SIZE_MAX) { ncompleted++; - processed[completed_idx] = 1; } else { /* Overlap some computation here */ } From c492deb9584d5ed1c7b23aab8b681d7c8fc8b25a Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Mon, 29 Oct 2018 16:14:17 -0400 Subject: [PATCH 11/23] Changes from code review: wait/test any/all/some * Add `default` case for C11 routines * Add SHMEM_INTERNAL_WAIT_UNTIL and restructure the code * Check for SIZE_MAX return case before looping through ivars * Only do memory barrier in shmem_test_* if successful * Remove stdbool.h from C11 unit tests * Add sanity check for `status==NULL` paths in unit tests * Add missing license and consistent spacing in unit tests Signed-off-by: David M. Ozog --- mpp/shmemx.h4.in | 6 + src/shmem_synchronization.h | 35 ++--- src/synchronization_c.c4 | 168 +++++++++++------------ test/shmemx/c11_test_shmemx_test.c | 7 +- test/shmemx/c11_test_shmemx_wait_until.c | 7 +- test/shmemx/shmemx_test_all.c | 4 +- test/shmemx/shmemx_test_any.c | 56 ++++---- test/shmemx/shmemx_test_some.c | 110 ++++++++++----- test/shmemx/shmemx_wait_until_all.c | 2 +- test/shmemx/shmemx_wait_until_any.c | 62 +++++---- test/shmemx/shmemx_wait_until_some.c | 88 ++++++------ test/unit/c11_test_shmem_atomic_add.c | 3 +- test/unit/c11_test_shmem_atomic_and.c | 3 +- test/unit/c11_test_shmem_atomic_cswap.c | 3 +- test/unit/c11_test_shmem_atomic_fetch.c | 3 +- test/unit/c11_test_shmem_atomic_inc.c | 3 +- test/unit/c11_test_shmem_atomic_or.c | 3 +- test/unit/c11_test_shmem_atomic_set.c | 3 +- test/unit/c11_test_shmem_atomic_swap.c | 3 +- test/unit/c11_test_shmem_atomic_xor.c | 3 +- test/unit/c11_test_shmem_g.c | 3 +- test/unit/c11_test_shmem_get.c | 3 +- test/unit/c11_test_shmem_p.c | 3 +- test/unit/c11_test_shmem_put.c | 3 +- test/unit/c11_test_shmem_test.c | 3 +- test/unit/c11_test_shmem_wait_until.c | 3 +- 26 files changed, 307 insertions(+), 283 deletions(-) diff --git a/mpp/shmemx.h4.in b/mpp/shmemx.h4.in index 8933095cf..62c02207a 100644 --- a/mpp/shmemx.h4.in +++ b/mpp/shmemx.h4.in @@ -171,36 +171,42 @@ SHMEM_CXX_DEFINE_FOR_BITWISE_AMO(`SHMEM_CXX_ATOMIC_FETCH_XOR_NBI') define(`SHMEM_C11_GEN_WAIT_UNTIL_ALL', ` $2*: shmemx_$1_wait_until_all')dnl #define shmemx_wait_until_all(...) \ _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ + default: shmem_ctx_c11_generic_selection_failed, \ SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_WAIT_UNTIL_ALL', `, \') \ )(__VA_ARGS__) define(`SHMEM_C11_GEN_WAIT_UNTIL_ANY', ` $2*: shmemx_$1_wait_until_any')dnl #define shmemx_wait_until_any(...) \ _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ + default: shmem_ctx_c11_generic_selection_failed, \ SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_WAIT_UNTIL_ANY', `, \') \ )(__VA_ARGS__) define(`SHMEM_C11_GEN_WAIT_UNTIL_SOME', ` $2*: shmemx_$1_wait_until_some')dnl #define shmemx_wait_until_some(...) \ _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ + default: shmem_ctx_c11_generic_selection_failed, \ SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_WAIT_UNTIL_SOME', `, \') \ )(__VA_ARGS__) define(`SHMEM_C11_GEN_TEST_ALL', ` $2*: shmemx_$1_test_all')dnl #define shmemx_test_all(...) \ _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ + default: shmem_ctx_c11_generic_selection_failed, \ SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_TEST_ALL', `, \') \ )(__VA_ARGS__) define(`SHMEM_C11_GEN_TEST_ANY', ` $2*: shmemx_$1_test_any')dnl #define shmemx_test_any(...) \ _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ + default: shmem_ctx_c11_generic_selection_failed, \ SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_TEST_ANY', `, \') \ )(__VA_ARGS__) define(`SHMEM_C11_GEN_TEST_SOME', ` $2*: shmemx_$1_test_some')dnl #define shmemx_test_some(...) \ _Generic(SHMEM_C11_TYPE_EVAL_PTR(SHMEM_C11_ARG0(__VA_ARGS__)), \ + default: shmem_ctx_c11_generic_selection_failed, \ SHMEM_BIND_C11_SYNC(`SHMEM_C11_GEN_TEST_SOME', `, \') \ )(__VA_ARGS__) diff --git a/src/shmem_synchronization.h b/src/shmem_synchronization.h index f356fda1d..ef4b4e6a1 100644 --- a/src/shmem_synchronization.h +++ b/src/shmem_synchronization.h @@ -129,39 +129,28 @@ shmem_internal_fence(shmem_ctx_t ctx) } \ } while(0) -#if defined(ENABLE_HARD_POLLING) #define SHMEM_WAIT(var, value) do { \ - SHMEM_WAIT_POLL(var, value); \ + SHMEM_INTERNAL_WAIT_UNTIL(var, SHMEM_CMP_NE, value); \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ } while (0) #define SHMEM_WAIT_UNTIL(var, cond, value) do { \ - SHMEM_WAIT_UNTIL_POLL(var, cond, value); \ + SHMEM_INTERNAL_WAIT_UNTIL(var, cond, value); \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ } while (0) +#if defined(ENABLE_HARD_POLLING) +#define SHMEM_INTERNAL_WAIT_UNTIL(var, cond, value) \ + SHMEM_WAIT_UNTIL_POLL(var, cond, value) #else -#define SHMEM_WAIT(var, value) do { \ - if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ - SHMEM_WAIT_BLOCK(var, value); \ - } else { \ - SHMEM_WAIT_POLL(var, value); \ - } \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) - -#define SHMEM_WAIT_UNTIL(var, cond, value) do { \ - if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ - SHMEM_WAIT_UNTIL_BLOCK(var, cond, value); \ - } else { \ - SHMEM_WAIT_UNTIL_POLL(var, cond, value); \ - } \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) -#endif /* HARD_POLLING */ +#define SHMEM_INTERNAL_WAIT_UNTIL(var, cond, value) \ + if (shmem_internal_thread_level == SHMEM_THREAD_SINGLE) { \ + SHMEM_WAIT_UNTIL_BLOCK(var, cond, value); \ + } else { \ + SHMEM_WAIT_UNTIL_POLL(var, cond, value); \ + } +#endif #endif diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index 5f75543fc..8b659a40b 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -131,7 +131,8 @@ shmem_ctx_fence(shmem_ctx_t ctx) } -/* This legacy wait API is ignored when using C11 generic bindings: */ +/* The untyped shmem_wait and shmem_wait_until routines + * are ignored when using C11 generic bindings. */ void SHMEM_FUNCTION_ATTRIBUTES shmem_wait(long *ivar, long cmp_value) { @@ -141,6 +142,7 @@ shmem_wait(long *ivar, long cmp_value) SHMEM_WAIT(ivar, cmp_value); } + void SHMEM_FUNCTION_ATTRIBUTES shmem_wait_until(long *ivar, int cmp, long value) { @@ -152,7 +154,6 @@ shmem_wait_until(long *ivar, int cmp, long value) } -/* Non-legacy wait/test API: */ #define SHMEM_DEF_WAIT(STYPE,TYPE) \ void SHMEM_FUNCTION_ATTRIBUTES \ shmem_##STYPE##_wait(TYPE *var, TYPE value) \ @@ -165,6 +166,7 @@ shmem_wait_until(long *ivar, int cmp, long value) SHMEM_BIND_C_WAIT(`SHMEM_DEF_WAIT') + #define SHMEM_DEF_WAIT_UNTIL(STYPE,TYPE) \ void SHMEM_FUNCTION_ATTRIBUTES \ shmem_##STYPE##_wait_until(TYPE *var, int cond, TYPE value) \ @@ -178,6 +180,7 @@ SHMEM_BIND_C_WAIT(`SHMEM_DEF_WAIT') SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL') + #define SHMEM_DEF_WAIT_UNTIL_ALL(STYPE,TYPE) \ void SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_wait_until_all(TYPE *vars, size_t nelems, int cond, TYPE value) \ @@ -186,24 +189,16 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t ret = 0, i = 0, ncompleted = 0; \ - size_t *completed = calloc(nelems, sizeof(size_t)); \ - while (ncompleted < nelems) { \ - for (i = 0; i < nelems; i++) { \ - COMP(cond, vars[i], value, ret); \ - if (!completed[i] && ret) { \ - completed[i] = 1; \ - ncompleted++; \ - } \ - } \ - } \ + size_t i; \ + for (i = 0; i < nelems; i++) SHMEM_INTERNAL_WAIT_UNTIL(&vars[i], cond, value); \ + \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ - free(completed); \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') + #define SHMEM_DEF_WAIT_UNTIL_ANY(STYPE,TYPE) \ size_t SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_wait_until_any(TYPE *vars, size_t nelems, \ @@ -213,37 +208,38 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t ret = 0, i = 0, npasses = 0, no_wait_len = 0; \ - while (!ret) { \ + size_t cmpret = 0, i = 0, found_idx = SIZE_MAX, wait_set_len = 0; \ + \ + if (status) { \ for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - COMP(cond, vars[i], value, ret); \ - } else { \ - no_wait_len++; \ - } \ - } else { \ - COMP(cond, vars[i], value, ret); \ + if (status[i]) wait_set_len++; \ + } \ + } \ + if (nelems == 0 || wait_set_len == nelems) \ + return SIZE_MAX; \ + \ + while (!cmpret) { \ + for (i = 0; i < nelems; i++) { \ + if (status == NULL || (status && !status[i])) { \ + COMP(cond, vars[i], value, cmpret); \ } \ - if (ret) { \ + if (cmpret) { \ if (status) status[i] = 1; \ + found_idx = i; \ break; \ } \ } \ - if (no_wait_len == nelems && npasses == 0) { \ - ret = SIZE_MAX; \ - } \ shmem_transport_probe(); \ - npasses++; \ } \ - if (ret != SIZE_MAX) ret = i; \ + \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ - return ret; \ + return found_idx; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') + #define SHMEM_DEF_WAIT_UNTIL_SOME(STYPE,TYPE) \ size_t SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_wait_until_some(TYPE *vars, size_t nelems, size_t * restrict indices, \ @@ -253,72 +249,71 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t ret = 0, i = 0, ncompleted = 0, npasses = 0, no_wait_len = 0; \ + size_t cmpret = 0, i = 0, ncompleted = 0, wait_set_len = 0; \ + \ + if (status) { \ + for (i = 0; i < nelems; i++) { \ + if (status[i]) wait_set_len++; \ + } \ + } \ + if (nelems == 0 || wait_set_len == nelems) \ + return 0; \ + \ while (ncompleted == 0) { \ for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - COMP(cond, vars[i], value, ret); \ - } else { \ - no_wait_len++; \ - } \ - } else { \ - COMP(cond, vars[i], value, ret); \ + if (status == NULL || (status && !status[i])) { \ + COMP(cond, vars[i], value, cmpret); \ } \ - if (ret) { \ + if (cmpret) { \ if (status) status[i] = 1; \ indices[ncompleted++] = i; \ - ret = 0; \ + cmpret = 0; \ } \ } \ - if (no_wait_len == nelems && npasses == 0) { \ - shmem_internal_assert(ncompleted == 0); \ - break; \ - } \ shmem_transport_probe(); \ - npasses++; \ } \ - ret = ncompleted; \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ - return ret; \ + return ncompleted; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_SOME') + #define SHMEM_DEF_TEST(STYPE,TYPE) \ int SHMEM_FUNCTION_ATTRIBUTES \ shmem_##STYPE##_test(TYPE *var, int cond, TYPE value) \ { \ - int ret; \ + int cmpret; \ SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(var, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - COMP(cond, *(var), value, ret); \ - if (ret) { \ + COMP(cond, *(var), value, cmpret); \ + if (cmpret) { \ shmem_internal_membar_load(); \ } \ - return ret; \ + return cmpret; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST') + #define SHMEM_DEF_TEST_ALL(STYPE,TYPE) \ int SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_test_all(TYPE *vars, size_t nelems, int cond, TYPE value) \ { \ - int ret, ncompleted = 0; \ + int cmpret, ncompleted = 0; \ SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ for (int i = 0; i < nelems; i++) { \ - COMP(cond, vars[i], value, ret); \ - if (ret) ncompleted++; \ + COMP(cond, vars[i], value, cmpret); \ + if (cmpret) ncompleted++; \ } \ - shmem_internal_membar_load(); \ if (ncompleted == nelems) { \ + shmem_internal_membar_load(); \ return 1; \ } else { \ return 0; \ @@ -327,6 +322,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST') SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') + #define SHMEM_DEF_TEST_ANY(STYPE,TYPE) \ size_t SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_test_any(TYPE *vars, size_t nelems, int * restrict status, \ @@ -336,31 +332,26 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t ret = 0, i = 0; \ + size_t found_idx = SIZE_MAX, i = 0; \ for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - COMP(cond, vars[i], value, ret); \ - } \ - } else { \ - COMP(cond, vars[i], value, ret); \ - } \ - if (ret) { \ + size_t cmpret = 0; \ + if (status == NULL || (status && !status[i])) \ + COMP(cond, vars[i], value, cmpret); \ + if (cmpret) { \ if (status) status[i] = 1; \ + found_idx = i; \ break; \ } \ } \ - if (i == nelems) { \ - ret = SIZE_MAX; \ - } else { \ - ret = i; \ - } \ - shmem_internal_membar_load(); \ - return ret; \ + if (found_idx != SIZE_MAX) \ + shmem_internal_membar_load(); \ + \ + return found_idx; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') + #define SHMEM_DEF_TEST_SOME(STYPE,TYPE) \ size_t SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_test_some(TYPE *vars, size_t nelems, size_t * restrict indices, \ @@ -370,30 +361,29 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t ret = 0, i = 0, ncompleted = 0, no_wait_len = 0; \ + size_t cmpret = 0, i = 0, ncompleted = 0, wait_set_len = 0; \ + \ + if (status) { \ + for (i = 0; i < nelems; i++) { \ + if (status[i]) wait_set_len++; \ + } \ + } \ + if (nelems == 0 || wait_set_len == nelems) \ + return 0; \ + \ for (i = 0; i < nelems; i++) { \ - if (status) { \ - if (!status[i]) { \ - COMP(cond, vars[i], value, ret); \ - } else { \ - no_wait_len++; \ - } \ - } else { \ - COMP(cond, vars[i], value, ret); \ + if (status == NULL || !status[i]) { \ + COMP(cond, vars[i], value, cmpret); \ } \ - if (ret) { \ + if (cmpret) { \ if (status) status[i] = 1; \ indices[ncompleted++] = i; \ - ret = 0; \ + cmpret = 0; \ } \ } \ - if (no_wait_len == nelems) { \ - shmem_internal_assert(ncompleted == 0); \ - } \ - ret = ncompleted; \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ - return ret; \ + return ncompleted; \ } SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_SOME') diff --git a/test/shmemx/c11_test_shmemx_test.c b/test/shmemx/c11_test_shmemx_test.c index b1414a881..f054c92ff 100644 --- a/test/shmemx/c11_test_shmemx_test.c +++ b/test/shmemx/c11_test_shmemx_test.c @@ -32,7 +32,6 @@ #include #include -#include #include #include #include @@ -51,7 +50,7 @@ "TEST_SHMEM_TEST_ALL(%s)\n", mype, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #define TEST_SHMEM_TEST_ANY(TYPE) \ do { \ @@ -66,7 +65,7 @@ "TEST_SHMEM_TEST_ANY(%s)\n", mype, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #define TEST_SHMEM_TEST_SOME(TYPE) \ do { \ @@ -82,7 +81,7 @@ "TEST_SHMEM_TEST_SOME(%s)\n", mype, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_TEST_ALL(TYPE) diff --git a/test/shmemx/c11_test_shmemx_wait_until.c b/test/shmemx/c11_test_shmemx_wait_until.c index 41798471d..a6b17ef23 100644 --- a/test/shmemx/c11_test_shmemx_wait_until.c +++ b/test/shmemx/c11_test_shmemx_wait_until.c @@ -32,7 +32,6 @@ #include #include -#include #include #include #include @@ -51,7 +50,7 @@ "TEST_SHMEM_WAIT_UNTIL_ALL(%s)\n", mype, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #define TEST_SHMEM_WAIT_UNTIL_ANY(TYPE) \ do { \ @@ -66,7 +65,7 @@ "TEST_SHMEM_WAIT_UNTIL_ANY(%s)\n", mype, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #define TEST_SHMEM_WAIT_UNTIL_SOME(TYPE) \ do { \ @@ -82,7 +81,7 @@ "TEST_SHMEM_WAIT_UNTIL_SOME(%s)\n", mype, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_WAIT_UNTIL_ALL(TYPE) diff --git a/test/shmemx/shmemx_test_all.c b/test/shmemx/shmemx_test_all.c index 6f50c9218..bcd3b78ba 100644 --- a/test/shmemx/shmemx_test_all.c +++ b/test/shmemx/shmemx_test_all.c @@ -42,8 +42,8 @@ int main(void) for (int i = 0; i < npes; i++) shmem_int_p(&flags[mype], 1, i); - - while (!shmemx_int_test_all(flags, npes, SHMEM_CMP_EQ, 1)) {} + + while (!shmemx_int_test_all(flags, npes, SHMEM_CMP_EQ, 1)); shmem_free(flags); shmem_finalize(); diff --git a/test/shmemx/shmemx_test_any.c b/test/shmemx/shmemx_test_any.c index 6bf8d896d..46cdc0ab0 100644 --- a/test/shmemx/shmemx_test_any.c +++ b/test/shmemx/shmemx_test_any.c @@ -35,30 +35,36 @@ int main(void) { - shmem_init(); - int mype = shmem_my_pe(); - int npes = shmem_n_pes(); - - int *flags = shmem_calloc(npes, sizeof(int)); - int *status = calloc(npes, sizeof(int)); - - for (int i = 0; i < npes; i++) - shmem_int_p(&flags[mype], 1, i); - - int ncompleted = 0; - size_t completed_idx; - - while (ncompleted < npes) { - completed_idx = shmemx_int_test_any(flags, npes, status, SHMEM_CMP_EQ, 1); - if (completed_idx != SIZE_MAX) { - ncompleted++; - } else { - /* Overlap some computation here */ - } - } + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); + + int *flags = shmem_calloc(npes, sizeof(int)); + int *status = calloc(npes, sizeof(int)); + + for (int i = 0; i < npes; i++) + shmem_int_p(&flags[mype], 1, i); + + int ncompleted = 0; + size_t completed_idx; + + while (ncompleted < npes) { + completed_idx = shmemx_int_test_any(flags, npes, status, SHMEM_CMP_EQ, 1); + if (completed_idx != SIZE_MAX) { + ncompleted++; + } else { + /* Overlap some computation here */ + } + } + + /* Sanity check case with NULL status array */ + completed_idx = shmemx_int_test_any(flags, npes, NULL, SHMEM_CMP_EQ, 1); + + if (completed_idx == SIZE_MAX || completed_idx >= npes) + shmem_global_exit(2); - free(status); - shmem_free(flags); - shmem_finalize(); - return 0; + free(status); + shmem_free(flags); + shmem_finalize(); + return 0; } diff --git a/test/shmemx/shmemx_test_some.c b/test/shmemx/shmemx_test_some.c index 521a0ef33..8c7ca0ee0 100644 --- a/test/shmemx/shmemx_test_some.c +++ b/test/shmemx/shmemx_test_some.c @@ -1,3 +1,34 @@ +/* + * Copyright (c) 2018 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * This test is derived from an example provided in the OpenSHMEM 1.4 + * specification. Additional copyrights may apply. + * + */ + #include #include #include @@ -6,51 +37,58 @@ int main(void) { - int total_sum = 0; + int total_sum = 0; + + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); - shmem_init(); - int mype = shmem_my_pe(); - int npes = shmem_n_pes(); + int *my_data = malloc(N * sizeof(int)); + int *all_data = shmem_malloc(N * npes * sizeof(int)); - int *my_data = malloc(N * sizeof(int)); - int *all_data = shmem_malloc(N * npes * sizeof(int)); + int *flags = shmem_calloc(npes, sizeof(int)); + size_t *indices = calloc(npes, sizeof(size_t)); + int *status = calloc(npes, sizeof(int)); - int *flags = shmem_calloc(npes, sizeof(int)); - size_t *indices = calloc(npes, sizeof(size_t)); - int *status = calloc(npes, sizeof(int)); + for (int i = 0; i < N; i++) + my_data[i] = mype*N + i; - for (int i = 0; i < N; i++) - my_data[i] = mype*N + i; + for (int i = 0; i < npes; i++) + shmem_int_put_nbi(&all_data[mype*N], my_data, N, i); - for (int i = 0; i < npes; i++) - shmem_int_put_nbi(&all_data[mype*N], my_data, N, i); + shmem_fence(); - shmem_fence(); + for (int i = 0; i < npes; i++) + shmem_int_p(&flags[mype], 1, i); - for (int i = 0; i < npes; i++) - shmem_int_p(&flags[mype], 1, i); - - int ncompleted = 0; + int ncompleted = 0; - while (ncompleted < npes) { - int ntested = shmemx_int_test_some(flags, npes, indices, status, SHMEM_CMP_NE, 0); - if (ntested > 0) { - for (int i = 0; i < ntested; i++) { - for (int j = 0; j < N; j++) - total_sum += all_data[indices[i]*N + j]; - } - ncompleted += ntested; - } else { - /* Overlap some computation here */ - } - } + while (ncompleted < npes) { + int ntested = shmemx_int_test_some(flags, npes, indices, status, SHMEM_CMP_NE, 0); + if (ntested > 0) { + for (int i = 0; i < ntested; i++) { + for (int j = 0; j < N; j++) + total_sum += all_data[indices[i]*N + j]; + } + ncompleted += ntested; + } else { + /* Overlap some computation here */ + } + } /* check result */ - int M = N * npes - 1; - if (total_sum != M * (M + 1) / 2) { - shmem_global_exit(1); - } + int M = N * npes - 1; + if (total_sum != M * (M + 1) / 2) { + shmem_global_exit(1); + } + + /* Sanity check case with NULL status array */ + ncompleted = shmemx_int_test_some(flags, npes, indices, NULL, SHMEM_CMP_EQ, 1); + + if (ncompleted == 0 || ncompleted > npes) + shmem_global_exit(2); + - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } diff --git a/test/shmemx/shmemx_wait_until_all.c b/test/shmemx/shmemx_wait_until_all.c index 0027c5d82..757e84314 100644 --- a/test/shmemx/shmemx_wait_until_all.c +++ b/test/shmemx/shmemx_wait_until_all.c @@ -42,7 +42,7 @@ int main(void) for (int i = 0; i < npes; i++) shmem_int_p(&flags[mype], 1, i); - + shmemx_int_wait_until_all(flags, npes, SHMEM_CMP_EQ, 1); shmem_free(flags); diff --git a/test/shmemx/shmemx_wait_until_any.c b/test/shmemx/shmemx_wait_until_any.c index 8832570c3..c6b57ff19 100644 --- a/test/shmemx/shmemx_wait_until_any.c +++ b/test/shmemx/shmemx_wait_until_any.c @@ -37,42 +37,48 @@ int main(void) { - int total_sum = 0; + int total_sum = 0; - shmem_init(); - int mype = shmem_my_pe(); - int npes = shmem_n_pes(); + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); - int *my_data = malloc(N * sizeof(int)); - int *all_data = shmem_malloc(N * npes * sizeof(int)); + int *my_data = malloc(N * sizeof(int)); + int *all_data = shmem_malloc(N * npes * sizeof(int)); - int *flags = shmem_calloc(npes, sizeof(int)); - int *status = calloc(npes, sizeof(int)); + int *flags = shmem_calloc(npes, sizeof(int)); + int *status = calloc(npes, sizeof(int)); - for (int i = 0; i < N; i++) - my_data[i] = mype*N + i; + for (int i = 0; i < N; i++) + my_data[i] = mype*N + i; - for (int i = 0; i < npes; i++) - shmem_int_put_nbi(&all_data[mype*N], my_data, N, i); + for (int i = 0; i < npes; i++) + shmem_int_put_nbi(&all_data[mype*N], my_data, N, i); - shmem_fence(); + shmem_fence(); - for (int i = 0; i < npes; i++) - shmem_int_p(&flags[mype], 1, i); - - size_t completed_idx; - for (int i = 0; i < npes; i++) { - completed_idx = shmemx_int_wait_until_any(flags, npes, status, SHMEM_CMP_NE, 0); - for (int j = 0; j < N; j++) - total_sum += all_data[completed_idx * N + j]; - } + for (int i = 0; i < npes; i++) + shmem_int_p(&flags[mype], 1, i); + + size_t completed_idx; + for (int i = 0; i < npes; i++) { + completed_idx = shmemx_int_wait_until_any(flags, npes, status, SHMEM_CMP_NE, 0); + for (int j = 0; j < N; j++) + total_sum += all_data[completed_idx * N + j]; + } /* check result */ - int M = N * npes - 1; - if (total_sum != M * (M + 1) / 2) { - shmem_global_exit(1); - } + int M = N * npes - 1; + if (total_sum != M * (M + 1) / 2) { + shmem_global_exit(1); + } + + /* Sanity check the case with NULL status array */ + completed_idx = shmemx_int_wait_until_any(flags, npes, NULL, SHMEM_CMP_EQ, 1); + + if (completed_idx == SIZE_MAX || completed_idx >= npes) + shmem_global_exit(2); - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } diff --git a/test/shmemx/shmemx_wait_until_some.c b/test/shmemx/shmemx_wait_until_some.c index a1ee688b7..98a7c5c9c 100644 --- a/test/shmemx/shmemx_wait_until_some.c +++ b/test/shmemx/shmemx_wait_until_some.c @@ -6,45 +6,51 @@ int main(void) { - int total_sum = 0; - - shmem_init(); - int mype = shmem_my_pe(); - int npes = shmem_n_pes(); - - int *my_data = malloc(N * sizeof(int)); - int *all_data = shmem_malloc(N * npes * sizeof(int)); - - int *flags = shmem_calloc(npes, sizeof(int)); - size_t *indices = malloc(npes * sizeof(size_t)); - int *status = calloc(npes, sizeof(int)); - - for (int i = 0; i < N; i++) - my_data[i] = mype*N + i; - - for (int i = 0; i < npes; i++) - shmem_int_put_nbi(&all_data[mype*N], my_data, N, i); - - shmem_fence(); - - for (int i = 0; i < npes; i++) - shmem_int_p(&flags[mype], 1, i); - - size_t ncompleted; - while ((ncompleted = shmemx_int_wait_until_some(flags, npes, indices, - status, SHMEM_CMP_NE, 0))) { - for (size_t i = 0; i < ncompleted; i++) { - for (size_t j = 0; j < N; j++) - total_sum += all_data[indices[i]*N + j]; - } - } - - /* check result */ - int M = N * npes - 1; - if (total_sum != M * (M + 1) / 2) { - shmem_global_exit(1); - } - - shmem_finalize(); - return 0; + int total_sum = 0; + + shmem_init(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); + + int *my_data = malloc(N * sizeof(int)); + int *all_data = shmem_malloc(N * npes * sizeof(int)); + + int *flags = shmem_calloc(npes, sizeof(int)); + size_t *indices = malloc(npes * sizeof(size_t)); + int *status = calloc(npes, sizeof(int)); + + for (int i = 0; i < N; i++) + my_data[i] = mype*N + i; + + for (int i = 0; i < npes; i++) + shmem_int_put_nbi(&all_data[mype*N], my_data, N, i); + + shmem_fence(); + + for (int i = 0; i < npes; i++) + shmem_int_p(&flags[mype], 1, i); + + size_t ncompleted; + while ((ncompleted = shmemx_int_wait_until_some(flags, npes, indices, + status, SHMEM_CMP_NE, 0))) { + for (size_t i = 0; i < ncompleted; i++) { + for (size_t j = 0; j < N; j++) + total_sum += all_data[indices[i]*N + j]; + } + } + + /* check result */ + int M = N * npes - 1; + if (total_sum != M * (M + 1) / 2) { + shmem_global_exit(1); + } + + /* Sanity check the case with NULL status array */ + ncompleted = shmemx_int_wait_until_some(flags, npes, indices, NULL, SHMEM_CMP_EQ, 1); + + if (ncompleted == 0 || ncompleted > npes) + shmem_global_exit(2); + + shmem_finalize(); + return 0; } diff --git a/test/unit/c11_test_shmem_atomic_add.c b/test/unit/c11_test_shmem_atomic_add.c index 5484fd277..58686d5ff 100644 --- a/test/unit/c11_test_shmem_atomic_add.c +++ b/test/unit/c11_test_shmem_atomic_add.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -132,7 +131,7 @@ enum op { ADD = 0, ATOMIC_ADD, CTX_ATOMIC_ADD, FADD, ATOMIC_FETCH_ADD, mype, #OP, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_ADD(OP, TYPE) diff --git a/test/unit/c11_test_shmem_atomic_and.c b/test/unit/c11_test_shmem_atomic_and.c index 1fd4513f0..1484fed2a 100644 --- a/test/unit/c11_test_shmem_atomic_and.c +++ b/test/unit/c11_test_shmem_atomic_and.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -119,7 +118,7 @@ enum op { AND = 0, CTX_AND, FETCH_AND, CTX_FETCH_AND, FETCH_AND_NBI, mype, #OP, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_AND(OP, TYPE) diff --git a/test/unit/c11_test_shmem_atomic_cswap.c b/test/unit/c11_test_shmem_atomic_cswap.c index 55f6396fa..d2d0c079e 100644 --- a/test/unit/c11_test_shmem_atomic_cswap.c +++ b/test/unit/c11_test_shmem_atomic_cswap.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -104,7 +103,7 @@ enum op { CSWAP = 0, ATOMIC_COMPARE_SWAP, CTX_ATOMIC_COMPARE_SWAP, mype, #OP, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_CSWAP(OP, TYPE) diff --git a/test/unit/c11_test_shmem_atomic_fetch.c b/test/unit/c11_test_shmem_atomic_fetch.c index 93ae82bcb..30affff02 100644 --- a/test/unit/c11_test_shmem_atomic_fetch.c +++ b/test/unit/c11_test_shmem_atomic_fetch.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -95,7 +94,7 @@ enum op { FETCH = 0, ATOMIC_FETCH, CTX_ATOMIC_FETCH, ATOMIC_FETCH_NBI, "TEST_SHMEM_FETCH(%s, %s)\n", mype, #OP, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_FETCH(OP, TYPE) diff --git a/test/unit/c11_test_shmem_atomic_inc.c b/test/unit/c11_test_shmem_atomic_inc.c index 4363701d4..4fab8c293 100644 --- a/test/unit/c11_test_shmem_atomic_inc.c +++ b/test/unit/c11_test_shmem_atomic_inc.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -132,7 +131,7 @@ enum op { INC = 0, ATOMIC_INC, CTX_ATOMIC_INC, FINC, ATOMIC_FETCH_INC, mype, #OP, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_INC(OP, TYPE) diff --git a/test/unit/c11_test_shmem_atomic_or.c b/test/unit/c11_test_shmem_atomic_or.c index 6b1484c92..05117454b 100644 --- a/test/unit/c11_test_shmem_atomic_or.c +++ b/test/unit/c11_test_shmem_atomic_or.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -121,7 +120,7 @@ enum op { OR = 0, CTX_OR, FETCH_OR, CTX_FETCH_OR, FETCH_OR_NBI, mype, #OP, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_OR(OP, TYPE) diff --git a/test/unit/c11_test_shmem_atomic_set.c b/test/unit/c11_test_shmem_atomic_set.c index 453f35b57..16dc1cea3 100644 --- a/test/unit/c11_test_shmem_atomic_set.c +++ b/test/unit/c11_test_shmem_atomic_set.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -71,7 +70,7 @@ enum op { SET = 0, ATOMIC_SET, CTX_ATOMIC_SET }; "TEST_SHMEM_SET(%s, %s)\n", mype, #OP, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_SET(OP, TYPE) diff --git a/test/unit/c11_test_shmem_atomic_swap.c b/test/unit/c11_test_shmem_atomic_swap.c index 32af2057f..de12c84b9 100644 --- a/test/unit/c11_test_shmem_atomic_swap.c +++ b/test/unit/c11_test_shmem_atomic_swap.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -100,7 +99,7 @@ enum op { SWAP = 0, ATOMIC_SWAP, CTX_ATOMIC_SWAP, ATOMIC_SWAP_NBI, mype, #OP, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_SWAP(OP, TYPE) diff --git a/test/unit/c11_test_shmem_atomic_xor.c b/test/unit/c11_test_shmem_atomic_xor.c index cf2d9aa5f..286d9acb4 100644 --- a/test/unit/c11_test_shmem_atomic_xor.c +++ b/test/unit/c11_test_shmem_atomic_xor.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -119,7 +118,7 @@ enum op { XOR = 0, CTX_XOR, FETCH_XOR, CTX_FETCH_XOR, FETCH_XOR_NBI, mype, #OP, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_XOR(OP, TYPE) diff --git a/test/unit/c11_test_shmem_g.c b/test/unit/c11_test_shmem_g.c index 4c6153306..969dd1386 100644 --- a/test/unit/c11_test_shmem_g.c +++ b/test/unit/c11_test_shmem_g.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -56,7 +55,7 @@ (int)(USE_CTX), #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_G(USE_CTX, TYPE) diff --git a/test/unit/c11_test_shmem_get.c b/test/unit/c11_test_shmem_get.c index 278a924ec..30487d37a 100644 --- a/test/unit/c11_test_shmem_get.c +++ b/test/unit/c11_test_shmem_get.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -80,7 +79,7 @@ enum op { GET = 0, IGET, GET_NBI }; (int)(USE_CTX), #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_GET(OP, USE_CTX, TYPE) diff --git a/test/unit/c11_test_shmem_p.c b/test/unit/c11_test_shmem_p.c index 2a40cc6ac..56adb0fc9 100644 --- a/test/unit/c11_test_shmem_p.c +++ b/test/unit/c11_test_shmem_p.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -54,7 +53,7 @@ (int)(USE_CTX), #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_P(USE_CTX, TYPE) diff --git a/test/unit/c11_test_shmem_put.c b/test/unit/c11_test_shmem_put.c index adf194220..0f50a77ad 100644 --- a/test/unit/c11_test_shmem_put.c +++ b/test/unit/c11_test_shmem_put.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -80,7 +79,7 @@ enum op { PUT = 0, IPUT, PUT_NBI }; #OP, (int)(USE_CTX), #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_PUT(OP, USE_CTX, TYPE) diff --git a/test/unit/c11_test_shmem_test.c b/test/unit/c11_test_shmem_test.c index 2a6dfcfeb..978c6ab11 100644 --- a/test/unit/c11_test_shmem_test.c +++ b/test/unit/c11_test_shmem_test.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -50,7 +49,7 @@ "TEST_SHMEM_TEST(%s)\n", mype, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_TEST(TYPE) diff --git a/test/unit/c11_test_shmem_wait_until.c b/test/unit/c11_test_shmem_wait_until.c index c152765cf..cc8e97131 100644 --- a/test/unit/c11_test_shmem_wait_until.c +++ b/test/unit/c11_test_shmem_wait_until.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -50,7 +49,7 @@ "TEST_SHMEM_WAIT_UNTIL(%s)\n", mype, #TYPE); \ rc = EXIT_FAILURE; \ } \ - } while (false) + } while (0) #else #define TEST_SHMEM_WAIT_UNTIL(TYPE) From ac9951cac0b75b799c14e39585123ec645c3e03b Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Tue, 13 Nov 2018 11:17:22 -0500 Subject: [PATCH 12/23] Code review changes for wait/test any/all/some: * handle all (nelems == 0) cases * rand_r starting index in "any" routines * organize/simplify conditionals * check flags array in unit tests * some other small fixes Signed-off-by: David M. Ozog --- src/shmem_synchronization.h | 24 ++++---- src/synchronization_c.c4 | 90 ++++++++++++++++------------ test/shmemx/shmemx_test_all.c | 5 ++ test/shmemx/shmemx_test_any.c | 12 +++- test/shmemx/shmemx_test_some.c | 9 ++- test/shmemx/shmemx_wait_until_all.c | 6 ++ test/shmemx/shmemx_wait_until_any.c | 8 ++- test/shmemx/shmemx_wait_until_some.c | 8 ++- 8 files changed, 105 insertions(+), 57 deletions(-) diff --git a/src/shmem_synchronization.h b/src/shmem_synchronization.h index ef4b4e6a1..430dcd3df 100644 --- a/src/shmem_synchronization.h +++ b/src/shmem_synchronization.h @@ -129,18 +129,6 @@ shmem_internal_fence(shmem_ctx_t ctx) } \ } while(0) -#define SHMEM_WAIT(var, value) do { \ - SHMEM_INTERNAL_WAIT_UNTIL(var, SHMEM_CMP_NE, value); \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) - -#define SHMEM_WAIT_UNTIL(var, cond, value) do { \ - SHMEM_INTERNAL_WAIT_UNTIL(var, cond, value); \ - shmem_internal_membar_load(); \ - shmem_transport_syncmem(); \ - } while (0) - #if defined(ENABLE_HARD_POLLING) #define SHMEM_INTERNAL_WAIT_UNTIL(var, cond, value) \ SHMEM_WAIT_UNTIL_POLL(var, cond, value) @@ -153,4 +141,16 @@ shmem_internal_fence(shmem_ctx_t ctx) } #endif +#define SHMEM_WAIT(var, value) do { \ + SHMEM_INTERNAL_WAIT_UNTIL(var, SHMEM_CMP_NE, value); \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + } while (0) + +#define SHMEM_WAIT_UNTIL(var, cond, value) do { \ + SHMEM_INTERNAL_WAIT_UNTIL(var, cond, value); \ + shmem_internal_membar_load(); \ + shmem_transport_syncmem(); \ + } while (0) + #endif diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index 8b659a40b..442c34513 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -190,6 +190,9 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL') SHMEM_ERR_CHECK_CMP_OP(cond); \ \ size_t i; \ + \ + if (nelems == 0) return; \ + \ for (i = 0; i < nelems; i++) SHMEM_INTERNAL_WAIT_UNTIL(&vars[i], cond, value); \ \ shmem_internal_membar_load(); \ @@ -208,28 +211,32 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t cmpret = 0, i = 0, found_idx = SIZE_MAX, wait_set_len = 0; \ + size_t cmpret = 0, i = 0, found_idx = SIZE_MAX, num_ignored = 0; \ \ if (status) { \ for (i = 0; i < nelems; i++) { \ - if (status[i]) wait_set_len++; \ + if (status[i]) num_ignored++; \ } \ } \ - if (nelems == 0 || wait_set_len == nelems) \ + if (nelems == 0 || num_ignored == nelems) \ return SIZE_MAX; \ \ + unsigned int rand_seed = shmem_internal_my_pe; \ + size_t start_idx = rand_r(&rand_seed) / (RAND_MAX + 1.0) * nelems; \ + \ while (!cmpret) { \ - for (i = 0; i < nelems; i++) { \ - if (status == NULL || (status && !status[i])) { \ - COMP(cond, vars[i], value, cmpret); \ - } \ - if (cmpret) { \ - if (status) status[i] = 1; \ - found_idx = i; \ - break; \ + for (i = start_idx; i < start_idx + nelems; i++) { \ + size_t idx = i % nelems; \ + if (status == NULL || !status[idx]) { \ + COMP(cond, vars[idx], value, cmpret); \ + if (cmpret) { \ + if (status) status[idx] = 1; \ + found_idx = idx; \ + break; \ + } \ } \ } \ - shmem_transport_probe(); \ + if (!cmpret) shmem_transport_probe(); \ } \ \ shmem_internal_membar_load(); \ @@ -249,28 +256,28 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t cmpret = 0, i = 0, ncompleted = 0, wait_set_len = 0; \ + size_t cmpret = 0, i = 0, ncompleted = 0, num_ignored = 0; \ \ if (status) { \ for (i = 0; i < nelems; i++) { \ - if (status[i]) wait_set_len++; \ + if (status[i]) num_ignored++; \ } \ } \ - if (nelems == 0 || wait_set_len == nelems) \ + if (nelems == 0 || num_ignored == nelems) \ return 0; \ \ while (ncompleted == 0) { \ for (i = 0; i < nelems; i++) { \ - if (status == NULL || (status && !status[i])) { \ + if (status == NULL || !status[i]) { \ COMP(cond, vars[i], value, cmpret); \ - } \ - if (cmpret) { \ - if (status) status[i] = 1; \ - indices[ncompleted++] = i; \ - cmpret = 0; \ + if (cmpret) { \ + if (status) status[i] = 1; \ + indices[ncompleted++] = i; \ + cmpret = 0; \ + } \ } \ } \ - shmem_transport_probe(); \ + if (!cmpret) shmem_transport_probe(); \ } \ shmem_internal_membar_load(); \ shmem_transport_syncmem(); \ @@ -308,6 +315,8 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ + if (nelems == 0) return 1; \ + \ for (int i = 0; i < nelems; i++) { \ COMP(cond, vars[i], value, cmpret); \ if (cmpret) ncompleted++; \ @@ -333,15 +342,20 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') SHMEM_ERR_CHECK_CMP_OP(cond); \ \ size_t found_idx = SIZE_MAX, i = 0; \ - for (i = 0; i < nelems; i++) { \ + unsigned int rand_seed = shmem_internal_my_pe; \ + size_t start_idx = rand_r(&rand_seed) / (RAND_MAX + 1.0) * nelems; \ + \ + for (i = start_idx; i < start_idx + nelems; i++) { \ size_t cmpret = 0; \ - if (status == NULL || (status && !status[i])) \ - COMP(cond, vars[i], value, cmpret); \ - if (cmpret) { \ - if (status) status[i] = 1; \ - found_idx = i; \ - break; \ - } \ + size_t idx = i % nelems; \ + if (status == NULL || !status[idx]) { \ + COMP(cond, vars[idx], value, cmpret); \ + if (cmpret) { \ + if (status) status[idx] = 1; \ + found_idx = idx; \ + break; \ + } \ + } \ } \ if (found_idx != SIZE_MAX) \ shmem_internal_membar_load(); \ @@ -361,24 +375,24 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t cmpret = 0, i = 0, ncompleted = 0, wait_set_len = 0; \ + size_t cmpret = 0, i = 0, ncompleted = 0, num_ignored = 0; \ \ if (status) { \ for (i = 0; i < nelems; i++) { \ - if (status[i]) wait_set_len++; \ + if (status[i]) num_ignored++; \ } \ } \ - if (nelems == 0 || wait_set_len == nelems) \ + if (nelems == 0 || num_ignored == nelems) \ return 0; \ \ for (i = 0; i < nelems; i++) { \ if (status == NULL || !status[i]) { \ COMP(cond, vars[i], value, cmpret); \ - } \ - if (cmpret) { \ - if (status) status[i] = 1; \ - indices[ncompleted++] = i; \ - cmpret = 0; \ + if (cmpret) { \ + if (status) status[i] = 1; \ + indices[ncompleted++] = i; \ + cmpret = 0; \ + } \ } \ } \ shmem_internal_membar_load(); \ diff --git a/test/shmemx/shmemx_test_all.c b/test/shmemx/shmemx_test_all.c index bcd3b78ba..6a6425007 100644 --- a/test/shmemx/shmemx_test_all.c +++ b/test/shmemx/shmemx_test_all.c @@ -45,6 +45,11 @@ int main(void) while (!shmemx_int_test_all(flags, npes, SHMEM_CMP_EQ, 1)); + /* Check the flags array */ + for (int i = 0; i < npes; i++) { + if (flags[i] != 1) + shmem_global_exit(1); + } shmem_free(flags); shmem_finalize(); return 0; diff --git a/test/shmemx/shmemx_test_any.c b/test/shmemx/shmemx_test_any.c index 46cdc0ab0..db5199a14 100644 --- a/test/shmemx/shmemx_test_any.c +++ b/test/shmemx/shmemx_test_any.c @@ -32,7 +32,7 @@ #include #include #include - + int main(void) { shmem_init(); @@ -57,12 +57,18 @@ int main(void) } } + /* Check the flags array */ + for (int i = 0; i < npes; i++) { + if (flags[i] != 1) + shmem_global_exit(1); + } + /* Sanity check case with NULL status array */ completed_idx = shmemx_int_test_any(flags, npes, NULL, SHMEM_CMP_EQ, 1); - if (completed_idx == SIZE_MAX || completed_idx >= npes) + if (completed_idx >= npes) shmem_global_exit(2); - + free(status); shmem_free(flags); shmem_finalize(); diff --git a/test/shmemx/shmemx_test_some.c b/test/shmemx/shmemx_test_some.c index 8c7ca0ee0..35598b2e4 100644 --- a/test/shmemx/shmemx_test_some.c +++ b/test/shmemx/shmemx_test_some.c @@ -76,6 +76,12 @@ int main(void) } } + /* Check the flags array */ + for (int i = 0; i < npes; i++) { + if (flags[i] != 1) + shmem_global_exit(0); + } + /* check result */ int M = N * npes - 1; if (total_sum != M * (M + 1) / 2) { @@ -85,10 +91,9 @@ int main(void) /* Sanity check case with NULL status array */ ncompleted = shmemx_int_test_some(flags, npes, indices, NULL, SHMEM_CMP_EQ, 1); - if (ncompleted == 0 || ncompleted > npes) + if (ncompleted != npes) shmem_global_exit(2); - shmem_finalize(); return 0; } diff --git a/test/shmemx/shmemx_wait_until_all.c b/test/shmemx/shmemx_wait_until_all.c index 757e84314..f79a9146e 100644 --- a/test/shmemx/shmemx_wait_until_all.c +++ b/test/shmemx/shmemx_wait_until_all.c @@ -45,6 +45,12 @@ int main(void) shmemx_int_wait_until_all(flags, npes, SHMEM_CMP_EQ, 1); + /* Check the flags array */ + for (int i = 0; i < npes; i++) { + if (flags[i] != 1) + shmem_global_exit(1); + } + shmem_free(flags); shmem_finalize(); return 0; diff --git a/test/shmemx/shmemx_wait_until_any.c b/test/shmemx/shmemx_wait_until_any.c index c6b57ff19..ed64d8862 100644 --- a/test/shmemx/shmemx_wait_until_any.c +++ b/test/shmemx/shmemx_wait_until_any.c @@ -67,6 +67,12 @@ int main(void) total_sum += all_data[completed_idx * N + j]; } + /* Check the flags array */ + for (int i = 0; i < npes; i++) { + if (flags[i] != 1) + shmem_global_exit(0); + } + /* check result */ int M = N * npes - 1; if (total_sum != M * (M + 1) / 2) { @@ -76,7 +82,7 @@ int main(void) /* Sanity check the case with NULL status array */ completed_idx = shmemx_int_wait_until_any(flags, npes, NULL, SHMEM_CMP_EQ, 1); - if (completed_idx == SIZE_MAX || completed_idx >= npes) + if (completed_idx >= npes) shmem_global_exit(2); shmem_finalize(); diff --git a/test/shmemx/shmemx_wait_until_some.c b/test/shmemx/shmemx_wait_until_some.c index 98a7c5c9c..b806bf4f1 100644 --- a/test/shmemx/shmemx_wait_until_some.c +++ b/test/shmemx/shmemx_wait_until_some.c @@ -39,6 +39,12 @@ int main(void) } } + /* Check the flags array */ + for (int i = 0; i < npes; i++) { + if (flags[i] != 1) + shmem_global_exit(0); + } + /* check result */ int M = N * npes - 1; if (total_sum != M * (M + 1) / 2) { @@ -48,7 +54,7 @@ int main(void) /* Sanity check the case with NULL status array */ ncompleted = shmemx_int_wait_until_some(flags, npes, indices, NULL, SHMEM_CMP_EQ, 1); - if (ncompleted == 0 || ncompleted > npes) + if (ncompleted != npes) shmem_global_exit(2); shmem_finalize(); From 2fc6b70311fc4b02e34b17c16c01afc0883a66f9 Mon Sep 17 00:00:00 2001 From: David Ozog Date: Mon, 26 Nov 2018 09:03:35 -0500 Subject: [PATCH 13/23] Init/fini randr seed and mutex for fair wait/test Signed-off-by: David Ozog --- src/init.c | 42 +++++++++++++++++++++++++++++++++++++ src/shmem_internal.h | 3 +++ src/shmem_synchronization.h | 2 -- src/synchronization_c.c4 | 19 ++++++++++------- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/init.c b/src/init.c index 98ec1152f..a473d6a44 100644 --- a/src/init.c +++ b/src/init.c @@ -35,6 +35,7 @@ #include "shmem.h" #include "shmem_internal.h" #include "shmem_collectives.h" +#include "shmem_synchronization.h" #include "shmem_comm.h" #include "runtime.h" #include "build_info.h" @@ -68,10 +69,16 @@ int shmem_internal_global_exit_called = 0; int shmem_internal_thread_level; +unsigned int shmem_internal_rand_seed; + #ifdef ENABLE_THREADS shmem_internal_mutex_t shmem_internal_mutex_alloc; #endif +#ifdef ENABLE_THREADS +shmem_internal_mutex_t shmem_internal_mutex_rand_r; +#endif + #ifdef USE_ON_NODE_COMMS char *shmem_internal_location_array = NULL; #endif @@ -85,6 +92,30 @@ static char shmem_internal_my_hostname[HOST_NAME_MAX]; static char *shmem_internal_thread_level_str[4] = { "SINGLE", "FUNNELED", "SERIALIZED", "MULTIPLE" }; +static void +shmem_internal_randr_init(void) +{ + shmem_internal_rand_seed = shmem_internal_my_pe; + +#ifdef ENABLE_THREADS + SHMEM_MUTEX_INIT(shmem_internal_mutex_rand_r); +#endif + + return; +} + +static void +shmem_internal_randr_fini(void) +{ + +#ifdef ENABLE_THREADS + SHMEM_MUTEX_DESTROY(shmem_internal_mutex_rand_r); +#endif + + return; +} + + static void shmem_internal_shutdown(void) { @@ -107,6 +138,8 @@ shmem_internal_shutdown(void) SHMEM_MUTEX_DESTROY(shmem_internal_mutex_alloc); + shmem_internal_randr_fini(); + shmem_internal_symmetric_fini(); shmem_runtime_fini(); } @@ -149,6 +182,7 @@ shmem_internal_init(int tl_requested, int *tl_provided) #ifdef USE_CMA int cma_initialized = 0; #endif + int randr_initialized = 0; #ifdef HAVE_SCHED_GETAFFINITY cpu_set_t my_set; @@ -395,6 +429,9 @@ shmem_internal_init(int tl_requested, int *tl_provided) goto cleanup; } + shmem_internal_randr_init(); + randr_initialized = 1; + atexit(shmem_internal_shutdown_atexit); shmem_internal_initialized = 1; @@ -428,6 +465,11 @@ shmem_internal_init(int tl_requested, int *tl_provided) shmem_transport_cma_fini(); } #endif + + if (randr_initialized) { + shmem_internal_randr_fini(); + } + if (NULL != shmem_internal_data_base) { shmem_internal_symmetric_fini(); } diff --git a/src/shmem_internal.h b/src/shmem_internal.h index 226fea3f8..fc21c7ed1 100644 --- a/src/shmem_internal.h +++ b/src/shmem_internal.h @@ -40,6 +40,8 @@ extern long shmem_internal_heap_length; extern void *shmem_internal_data_base; extern long shmem_internal_data_length; +extern unsigned int shmem_internal_rand_seed; + #define SHMEM_INTERNAL_HEAP_OVERHEAD (1024*1024) #define SHMEM_INTERNAL_DIAG_STRLEN 1024 @@ -394,6 +396,7 @@ typedef shmem_spinlock_t shmem_internal_mutex_t; # endif /* ENABLE_PTHREAD_MUTEX */ extern shmem_internal_mutex_t shmem_internal_mutex_alloc; +extern shmem_internal_mutex_t shmem_internal_mutex_rand_r; #else # define SHMEM_MUTEX_INIT(_mutex) diff --git a/src/shmem_synchronization.h b/src/shmem_synchronization.h index 430dcd3df..c8a9ec4ed 100644 --- a/src/shmem_synchronization.h +++ b/src/shmem_synchronization.h @@ -20,7 +20,6 @@ #include "shmem_comm.h" #include "transport.h" - static inline void shmem_internal_quiet(shmem_ctx_t ctx) { @@ -53,7 +52,6 @@ shmem_internal_fence(shmem_ctx_t ctx) * transport level memory flush is not required here. */ } - #define COMP(type, a, b, ret) \ do { \ ret = 0; \ diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index 442c34513..05f1800b5 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -221,8 +221,9 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') if (nelems == 0 || num_ignored == nelems) \ return SIZE_MAX; \ \ - unsigned int rand_seed = shmem_internal_my_pe; \ - size_t start_idx = rand_r(&rand_seed) / (RAND_MAX + 1.0) * nelems; \ + SHMEM_MUTEX_LOCK(shmem_internal_mutex_rand_r); \ + size_t start_idx = rand_r(&shmem_internal_rand_seed) / (RAND_MAX + 1.0) * nelems; \ + SHMEM_MUTEX_UNLOCK(shmem_internal_mutex_rand_r); \ \ while (!cmpret) { \ for (i = start_idx; i < start_idx + nelems; i++) { \ @@ -256,7 +257,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t cmpret = 0, i = 0, ncompleted = 0, num_ignored = 0; \ + size_t i = 0, ncompleted = 0, num_ignored = 0; \ \ if (status) { \ for (i = 0; i < nelems; i++) { \ @@ -267,6 +268,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') return 0; \ \ while (ncompleted == 0) { \ + size_t cmpret = 0; \ for (i = 0; i < nelems; i++) { \ if (status == NULL || !status[i]) { \ COMP(cond, vars[i], value, cmpret); \ @@ -310,7 +312,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST') int SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_test_all(TYPE *vars, size_t nelems, int cond, TYPE value) \ { \ - int cmpret, ncompleted = 0; \ + int ncompleted = 0; \ SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ @@ -318,6 +320,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST') if (nelems == 0) return 1; \ \ for (int i = 0; i < nelems; i++) { \ + int cmpret; \ COMP(cond, vars[i], value, cmpret); \ if (cmpret) ncompleted++; \ } \ @@ -342,8 +345,9 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') SHMEM_ERR_CHECK_CMP_OP(cond); \ \ size_t found_idx = SIZE_MAX, i = 0; \ - unsigned int rand_seed = shmem_internal_my_pe; \ - size_t start_idx = rand_r(&rand_seed) / (RAND_MAX + 1.0) * nelems; \ + SHMEM_MUTEX_LOCK(shmem_internal_mutex_rand_r); \ + size_t start_idx = rand_r(&shmem_internal_rand_seed) / (RAND_MAX + 1.0) * nelems; \ + SHMEM_MUTEX_UNLOCK(shmem_internal_mutex_rand_r); \ \ for (i = start_idx; i < start_idx + nelems; i++) { \ size_t cmpret = 0; \ @@ -375,7 +379,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t cmpret = 0, i = 0, ncompleted = 0, num_ignored = 0; \ + size_t i = 0, ncompleted = 0, num_ignored = 0; \ \ if (status) { \ for (i = 0; i < nelems; i++) { \ @@ -387,6 +391,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') \ for (i = 0; i < nelems; i++) { \ if (status == NULL || !status[i]) { \ + size_t cmpret; \ COMP(cond, vars[i], value, cmpret); \ if (cmpret) { \ if (status) status[i] = 1; \ From 6b1aabe8c99f2de2526d4c3f967b006ddf3b4b64 Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Tue, 27 Nov 2018 14:22:19 -0500 Subject: [PATCH 14/23] Unit test_any for fairness, fix loop index bounds Signed-off-by: David M. Ozog --- src/init.c | 1 - src/synchronization_c.c4 | 8 ++++---- test/shmemx/shmemx_test_any.c | 22 +++++++++++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/init.c b/src/init.c index a473d6a44..c5ec32b75 100644 --- a/src/init.c +++ b/src/init.c @@ -35,7 +35,6 @@ #include "shmem.h" #include "shmem_internal.h" #include "shmem_collectives.h" -#include "shmem_synchronization.h" #include "shmem_comm.h" #include "runtime.h" #include "build_info.h" diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index 05f1800b5..6041079e2 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -226,8 +226,8 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') SHMEM_MUTEX_UNLOCK(shmem_internal_mutex_rand_r); \ \ while (!cmpret) { \ - for (i = start_idx; i < start_idx + nelems; i++) { \ - size_t idx = i % nelems; \ + for (i = 0; i < nelems; i++) { \ + size_t idx = (i + start_idx) % nelems; \ if (status == NULL || !status[idx]) { \ COMP(cond, vars[idx], value, cmpret); \ if (cmpret) { \ @@ -349,9 +349,9 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') size_t start_idx = rand_r(&shmem_internal_rand_seed) / (RAND_MAX + 1.0) * nelems; \ SHMEM_MUTEX_UNLOCK(shmem_internal_mutex_rand_r); \ \ - for (i = start_idx; i < start_idx + nelems; i++) { \ + for (i = 0; i < nelems; i++) { \ size_t cmpret = 0; \ - size_t idx = i % nelems; \ + size_t idx = (i + start_idx) % nelems; \ if (status == NULL || !status[idx]) { \ COMP(cond, vars[idx], value, cmpret); \ if (cmpret) { \ diff --git a/test/shmemx/shmemx_test_any.c b/test/shmemx/shmemx_test_any.c index db5199a14..7659bfc0c 100644 --- a/test/shmemx/shmemx_test_any.c +++ b/test/shmemx/shmemx_test_any.c @@ -63,12 +63,32 @@ int main(void) shmem_global_exit(1); } + /* Sanity check of shmem_test_any's fairness */ + ncompleted = 0; + int *found = calloc(npes, sizeof(int)); + + while (ncompleted < npes) { + int idx = shmemx_test_any(flags, npes, NULL, SHMEM_CMP_EQ, 1); + if (found[idx] == 0) { + found[idx] = 1; + ncompleted++; + } + } + + for (int i = 0; i < npes; i++) { + if (found[i] != 1) { + shmem_global_exit(2); + } + } + /* Sanity check case with NULL status array */ completed_idx = shmemx_int_test_any(flags, npes, NULL, SHMEM_CMP_EQ, 1); if (completed_idx >= npes) - shmem_global_exit(2); + shmem_global_exit(3); + + free(found); free(status); shmem_free(flags); shmem_finalize(); From 08e42454dabd27be71b8791cd3ebfb86757dbe6f Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Tue, 27 Nov 2018 15:18:27 -0500 Subject: [PATCH 15/23] Use C API (not a C11 generic) in shmemx_test_any.c Signed-off-by: David M. Ozog --- test/shmemx/shmemx_test_any.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/shmemx/shmemx_test_any.c b/test/shmemx/shmemx_test_any.c index 7659bfc0c..d6fee17f3 100644 --- a/test/shmemx/shmemx_test_any.c +++ b/test/shmemx/shmemx_test_any.c @@ -68,7 +68,7 @@ int main(void) int *found = calloc(npes, sizeof(int)); while (ncompleted < npes) { - int idx = shmemx_test_any(flags, npes, NULL, SHMEM_CMP_EQ, 1); + int idx = shmemx_int_test_any(flags, npes, NULL, SHMEM_CMP_EQ, 1); if (found[idx] == 0) { found[idx] = 1; ncompleted++; From d6a6ccd950cc839512398a3d66f4bd74bbb3d78b Mon Sep 17 00:00:00 2001 From: Min Si Date: Thu, 15 Nov 2018 15:40:31 -0600 Subject: [PATCH 16/23] Move CXX generic to shmemx folder --- test/shmemx/Makefile.am | 40 +++++++++++++++++++ .../cxx_test_shmem_atomic_add.cpp | 0 .../cxx_test_shmem_atomic_and.cpp | 0 .../cxx_test_shmem_atomic_cswap.cpp | 0 .../cxx_test_shmem_atomic_fetch.cpp | 0 .../cxx_test_shmem_atomic_inc.cpp | 0 .../cxx_test_shmem_atomic_or.cpp | 0 .../cxx_test_shmem_atomic_set.cpp | 0 .../cxx_test_shmem_atomic_swap.cpp | 0 .../cxx_test_shmem_atomic_xor.cpp | 0 test/{unit => shmemx}/cxx_test_shmem_g.cpp | 0 test/{unit => shmemx}/cxx_test_shmem_get.cpp | 0 test/{unit => shmemx}/cxx_test_shmem_p.cpp | 0 test/{unit => shmemx}/cxx_test_shmem_put.cpp | 0 test/{unit => shmemx}/cxx_test_shmem_test.cpp | 0 .../cxx_test_shmem_wait_until.cpp | 0 test/unit/Makefile.am | 34 ---------------- 17 files changed, 40 insertions(+), 34 deletions(-) rename test/{unit => shmemx}/cxx_test_shmem_atomic_add.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_atomic_and.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_atomic_cswap.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_atomic_fetch.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_atomic_inc.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_atomic_or.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_atomic_set.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_atomic_swap.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_atomic_xor.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_g.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_get.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_p.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_put.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_test.cpp (100%) rename test/{unit => shmemx}/cxx_test_shmem_wait_until.cpp (100%) diff --git a/test/shmemx/Makefile.am b/test/shmemx/Makefile.am index 98c0e6739..49e0db56a 100644 --- a/test/shmemx/Makefile.am +++ b/test/shmemx/Makefile.am @@ -38,6 +38,27 @@ check_PROGRAMS += \ endif endif SHMEMX_TESTS +if HAVE_CXX +if SHMEMX_TESTS +check_PROGRAMS += \ + cxx_test_shmem_g \ + cxx_test_shmem_get \ + cxx_test_shmem_p \ + cxx_test_shmem_put \ + cxx_test_shmem_atomic_fetch \ + cxx_test_shmem_atomic_set \ + cxx_test_shmem_atomic_add \ + cxx_test_shmem_atomic_inc \ + cxx_test_shmem_atomic_and \ + cxx_test_shmem_atomic_or \ + cxx_test_shmem_atomic_xor \ + cxx_test_shmem_atomic_swap \ + cxx_test_shmem_atomic_cswap \ + cxx_test_shmem_wait_until \ + cxx_test_shmem_test +endif +endif + TESTS = $(check_PROGRAMS) NPROCS ?= 2 @@ -65,4 +86,23 @@ gettid_register_LDFLAGS = $(AM_LDFLAGS) $(PTHREAD_LIBS) gettid_register_CFLAGS = $(PTHREAD_CFLAGS) gettid_register_LDADD = $(LDADD) $(PTHREAD_CFLAGS) +AM_CPPFLAGS += -DENABLE_SHMEMX_TESTS + +# C++ Tests +cxx_test_shmem_g_SOURCES = cxx_test_shmem_g.cpp +cxx_test_shmem_get_SOURCES = cxx_test_shmem_get.cpp +cxx_test_shmem_p_SOURCES = cxx_test_shmem_p.cpp +cxx_test_shmem_put_SOURCES = cxx_test_shmem_put.cpp +cxx_test_shmem_atomic_fetch_SOURCES = cxx_test_shmem_atomic_fetch.cpp +cxx_test_shmem_atomic_set_SOURCES = cxx_test_shmem_atomic_set.cpp +cxx_test_shmem_atomic_add_SOURCES = cxx_test_shmem_atomic_add.cpp +cxx_test_shmem_atomic_inc_SOURCES = cxx_test_shmem_atomic_inc.cpp +cxx_test_shmem_atomic_and_SOURCES = cxx_test_shmem_atomic_and.cpp +cxx_test_shmem_atomic_or_SOURCES = cxx_test_shmem_atomic_or.cpp +cxx_test_shmem_atomic_xor_SOURCES = cxx_test_shmem_atomic_xor.cpp +cxx_test_shmem_atomic_swap_SOURCES = cxx_test_shmem_atomic_swap.cpp +cxx_test_shmem_atomic_cswap_SOURCES = cxx_test_shmem_atomic_cswap.cpp +cxx_test_shmem_wait_until_SOURCES = cxx_test_shmem_wait_until.cpp +cxx_test_shmem_test_SOURCES = cxx_test_shmem_test.cpp + endif diff --git a/test/unit/cxx_test_shmem_atomic_add.cpp b/test/shmemx/cxx_test_shmem_atomic_add.cpp similarity index 100% rename from test/unit/cxx_test_shmem_atomic_add.cpp rename to test/shmemx/cxx_test_shmem_atomic_add.cpp diff --git a/test/unit/cxx_test_shmem_atomic_and.cpp b/test/shmemx/cxx_test_shmem_atomic_and.cpp similarity index 100% rename from test/unit/cxx_test_shmem_atomic_and.cpp rename to test/shmemx/cxx_test_shmem_atomic_and.cpp diff --git a/test/unit/cxx_test_shmem_atomic_cswap.cpp b/test/shmemx/cxx_test_shmem_atomic_cswap.cpp similarity index 100% rename from test/unit/cxx_test_shmem_atomic_cswap.cpp rename to test/shmemx/cxx_test_shmem_atomic_cswap.cpp diff --git a/test/unit/cxx_test_shmem_atomic_fetch.cpp b/test/shmemx/cxx_test_shmem_atomic_fetch.cpp similarity index 100% rename from test/unit/cxx_test_shmem_atomic_fetch.cpp rename to test/shmemx/cxx_test_shmem_atomic_fetch.cpp diff --git a/test/unit/cxx_test_shmem_atomic_inc.cpp b/test/shmemx/cxx_test_shmem_atomic_inc.cpp similarity index 100% rename from test/unit/cxx_test_shmem_atomic_inc.cpp rename to test/shmemx/cxx_test_shmem_atomic_inc.cpp diff --git a/test/unit/cxx_test_shmem_atomic_or.cpp b/test/shmemx/cxx_test_shmem_atomic_or.cpp similarity index 100% rename from test/unit/cxx_test_shmem_atomic_or.cpp rename to test/shmemx/cxx_test_shmem_atomic_or.cpp diff --git a/test/unit/cxx_test_shmem_atomic_set.cpp b/test/shmemx/cxx_test_shmem_atomic_set.cpp similarity index 100% rename from test/unit/cxx_test_shmem_atomic_set.cpp rename to test/shmemx/cxx_test_shmem_atomic_set.cpp diff --git a/test/unit/cxx_test_shmem_atomic_swap.cpp b/test/shmemx/cxx_test_shmem_atomic_swap.cpp similarity index 100% rename from test/unit/cxx_test_shmem_atomic_swap.cpp rename to test/shmemx/cxx_test_shmem_atomic_swap.cpp diff --git a/test/unit/cxx_test_shmem_atomic_xor.cpp b/test/shmemx/cxx_test_shmem_atomic_xor.cpp similarity index 100% rename from test/unit/cxx_test_shmem_atomic_xor.cpp rename to test/shmemx/cxx_test_shmem_atomic_xor.cpp diff --git a/test/unit/cxx_test_shmem_g.cpp b/test/shmemx/cxx_test_shmem_g.cpp similarity index 100% rename from test/unit/cxx_test_shmem_g.cpp rename to test/shmemx/cxx_test_shmem_g.cpp diff --git a/test/unit/cxx_test_shmem_get.cpp b/test/shmemx/cxx_test_shmem_get.cpp similarity index 100% rename from test/unit/cxx_test_shmem_get.cpp rename to test/shmemx/cxx_test_shmem_get.cpp diff --git a/test/unit/cxx_test_shmem_p.cpp b/test/shmemx/cxx_test_shmem_p.cpp similarity index 100% rename from test/unit/cxx_test_shmem_p.cpp rename to test/shmemx/cxx_test_shmem_p.cpp diff --git a/test/unit/cxx_test_shmem_put.cpp b/test/shmemx/cxx_test_shmem_put.cpp similarity index 100% rename from test/unit/cxx_test_shmem_put.cpp rename to test/shmemx/cxx_test_shmem_put.cpp diff --git a/test/unit/cxx_test_shmem_test.cpp b/test/shmemx/cxx_test_shmem_test.cpp similarity index 100% rename from test/unit/cxx_test_shmem_test.cpp rename to test/shmemx/cxx_test_shmem_test.cpp diff --git a/test/unit/cxx_test_shmem_wait_until.cpp b/test/shmemx/cxx_test_shmem_wait_until.cpp similarity index 100% rename from test/unit/cxx_test_shmem_wait_until.cpp rename to test/shmemx/cxx_test_shmem_wait_until.cpp diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 3271fccab..8e69827eb 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -112,25 +112,6 @@ endif if HAVE_CXX check_PROGRAMS += \ cxx_test_shmem_complex - -if SHMEMX_TESTS -check_PROGRAMS += \ - cxx_test_shmem_g \ - cxx_test_shmem_get \ - cxx_test_shmem_p \ - cxx_test_shmem_put \ - cxx_test_shmem_atomic_fetch \ - cxx_test_shmem_atomic_set \ - cxx_test_shmem_atomic_add \ - cxx_test_shmem_atomic_inc \ - cxx_test_shmem_atomic_and \ - cxx_test_shmem_atomic_or \ - cxx_test_shmem_atomic_xor \ - cxx_test_shmem_atomic_swap \ - cxx_test_shmem_atomic_cswap \ - cxx_test_shmem_wait_until \ - cxx_test_shmem_test -endif endif if HAVE_FORTRAN @@ -235,18 +216,3 @@ set_fetch_f_SOURCES = set_fetch_f.f90 # C++ Tests cxx_test_shmem_complex_SOURCES = cxx_test_shmem_complex.cpp -cxx_test_shmem_g_SOURCES = cxx_test_shmem_g.cpp -cxx_test_shmem_get_SOURCES = cxx_test_shmem_get.cpp -cxx_test_shmem_p_SOURCES = cxx_test_shmem_p.cpp -cxx_test_shmem_put_SOURCES = cxx_test_shmem_put.cpp -cxx_test_shmem_atomic_fetch_SOURCES = cxx_test_shmem_atomic_fetch.cpp -cxx_test_shmem_atomic_set_SOURCES = cxx_test_shmem_atomic_set.cpp -cxx_test_shmem_atomic_add_SOURCES = cxx_test_shmem_atomic_add.cpp -cxx_test_shmem_atomic_inc_SOURCES = cxx_test_shmem_atomic_inc.cpp -cxx_test_shmem_atomic_and_SOURCES = cxx_test_shmem_atomic_and.cpp -cxx_test_shmem_atomic_or_SOURCES = cxx_test_shmem_atomic_or.cpp -cxx_test_shmem_atomic_xor_SOURCES = cxx_test_shmem_atomic_xor.cpp -cxx_test_shmem_atomic_swap_SOURCES = cxx_test_shmem_atomic_swap.cpp -cxx_test_shmem_atomic_cswap_SOURCES = cxx_test_shmem_atomic_cswap.cpp -cxx_test_shmem_wait_until_SOURCES = cxx_test_shmem_wait_until.cpp -cxx_test_shmem_test_SOURCES = cxx_test_shmem_test.cpp From cb60df05f9f1a7dc57075774b517636b94f0941e Mon Sep 17 00:00:00 2001 From: Min Si Date: Thu, 15 Nov 2018 16:03:39 -0600 Subject: [PATCH 17/23] Add CXX standard tests in test/unit --- test/unit/Makefile.am | 32 ++- test/unit/cxx_test_shmem_atomic_add.cpp | 196 +++++++++++++++++ test/unit/cxx_test_shmem_atomic_and.cpp | 134 ++++++++++++ test/unit/cxx_test_shmem_atomic_cswap.cpp | 136 ++++++++++++ test/unit/cxx_test_shmem_atomic_fetch.cpp | 134 ++++++++++++ test/unit/cxx_test_shmem_atomic_inc.cpp | 195 +++++++++++++++++ test/unit/cxx_test_shmem_atomic_or.cpp | 134 ++++++++++++ test/unit/cxx_test_shmem_atomic_set.cpp | 132 ++++++++++++ test/unit/cxx_test_shmem_atomic_swap.cpp | 140 ++++++++++++ test/unit/cxx_test_shmem_atomic_xor.cpp | 134 ++++++++++++ test/unit/cxx_test_shmem_g.cpp | 117 ++++++++++ test/unit/cxx_test_shmem_get.cpp | 246 ++++++++++++++++++++++ test/unit/cxx_test_shmem_p.cpp | 115 ++++++++++ test/unit/cxx_test_shmem_put.cpp | 245 +++++++++++++++++++++ test/unit/cxx_test_shmem_test.cpp | 76 +++++++ test/unit/cxx_test_shmem_wait_until.cpp | 76 +++++++ 16 files changed, 2241 insertions(+), 1 deletion(-) create mode 100644 test/unit/cxx_test_shmem_atomic_add.cpp create mode 100644 test/unit/cxx_test_shmem_atomic_and.cpp create mode 100644 test/unit/cxx_test_shmem_atomic_cswap.cpp create mode 100644 test/unit/cxx_test_shmem_atomic_fetch.cpp create mode 100644 test/unit/cxx_test_shmem_atomic_inc.cpp create mode 100644 test/unit/cxx_test_shmem_atomic_or.cpp create mode 100644 test/unit/cxx_test_shmem_atomic_set.cpp create mode 100644 test/unit/cxx_test_shmem_atomic_swap.cpp create mode 100644 test/unit/cxx_test_shmem_atomic_xor.cpp create mode 100644 test/unit/cxx_test_shmem_g.cpp create mode 100644 test/unit/cxx_test_shmem_get.cpp create mode 100644 test/unit/cxx_test_shmem_p.cpp create mode 100644 test/unit/cxx_test_shmem_put.cpp create mode 100644 test/unit/cxx_test_shmem_test.cpp create mode 100644 test/unit/cxx_test_shmem_wait_until.cpp diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 8e69827eb..d370fee4e 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -111,7 +111,22 @@ endif if HAVE_CXX check_PROGRAMS += \ - cxx_test_shmem_complex + cxx_test_shmem_complex \ + cxx_test_shmem_g \ + cxx_test_shmem_get \ + cxx_test_shmem_p \ + cxx_test_shmem_put \ + cxx_test_shmem_atomic_fetch \ + cxx_test_shmem_atomic_set \ + cxx_test_shmem_atomic_add \ + cxx_test_shmem_atomic_inc \ + cxx_test_shmem_atomic_and \ + cxx_test_shmem_atomic_or \ + cxx_test_shmem_atomic_xor \ + cxx_test_shmem_atomic_swap \ + cxx_test_shmem_atomic_cswap \ + cxx_test_shmem_wait_until \ + cxx_test_shmem_test endif if HAVE_FORTRAN @@ -216,3 +231,18 @@ set_fetch_f_SOURCES = set_fetch_f.f90 # C++ Tests cxx_test_shmem_complex_SOURCES = cxx_test_shmem_complex.cpp +cxx_test_shmem_g_SOURCES = cxx_test_shmem_g.cpp +cxx_test_shmem_get_SOURCES = cxx_test_shmem_get.cpp +cxx_test_shmem_p_SOURCES = cxx_test_shmem_p.cpp +cxx_test_shmem_put_SOURCES = cxx_test_shmem_put.cpp +cxx_test_shmem_atomic_fetch_SOURCES = cxx_test_shmem_atomic_fetch.cpp +cxx_test_shmem_atomic_set_SOURCES = cxx_test_shmem_atomic_set.cpp +cxx_test_shmem_atomic_add_SOURCES = cxx_test_shmem_atomic_add.cpp +cxx_test_shmem_atomic_inc_SOURCES = cxx_test_shmem_atomic_inc.cpp +cxx_test_shmem_atomic_and_SOURCES = cxx_test_shmem_atomic_and.cpp +cxx_test_shmem_atomic_or_SOURCES = cxx_test_shmem_atomic_or.cpp +cxx_test_shmem_atomic_xor_SOURCES = cxx_test_shmem_atomic_xor.cpp +cxx_test_shmem_atomic_swap_SOURCES = cxx_test_shmem_atomic_swap.cpp +cxx_test_shmem_atomic_cswap_SOURCES = cxx_test_shmem_atomic_cswap.cpp +cxx_test_shmem_wait_until_SOURCES = cxx_test_shmem_wait_until.cpp +cxx_test_shmem_test_SOURCES = cxx_test_shmem_test.cpp diff --git a/test/unit/cxx_test_shmem_atomic_add.cpp b/test/unit/cxx_test_shmem_atomic_add.cpp new file mode 100644 index 000000000..bc45323f2 --- /dev/null +++ b/test/unit/cxx_test_shmem_atomic_add.cpp @@ -0,0 +1,196 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +enum op { ADD = 0, ATOMIC_ADD, CTX_ATOMIC_ADD, FADD, ATOMIC_FETCH_ADD, + CTX_ATOMIC_FETCH_ADD }; + +#ifdef ENABLE_DEPRECATED_TESTS +#define DEPRECATED_ADD(TYPENAME, ...) shmem_##TYPENAME##_add(__VA_ARGS__) +#define DEPRECATED_FADD(TYPENAME, ...) shmem_##TYPENAME##_fadd(__VA_ARGS__) +#else +#define DEPRECATED_ADD(TYPENAME, ...) shmem_##TYPENAME##_atomic_add(__VA_ARGS__) +#define DEPRECATED_FADD(TYPENAME, ...) shmem_##TYPENAME##_atomic_fetch_add(__VA_ARGS__) +#endif + +#define TEST_SHMEM_ADD(OP, TYPE, TYPENAME) \ + do { \ + static TYPE remote; \ + TYPE old; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + remote = (TYPE)0; \ + shmem_barrier_all(); \ + for (int i = 0; i < npes; i++) \ + switch (OP) { \ + case ADD: \ + DEPRECATED_ADD(TYPENAME, &remote, (TYPE)(mype + 1), i); \ + break; \ + case ATOMIC_ADD: \ + shmem_##TYPENAME##_atomic_add(&remote, (TYPE)(mype + 1), i); \ + break; \ + case CTX_ATOMIC_ADD: \ + shmem_ctx_##TYPENAME##_atomic_add(SHMEM_CTX_DEFAULT, &remote, \ + (TYPE)(mype + 1), i); \ + break; \ + case FADD: \ + old = DEPRECATED_FADD(TYPENAME, &remote, (TYPE)(mype + 1), i);\ + if (old > (TYPE)(npes * (npes + 1) / 2)) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case ATOMIC_FETCH_ADD: \ + old = shmem_##TYPENAME##_atomic_fetch_add(&remote, \ + (TYPE)(mype + 1), i);\ + if (old > (TYPE)(npes * (npes + 1) / 2)) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_ATOMIC_FETCH_ADD: \ + old = shmem_ctx_##TYPENAME##_atomic_fetch_add( \ + SHMEM_CTX_DEFAULT, &remote, (TYPE)(mype + 1), i); \ + if (old > (TYPE)(npes * (npes + 1) / 2)) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + default: \ + printf("Invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + shmem_barrier_all(); \ + if (remote != (TYPE)(npes * (npes + 1) / 2)) { \ + printf("PE %i observed error with TEST_SHMEM_ADD(%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + +#ifdef ENABLE_DEPRECATED_TESTS + TEST_SHMEM_ADD(ADD, int, int); + TEST_SHMEM_ADD(ADD, long, long); + TEST_SHMEM_ADD(ADD, long long, longlong); + TEST_SHMEM_ADD(ADD, unsigned int, uint); + TEST_SHMEM_ADD(ADD, unsigned long, ulong); + TEST_SHMEM_ADD(ADD, unsigned long long, ulonglong); + TEST_SHMEM_ADD(ADD, int32_t, int32); + TEST_SHMEM_ADD(ADD, int64_t, int64); + TEST_SHMEM_ADD(ADD, uint32_t, uint32); + TEST_SHMEM_ADD(ADD, uint64_t, uint64); + TEST_SHMEM_ADD(ADD, size_t, size); + TEST_SHMEM_ADD(ADD, ptrdiff_t, ptrdiff); +#endif /* ENABLE_DEPRECATED_TESTS */ + + TEST_SHMEM_ADD(ATOMIC_ADD, int, int); + TEST_SHMEM_ADD(ATOMIC_ADD, long, long); + TEST_SHMEM_ADD(ATOMIC_ADD, long long, longlong); + TEST_SHMEM_ADD(ATOMIC_ADD, unsigned int, uint); + TEST_SHMEM_ADD(ATOMIC_ADD, unsigned long, ulong); + TEST_SHMEM_ADD(ATOMIC_ADD, unsigned long long, ulonglong); + TEST_SHMEM_ADD(ATOMIC_ADD, int32_t, int32); + TEST_SHMEM_ADD(ATOMIC_ADD, int64_t, int64); + TEST_SHMEM_ADD(ATOMIC_ADD, uint32_t, uint32); + TEST_SHMEM_ADD(ATOMIC_ADD, uint64_t, uint64); + TEST_SHMEM_ADD(ATOMIC_ADD, size_t, size); + TEST_SHMEM_ADD(ATOMIC_ADD, ptrdiff_t, ptrdiff); + + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, int, int); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, long, long); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, long long, longlong); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, unsigned int, uint); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, unsigned long, ulong); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, unsigned long long, ulonglong); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, int32_t, int32); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, int64_t, int64); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, uint32_t, uint32); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, uint64_t, uint64); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, size_t, size); + TEST_SHMEM_ADD(CTX_ATOMIC_ADD, ptrdiff_t, ptrdiff); + + TEST_SHMEM_ADD(FADD, int, int); + TEST_SHMEM_ADD(FADD, long, long); + TEST_SHMEM_ADD(FADD, long long, longlong); + TEST_SHMEM_ADD(FADD, unsigned int, uint); + TEST_SHMEM_ADD(FADD, unsigned long, ulong); + TEST_SHMEM_ADD(FADD, unsigned long long, ulonglong); + TEST_SHMEM_ADD(FADD, int32_t, int32); + TEST_SHMEM_ADD(FADD, int64_t, int64); + TEST_SHMEM_ADD(FADD, uint32_t, uint32); + TEST_SHMEM_ADD(FADD, uint64_t, uint64); + TEST_SHMEM_ADD(FADD, size_t, size); + TEST_SHMEM_ADD(FADD, ptrdiff_t, ptrdiff); + + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, int, int); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, long, long); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, long long, longlong); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, unsigned int, uint); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, unsigned long, ulong); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, unsigned long long, ulonglong); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, int32_t, int32); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, int64_t, int64); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, uint32_t, uint32); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, uint64_t, uint64); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, size_t, size); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, ptrdiff_t, ptrdiff); + + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, int, int); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, long, long); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, long long, longlong); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, unsigned int, uint); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, unsigned long, ulong); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, unsigned long long, ulonglong); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, int32_t, int32); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, int64_t, int64); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, uint32_t, uint32); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, uint64_t, uint64); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, size_t, size); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_atomic_and.cpp b/test/unit/cxx_test_shmem_atomic_and.cpp new file mode 100644 index 000000000..fb089fdd5 --- /dev/null +++ b/test/unit/cxx_test_shmem_atomic_and.cpp @@ -0,0 +1,134 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +enum op { AND = 0, CTX_AND, FETCH_AND, CTX_FETCH_AND }; + +/* Initially, remote = 111...b. Each PE performs an atomic AND where the + * PEth bit of the input value is set to 0 and all other bits are set to 1. + * The result has the NPES least significant bits cleared, 111...000...b. + */ + +#define TEST_SHMEM_AND(OP, TYPE, TYPENAME) \ + do { \ + static TYPE remote = ~(TYPE)0; \ + TYPE old = (TYPE)0; \ + if ((size_t) npes-1 > sizeof(TYPE)) break; /* Avoid overflow */ \ + for (int i = 0; i < npes; i++) \ + switch (OP) { \ + case AND: \ + shmem_##TYPENAME##_atomic_and(&remote, \ + ~(TYPE)(1LLU << mype), i); \ + break; \ + case CTX_AND: \ + shmem_ctx_##TYPENAME##_atomic_and(SHMEM_CTX_DEFAULT, &remote, \ + ~(TYPE)(1LLU << mype), i); \ + break; \ + case FETCH_AND: \ + old = shmem_##TYPENAME##_atomic_fetch_and(&remote, \ + ~(TYPE)(1LLU << mype), i); \ + if ((old & (TYPE)(1LLU << mype)) == 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_FETCH_AND: \ + old = shmem_ctx_##TYPENAME##_atomic_fetch_and( \ + SHMEM_CTX_DEFAULT, &remote, ~(TYPE)(1LLU << mype), i); \ + if ((old & (TYPE)(1LLU << mype)) == 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + default: \ + printf("Invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + shmem_barrier_all(); \ + if (remote != ~(TYPE)((1LLU << npes) - 1LLU)) { \ + printf("PE %i observed error with TEST_SHMEM_AND(%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + + +int main(int argc, char* argv[]) { + shmem_init(); + + const int mype = shmem_my_pe(); + const int npes = shmem_n_pes(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_AND(AND, unsigned int, uint); + TEST_SHMEM_AND(AND, unsigned long, ulong); + TEST_SHMEM_AND(AND, unsigned long long, ulonglong); + TEST_SHMEM_AND(AND, int32_t, int32); + TEST_SHMEM_AND(AND, int64_t, int64); + TEST_SHMEM_AND(AND, uint32_t, uint32); + TEST_SHMEM_AND(AND, uint64_t, uint64); + + TEST_SHMEM_AND(CTX_AND, unsigned int, uint); + TEST_SHMEM_AND(CTX_AND, unsigned long, ulong); + TEST_SHMEM_AND(CTX_AND, unsigned long long, ulonglong); + TEST_SHMEM_AND(CTX_AND, int32_t, int32); + TEST_SHMEM_AND(CTX_AND, int64_t, int64); + TEST_SHMEM_AND(CTX_AND, uint32_t, uint32); + TEST_SHMEM_AND(CTX_AND, uint64_t, uint64); + + TEST_SHMEM_AND(FETCH_AND, unsigned int, uint); + TEST_SHMEM_AND(FETCH_AND, unsigned long, ulong); + TEST_SHMEM_AND(FETCH_AND, unsigned long long, ulonglong); + TEST_SHMEM_AND(FETCH_AND, int32_t, int32); + TEST_SHMEM_AND(FETCH_AND, int64_t, int64); + TEST_SHMEM_AND(FETCH_AND, uint32_t, uint32); + TEST_SHMEM_AND(FETCH_AND, uint64_t, uint64); + + TEST_SHMEM_AND(CTX_FETCH_AND, unsigned int, uint); + TEST_SHMEM_AND(CTX_FETCH_AND, unsigned long, ulong); + TEST_SHMEM_AND(CTX_FETCH_AND, unsigned long long, ulonglong); + TEST_SHMEM_AND(CTX_FETCH_AND, int32_t, int32); + TEST_SHMEM_AND(CTX_FETCH_AND, int64_t, int64); + TEST_SHMEM_AND(CTX_FETCH_AND, uint32_t, uint32); + TEST_SHMEM_AND(CTX_FETCH_AND, uint64_t, uint64); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_atomic_cswap.cpp b/test/unit/cxx_test_shmem_atomic_cswap.cpp new file mode 100644 index 000000000..4e0e34582 --- /dev/null +++ b/test/unit/cxx_test_shmem_atomic_cswap.cpp @@ -0,0 +1,136 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +enum op { CSWAP = 0, ATOMIC_COMPARE_SWAP, CTX_ATOMIC_COMPARE_SWAP }; + +#ifdef ENABLE_DEPRECATED_TESTS +#define DEPRECATED_CSWAP(TYPENAME,...) shmem_##TYPENAME##_cswap(__VA_ARGS__) +#else +#define DEPRECATED_CSWAP(TYPENAME,...) shmem_##TYPENAME##_atomic_compare_swap(__VA_ARGS__) +#endif + +#define TEST_SHMEM_CSWAP(OP, TYPE, TYPENAME) \ + do { \ + static TYPE remote; \ + TYPE old; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + remote = npes; \ + shmem_barrier_all(); \ + switch (OP) { \ + case CSWAP: \ + old = DEPRECATED_CSWAP(TYPENAME, &remote, (TYPE)npes, \ + (TYPE)mype, (mype + 1) % npes); \ + break; \ + case ATOMIC_COMPARE_SWAP: \ + old = shmem_##TYPENAME##_atomic_compare_swap(&remote, \ + (TYPE)npes, (TYPE)mype, (mype + 1) % npes); \ + break; \ + case CTX_ATOMIC_COMPARE_SWAP: \ + old = shmem_ctx_##TYPENAME##_atomic_compare_swap( \ + SHMEM_CTX_DEFAULT, &remote, \ + (TYPE)npes, (TYPE)mype, \ + (mype + 1) % npes); \ + break; \ + default: \ + printf("invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + shmem_barrier_all(); \ + if (remote != (TYPE)((mype + npes - 1) % npes)) { \ + printf("PE %i observed error with TEST_SHMEM_CSWAP(%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + if (old != (TYPE) npes) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + +#ifdef ENABLE_DEPRECATED_TESTS + TEST_SHMEM_CSWAP(CSWAP, int, int); + TEST_SHMEM_CSWAP(CSWAP, long, long); + TEST_SHMEM_CSWAP(CSWAP, long long, longlong); + TEST_SHMEM_CSWAP(CSWAP, unsigned int, uint); + TEST_SHMEM_CSWAP(CSWAP, unsigned long, ulong); + TEST_SHMEM_CSWAP(CSWAP, unsigned long long, ulonglong); + TEST_SHMEM_CSWAP(CSWAP, int32_t, int32); + TEST_SHMEM_CSWAP(CSWAP, int64_t, int64); + TEST_SHMEM_CSWAP(CSWAP, uint32_t, uint32); + TEST_SHMEM_CSWAP(CSWAP, uint64_t, uint64); + TEST_SHMEM_CSWAP(CSWAP, size_t, size); + TEST_SHMEM_CSWAP(CSWAP, ptrdiff_t, ptrdiff); +#endif /* ENABLE_DEPRECATED_TESTS */ + + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, int, int); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, long, long); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, long long, longlong); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, unsigned int, uint); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, unsigned long, ulong); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, unsigned long long, ulonglong); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, int32_t, int32); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, int64_t, int64); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, uint32_t, uint32); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, uint64_t, uint64); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, size_t, size); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP, ptrdiff_t, ptrdiff); + + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, int, int); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, long, long); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, long long, longlong); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, unsigned int, uint); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, unsigned long, ulong); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, unsigned long long, ulonglong); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, int32_t, int32); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, int64_t, int64); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, uint32_t, uint32); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, uint64_t, uint64); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, size_t, size); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_atomic_fetch.cpp b/test/unit/cxx_test_shmem_atomic_fetch.cpp new file mode 100644 index 000000000..f65d865f9 --- /dev/null +++ b/test/unit/cxx_test_shmem_atomic_fetch.cpp @@ -0,0 +1,134 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +enum op { FETCH = 0, ATOMIC_FETCH, CTX_ATOMIC_FETCH }; + +#ifdef ENABLE_DEPRECATED_TESTS +#define DEPRECATED_FETCH(TYPENAME,...) shmem_##TYPENAME##_fetch(__VA_ARGS__) +#else +#define DEPRECATED_FETCH(TYPENAME,...) shmem_##TYPENAME##_atomic_fetch(__VA_ARGS__) +#endif + +#define TEST_SHMEM_FETCH(OP, TYPE, TYPENAME) \ + do { \ + static TYPE remote; \ + TYPE val; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + remote = (TYPE)mype; \ + shmem_barrier_all(); \ + switch (OP) { \ + case FETCH: \ + val = DEPRECATED_FETCH(TYPENAME, &remote, \ + (mype + 1) % npes); \ + break; \ + case ATOMIC_FETCH: \ + val = shmem_##TYPENAME##_atomic_fetch(&remote, \ + (mype + 1) % npes); \ + break; \ + case CTX_ATOMIC_FETCH: \ + val = shmem_ctx_##TYPENAME##_atomic_fetch( \ + SHMEM_CTX_DEFAULT, &remote, (mype + 1) % npes); \ + break; \ + default: \ + printf("Invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + if (val != (TYPE)((mype + 1) % npes)) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_FETCH(%s, %s)\n", mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + +#ifdef ENABLE_DEPRECATED_TESTS + TEST_SHMEM_FETCH(FETCH, float, float); + TEST_SHMEM_FETCH(FETCH, double, double); + TEST_SHMEM_FETCH(FETCH, int, int); + TEST_SHMEM_FETCH(FETCH, long, long); + TEST_SHMEM_FETCH(FETCH, long long, longlong); + TEST_SHMEM_FETCH(FETCH, unsigned int, uint); + TEST_SHMEM_FETCH(FETCH, unsigned long, ulong); + TEST_SHMEM_FETCH(FETCH, unsigned long long, ulonglong); + TEST_SHMEM_FETCH(FETCH, int32_t, int32); + TEST_SHMEM_FETCH(FETCH, int64_t, int64); + TEST_SHMEM_FETCH(FETCH, uint32_t, uint32); + TEST_SHMEM_FETCH(FETCH, uint64_t, uint64); + TEST_SHMEM_FETCH(FETCH, size_t, size); + TEST_SHMEM_FETCH(FETCH, ptrdiff_t, ptrdiff); +#endif /* ENABLE_DEPRECATED_TESTS */ + + TEST_SHMEM_FETCH(ATOMIC_FETCH, float, float); + TEST_SHMEM_FETCH(ATOMIC_FETCH, double, double); + TEST_SHMEM_FETCH(ATOMIC_FETCH, int, int); + TEST_SHMEM_FETCH(ATOMIC_FETCH, long, long); + TEST_SHMEM_FETCH(ATOMIC_FETCH, long long, longlong); + TEST_SHMEM_FETCH(ATOMIC_FETCH, unsigned int, uint); + TEST_SHMEM_FETCH(ATOMIC_FETCH, unsigned long, ulong); + TEST_SHMEM_FETCH(ATOMIC_FETCH, unsigned long long, ulonglong); + TEST_SHMEM_FETCH(ATOMIC_FETCH, int32_t, int32); + TEST_SHMEM_FETCH(ATOMIC_FETCH, int64_t, int64); + TEST_SHMEM_FETCH(ATOMIC_FETCH, uint32_t, uint32); + TEST_SHMEM_FETCH(ATOMIC_FETCH, uint64_t, uint64); + TEST_SHMEM_FETCH(ATOMIC_FETCH, size_t, size); + TEST_SHMEM_FETCH(ATOMIC_FETCH, ptrdiff_t, ptrdiff); + + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, float, float); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, double, double); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, int, int); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, long, long); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, long long, longlong); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, unsigned int, uint); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, unsigned long, ulong); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, unsigned long long, ulonglong); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, int32_t, int32); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, int64_t, int64); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, uint32_t, uint32); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, uint64_t, uint64); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, size_t, size); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_atomic_inc.cpp b/test/unit/cxx_test_shmem_atomic_inc.cpp new file mode 100644 index 000000000..6ecc024ca --- /dev/null +++ b/test/unit/cxx_test_shmem_atomic_inc.cpp @@ -0,0 +1,195 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +enum op { INC = 0, ATOMIC_INC, CTX_ATOMIC_INC, FINC, ATOMIC_FETCH_INC, + CTX_ATOMIC_FETCH_INC }; + +#ifdef ENABLE_DEPRECATED_TESTS +#define DEPRECATED_INC(TYPENAME,...) shmem_##TYPENAME##_inc(__VA_ARGS__) +#define DEPRECATED_FINC(TYPENAME,...) shmem_##TYPENAME##_finc(__VA_ARGS__) +#else +#define DEPRECATED_INC(TYPENAME,...) shmem_##TYPENAME##_atomic_inc(__VA_ARGS__) +#define DEPRECATED_FINC(TYPENAME,...) shmem_##TYPENAME##_atomic_fetch_inc(__VA_ARGS__) +#endif + +#define TEST_SHMEM_INC(OP, TYPE, TYPENAME) \ + do { \ + static TYPE remote = (TYPE)0; \ + TYPE old; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + remote = (TYPE)0; \ + shmem_barrier_all(); \ + for (int i = 0; i < npes; i++) \ + switch (OP) { \ + case INC: \ + DEPRECATED_INC(TYPENAME, &remote, i); \ + break; \ + case ATOMIC_INC: \ + shmem_##TYPENAME##_atomic_inc(&remote, i); \ + break; \ + case CTX_ATOMIC_INC: \ + shmem_ctx_##TYPENAME##_atomic_inc(SHMEM_CTX_DEFAULT, \ + &remote, i); \ + break; \ + case FINC: \ + old = DEPRECATED_FINC(TYPENAME, &remote, i); \ + if (old > (TYPE) npes) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case ATOMIC_FETCH_INC: \ + old = shmem_##TYPENAME##_atomic_fetch_inc(&remote, i); \ + if (old > (TYPE) npes) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_ATOMIC_FETCH_INC: \ + old = shmem_ctx_##TYPENAME##_atomic_fetch_inc( \ + SHMEM_CTX_DEFAULT, &remote, i); \ + if (old > (TYPE) npes) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + default: \ + printf("Invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + shmem_barrier_all(); \ + if (remote != (TYPE)npes) { \ + printf("PE %i observed error with TEST_SHMEM_INC(%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + +#ifdef ENABLE_DEPRECATED_TESTS + TEST_SHMEM_INC(INC, int, int); + TEST_SHMEM_INC(INC, long, long); + TEST_SHMEM_INC(INC, long long, longlong); + TEST_SHMEM_INC(INC, unsigned int, uint); + TEST_SHMEM_INC(INC, unsigned long, ulong); + TEST_SHMEM_INC(INC, unsigned long long, ulonglong); + TEST_SHMEM_INC(INC, int32_t, int32); + TEST_SHMEM_INC(INC, int64_t, int64); + TEST_SHMEM_INC(INC, uint32_t, uint32); + TEST_SHMEM_INC(INC, uint64_t, uint64); + TEST_SHMEM_INC(INC, size_t, size); + TEST_SHMEM_INC(INC, ptrdiff_t, ptrdiff); +#endif /* ENABLE_DEPRECATED_TESTS */ + + TEST_SHMEM_INC(ATOMIC_INC, int, int); + TEST_SHMEM_INC(ATOMIC_INC, long, long); + TEST_SHMEM_INC(ATOMIC_INC, long long, longlong); + TEST_SHMEM_INC(ATOMIC_INC, unsigned int, uint); + TEST_SHMEM_INC(ATOMIC_INC, unsigned long, ulong); + TEST_SHMEM_INC(ATOMIC_INC, unsigned long long, ulonglong); + TEST_SHMEM_INC(ATOMIC_INC, int32_t, int32); + TEST_SHMEM_INC(ATOMIC_INC, int64_t, int64); + TEST_SHMEM_INC(ATOMIC_INC, uint32_t, uint32); + TEST_SHMEM_INC(ATOMIC_INC, uint64_t, uint64); + TEST_SHMEM_INC(ATOMIC_INC, size_t, size); + TEST_SHMEM_INC(ATOMIC_INC, ptrdiff_t, ptrdiff); + + TEST_SHMEM_INC(CTX_ATOMIC_INC, int, int); + TEST_SHMEM_INC(CTX_ATOMIC_INC, long, long); + TEST_SHMEM_INC(CTX_ATOMIC_INC, long long, longlong); + TEST_SHMEM_INC(CTX_ATOMIC_INC, unsigned int, uint); + TEST_SHMEM_INC(CTX_ATOMIC_INC, unsigned long, ulong); + TEST_SHMEM_INC(CTX_ATOMIC_INC, unsigned long long, ulonglong); + TEST_SHMEM_INC(CTX_ATOMIC_INC, int32_t, int32); + TEST_SHMEM_INC(CTX_ATOMIC_INC, int64_t, int64); + TEST_SHMEM_INC(CTX_ATOMIC_INC, uint32_t, uint32); + TEST_SHMEM_INC(CTX_ATOMIC_INC, uint64_t, uint64); + TEST_SHMEM_INC(CTX_ATOMIC_INC, size_t, size); + TEST_SHMEM_INC(CTX_ATOMIC_INC, ptrdiff_t, ptrdiff); + + TEST_SHMEM_INC(FINC, int, int); + TEST_SHMEM_INC(FINC, long, long); + TEST_SHMEM_INC(FINC, long long, longlong); + TEST_SHMEM_INC(FINC, unsigned int, uint); + TEST_SHMEM_INC(FINC, unsigned long, ulong); + TEST_SHMEM_INC(FINC, unsigned long long, ulonglong); + TEST_SHMEM_INC(FINC, int32_t, int32); + TEST_SHMEM_INC(FINC, int64_t, int64); + TEST_SHMEM_INC(FINC, uint32_t, uint32); + TEST_SHMEM_INC(FINC, uint64_t, uint64); + TEST_SHMEM_INC(FINC, size_t, size); + TEST_SHMEM_INC(FINC, ptrdiff_t, ptrdiff); + + TEST_SHMEM_INC(ATOMIC_FETCH_INC, int, int); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, long, long); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, long long, longlong); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, unsigned int, uint); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, unsigned long, ulong); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, unsigned long long, ulonglong); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, int32_t, int32); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, int64_t, int64); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, uint32_t, uint32); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, uint64_t, uint64); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, size_t, size); + TEST_SHMEM_INC(ATOMIC_FETCH_INC, ptrdiff_t, ptrdiff); + + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, int, int); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, long, long); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, long long, longlong); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, unsigned int, uint); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, unsigned long, ulong); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, unsigned long long, ulonglong); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, int32_t, int32); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, int64_t, int64); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, uint32_t, uint32); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, uint64_t, uint64); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, size_t, size); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_atomic_or.cpp b/test/unit/cxx_test_shmem_atomic_or.cpp new file mode 100644 index 000000000..67378caab --- /dev/null +++ b/test/unit/cxx_test_shmem_atomic_or.cpp @@ -0,0 +1,134 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +enum op { OR = 0, CTX_OR, FETCH_OR, CTX_FETCH_OR }; + +/* Initially, remote = 000...b. Each PE performs an atomic OR where the + * PEth bit of the input value is set to 1 and all other bits are set to 0. + * The result has the NPES least significant bits set, 000...111...b. + */ + +#define TEST_SHMEM_OR(OP, TYPE, TYPENAME) \ + do { \ + static TYPE remote = (TYPE)0; \ + TYPE old = (TYPE)0; \ + if ((size_t) npes-1 > sizeof(TYPE)) break; /* Avoid overflow */ \ + for (int i = 0; i < npes; i++) \ + switch (OP) { \ + case OR: \ + shmem_##TYPENAME##_atomic_or(&remote, \ + (TYPE)(1LLU << mype), i); \ + break; \ + case CTX_OR: \ + shmem_ctx_##TYPENAME##_atomic_or(SHMEM_CTX_DEFAULT, &remote, \ + (TYPE)(1LLU << mype), i); \ + break; \ + case FETCH_OR: \ + old = shmem_##TYPENAME##_atomic_fetch_or(&remote, \ + (TYPE)(1LLU << mype), i);\ + if ((old & (TYPE)(1LLU << mype)) != 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_FETCH_OR: \ + old = shmem_ctx_##TYPENAME##_atomic_fetch_or( \ + SHMEM_CTX_DEFAULT, &remote, (TYPE)(1LLU << mype), i); \ + if ((old & (TYPE)(1LLU << mype)) != 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + default: \ + printf("Invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + shmem_barrier_all(); \ + if (remote != (TYPE)((1LLU << npes) - 1LLU)) { \ + printf("PE %i observed error with TEST_SHMEM_OR(%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + + +int main(int argc, char* argv[]) { + shmem_init(); + + const int mype = shmem_my_pe(); + const int npes = shmem_n_pes(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_OR(OR, unsigned int, uint); + TEST_SHMEM_OR(OR, unsigned long, ulong); + TEST_SHMEM_OR(OR, unsigned long long, ulonglong); + TEST_SHMEM_OR(OR, int32_t, int32); + TEST_SHMEM_OR(OR, int64_t, int64); + TEST_SHMEM_OR(OR, uint32_t, uint32); + TEST_SHMEM_OR(OR, uint64_t, uint64); + + TEST_SHMEM_OR(CTX_OR, unsigned int, uint); + TEST_SHMEM_OR(CTX_OR, unsigned long, ulong); + TEST_SHMEM_OR(CTX_OR, unsigned long long, ulonglong); + TEST_SHMEM_OR(CTX_OR, int32_t, int32); + TEST_SHMEM_OR(CTX_OR, int64_t, int64); + TEST_SHMEM_OR(CTX_OR, uint32_t, uint32); + TEST_SHMEM_OR(CTX_OR, uint64_t, uint64); + + TEST_SHMEM_OR(FETCH_OR, unsigned int, uint); + TEST_SHMEM_OR(FETCH_OR, unsigned long, ulong); + TEST_SHMEM_OR(FETCH_OR, unsigned long long, ulonglong); + TEST_SHMEM_OR(FETCH_OR, int32_t, int32); + TEST_SHMEM_OR(FETCH_OR, int64_t, int64); + TEST_SHMEM_OR(FETCH_OR, uint32_t, uint32); + TEST_SHMEM_OR(FETCH_OR, uint64_t, uint64); + + TEST_SHMEM_OR(CTX_FETCH_OR, unsigned int, uint); + TEST_SHMEM_OR(CTX_FETCH_OR, unsigned long, ulong); + TEST_SHMEM_OR(CTX_FETCH_OR, unsigned long long, ulonglong); + TEST_SHMEM_OR(CTX_FETCH_OR, int32_t, int32); + TEST_SHMEM_OR(CTX_FETCH_OR, int64_t, int64); + TEST_SHMEM_OR(CTX_FETCH_OR, uint32_t, uint32); + TEST_SHMEM_OR(CTX_FETCH_OR, uint64_t, uint64); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_atomic_set.cpp b/test/unit/cxx_test_shmem_atomic_set.cpp new file mode 100644 index 000000000..a06ed0265 --- /dev/null +++ b/test/unit/cxx_test_shmem_atomic_set.cpp @@ -0,0 +1,132 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +enum op { SET = 0, ATOMIC_SET, CTX_ATOMIC_SET }; + +#ifdef ENABLE_DEPRECATED_TESTS +#define DEPRECATED_SET(TYPENAME, ...) shmem_##TYPENAME##_set(__VA_ARGS__) +#else +#define DEPRECATED_SET(TYPENAME, ...) shmem_##TYPENAME##_atomic_set(__VA_ARGS__) +#endif + +#define TEST_SHMEM_SET(OP, TYPE, TYPENAME) \ + do { \ + static TYPE remote; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + switch (OP) { \ + case SET: \ + DEPRECATED_SET(TYPENAME, &remote, (TYPE)mype, \ + (mype + 1) % npes); \ + break; \ + case ATOMIC_SET: \ + shmem_##TYPENAME##_atomic_set(&remote, \ + (TYPE)mype, (mype + 1) % npes); \ + break; \ + case CTX_ATOMIC_SET: \ + shmem_ctx_##TYPENAME##_atomic_set(SHMEM_CTX_DEFAULT,\ + &remote, (TYPE)mype, (mype + 1) % npes); \ + break; \ + default: \ + printf("Invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + shmem_barrier_all(); \ + if (remote != (TYPE)((mype + npes - 1) % npes)) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_SET(%s, %s)\n", mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + +#ifdef ENABLE_DEPRECATED_TESTS + TEST_SHMEM_SET(SET, float, float); + TEST_SHMEM_SET(SET, double, double); + TEST_SHMEM_SET(SET, int, int); + TEST_SHMEM_SET(SET, long, long); + TEST_SHMEM_SET(SET, long long, longlong); + TEST_SHMEM_SET(SET, unsigned int, uint); + TEST_SHMEM_SET(SET, unsigned long, ulong); + TEST_SHMEM_SET(SET, unsigned long long, ulonglong); + TEST_SHMEM_SET(SET, int32_t, int32); + TEST_SHMEM_SET(SET, int64_t, int64); + TEST_SHMEM_SET(SET, uint32_t, uint32); + TEST_SHMEM_SET(SET, uint64_t, uint64); + TEST_SHMEM_SET(SET, size_t, size); + TEST_SHMEM_SET(SET, ptrdiff_t, ptrdiff); +#endif /* ENABLE_DEPRECATED_TESTS */ + + TEST_SHMEM_SET(ATOMIC_SET, float, float); + TEST_SHMEM_SET(ATOMIC_SET, double, double); + TEST_SHMEM_SET(ATOMIC_SET, int, int); + TEST_SHMEM_SET(ATOMIC_SET, long, long); + TEST_SHMEM_SET(ATOMIC_SET, long long, longlong); + TEST_SHMEM_SET(ATOMIC_SET, unsigned int, uint); + TEST_SHMEM_SET(ATOMIC_SET, unsigned long, ulong); + TEST_SHMEM_SET(ATOMIC_SET, unsigned long long, ulonglong); + TEST_SHMEM_SET(ATOMIC_SET, int32_t, int32); + TEST_SHMEM_SET(ATOMIC_SET, int64_t, int64); + TEST_SHMEM_SET(ATOMIC_SET, uint32_t, uint32); + TEST_SHMEM_SET(ATOMIC_SET, uint64_t, uint64); + TEST_SHMEM_SET(ATOMIC_SET, size_t, size); + TEST_SHMEM_SET(ATOMIC_SET, ptrdiff_t, ptrdiff); + + TEST_SHMEM_SET(CTX_ATOMIC_SET, float, float); + TEST_SHMEM_SET(CTX_ATOMIC_SET, double, double); + TEST_SHMEM_SET(CTX_ATOMIC_SET, int, int); + TEST_SHMEM_SET(CTX_ATOMIC_SET, long, long); + TEST_SHMEM_SET(CTX_ATOMIC_SET, long long, longlong); + TEST_SHMEM_SET(CTX_ATOMIC_SET, unsigned int, uint); + TEST_SHMEM_SET(CTX_ATOMIC_SET, unsigned long, ulong); + TEST_SHMEM_SET(CTX_ATOMIC_SET, unsigned long long, ulonglong); + TEST_SHMEM_SET(CTX_ATOMIC_SET, int32_t, int32); + TEST_SHMEM_SET(CTX_ATOMIC_SET, int64_t, int64); + TEST_SHMEM_SET(CTX_ATOMIC_SET, uint32_t, uint32); + TEST_SHMEM_SET(CTX_ATOMIC_SET, uint64_t, uint64); + TEST_SHMEM_SET(CTX_ATOMIC_SET, size_t, size); + TEST_SHMEM_SET(CTX_ATOMIC_SET, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_atomic_swap.cpp b/test/unit/cxx_test_shmem_atomic_swap.cpp new file mode 100644 index 000000000..eed854b7f --- /dev/null +++ b/test/unit/cxx_test_shmem_atomic_swap.cpp @@ -0,0 +1,140 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +enum op { SWAP = 0, ATOMIC_SWAP, CTX_ATOMIC_SWAP }; + +#ifdef ENABLE_DEPRECATED_TESTS +#define DEPRECATED_SWAP(TYPENAME, ...) shmem_##TYPENAME##_swap(__VA_ARGS__) +#else +#define DEPRECATED_SWAP(TYPENAME, ...) shmem_##TYPENAME##_atomic_swap(__VA_ARGS__) +#endif + +#define TEST_SHMEM_SWAP(OP, TYPE, TYPENAME) \ + do { \ + static TYPE remote; \ + TYPE old; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + remote = npes; \ + shmem_barrier_all(); \ + switch (OP) { \ + case SWAP: \ + old = DEPRECATED_SWAP(TYPENAME, &remote, (TYPE)mype, \ + (mype + 1) % npes); \ + break; \ + case ATOMIC_SWAP: \ + old = shmem_##TYPENAME##_atomic_swap(&remote, (TYPE)mype, \ + (mype + 1) % npes); \ + break; \ + case CTX_ATOMIC_SWAP: \ + old = shmem_ctx_##TYPENAME##_atomic_swap(SHMEM_CTX_DEFAULT, \ + &remote, (TYPE)mype, (mype + 1) % npes); \ + break; \ + default: \ + printf("invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + shmem_barrier_all(); \ + if (remote != (TYPE)((mype + npes - 1) % npes)) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_SWAP(%s, %s)\n", mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + if (old != (TYPE) npes) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + +#ifdef ENABLE_DEPRECATED_TESTS + TEST_SHMEM_SWAP(SWAP, float, float); + TEST_SHMEM_SWAP(SWAP, double, double); + TEST_SHMEM_SWAP(SWAP, int, int); + TEST_SHMEM_SWAP(SWAP, long, long); + TEST_SHMEM_SWAP(SWAP, long long, longlong); + TEST_SHMEM_SWAP(SWAP, unsigned int, uint); + TEST_SHMEM_SWAP(SWAP, unsigned long, ulong); + TEST_SHMEM_SWAP(SWAP, unsigned long long, ulonglong); + TEST_SHMEM_SWAP(SWAP, int32_t, int32); + TEST_SHMEM_SWAP(SWAP, int64_t, int64); + TEST_SHMEM_SWAP(SWAP, uint32_t, uint32); + TEST_SHMEM_SWAP(SWAP, uint64_t, uint64); + TEST_SHMEM_SWAP(SWAP, size_t, size); + TEST_SHMEM_SWAP(SWAP, ptrdiff_t, ptrdiff); +#endif /* ENABLE_DEPRECATED_TESTS */ + + TEST_SHMEM_SWAP(ATOMIC_SWAP, float, float); + TEST_SHMEM_SWAP(ATOMIC_SWAP, double, double); + TEST_SHMEM_SWAP(ATOMIC_SWAP, int, int); + TEST_SHMEM_SWAP(ATOMIC_SWAP, long, long); + TEST_SHMEM_SWAP(ATOMIC_SWAP, long long, longlong); + TEST_SHMEM_SWAP(ATOMIC_SWAP, unsigned int, uint); + TEST_SHMEM_SWAP(ATOMIC_SWAP, unsigned long, ulong); + TEST_SHMEM_SWAP(ATOMIC_SWAP, unsigned long long, ulonglong); + TEST_SHMEM_SWAP(ATOMIC_SWAP, int32_t, int32); + TEST_SHMEM_SWAP(ATOMIC_SWAP, int64_t, int64); + TEST_SHMEM_SWAP(ATOMIC_SWAP, uint32_t, uint32); + TEST_SHMEM_SWAP(ATOMIC_SWAP, uint64_t, uint64); + TEST_SHMEM_SWAP(ATOMIC_SWAP, size_t, size); + TEST_SHMEM_SWAP(ATOMIC_SWAP, ptrdiff_t, ptrdiff); + + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, float, float); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, double, double); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, int, int); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, long, long); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, long long, longlong); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, unsigned int, uint); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, unsigned long, ulong); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, unsigned long long, ulonglong); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, int32_t, int32); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, int64_t, int64); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, uint32_t, uint32); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, uint64_t, uint64); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, size_t, size); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_atomic_xor.cpp b/test/unit/cxx_test_shmem_atomic_xor.cpp new file mode 100644 index 000000000..029b2f8b4 --- /dev/null +++ b/test/unit/cxx_test_shmem_atomic_xor.cpp @@ -0,0 +1,134 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +enum op { XOR = 0, CTX_XOR, FETCH_XOR, CTX_FETCH_XOR }; + +/* Initially, remote = 111...b. Each PE performs an atomic XOR where the + * PEth bit of the input value is set to 1 and all other bits are set to 0. + * The result has the NPES least significant bits cleared, 111...000...b. + */ + +#define TEST_SHMEM_XOR(OP, TYPE, TYPENAME) \ + do { \ + static TYPE remote = ~(TYPE)0; \ + TYPE old; \ + if ((size_t) npes-1 > sizeof(TYPE)) break; /* Avoid overflow */ \ + for (int i = 0; i < npes; i++) \ + switch (OP) { \ + case XOR: \ + shmem_##TYPENAME##_atomic_xor(&remote, \ + (TYPE)(1LLU << mype), i); \ + break; \ + case CTX_XOR: \ + shmem_ctx_##TYPENAME##_atomic_xor(SHMEM_CTX_DEFAULT, &remote, \ + (TYPE)(1LLU << mype), i); \ + break; \ + case FETCH_XOR: \ + old = shmem_##TYPENAME##_atomic_fetch_xor(&remote, \ + (TYPE)(1LLU << mype), i); \ + if (((old ^ (TYPE)(1LLU << mype)) & (TYPE)(1LLU << mype)) != 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_FETCH_XOR: \ + old = shmem_ctx_##TYPENAME##_atomic_fetch_xor( \ + SHMEM_CTX_DEFAULT, &remote, (TYPE)(1LLU << mype), i); \ + if (((old ^ (TYPE)(1LLU << mype)) & (TYPE)(1LLU << mype)) != 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + default: \ + printf("Invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + shmem_barrier_all(); \ + if (remote != ~(TYPE)((1LLU << npes) - 1LLU)) { \ + printf("PE %i observed error with TEST_SHMEM_XOR(%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + + +int main(int argc, char* argv[]) { + shmem_init(); + + const int mype = shmem_my_pe(); + const int npes = shmem_n_pes(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_XOR(XOR, unsigned int, uint); + TEST_SHMEM_XOR(XOR, unsigned long, ulong); + TEST_SHMEM_XOR(XOR, unsigned long long, ulonglong); + TEST_SHMEM_XOR(XOR, int32_t, int32); + TEST_SHMEM_XOR(XOR, int64_t, int64); + TEST_SHMEM_XOR(XOR, uint32_t, uint32); + TEST_SHMEM_XOR(XOR, uint64_t, uint64); + + TEST_SHMEM_XOR(CTX_XOR, unsigned int, uint); + TEST_SHMEM_XOR(CTX_XOR, unsigned long, ulong); + TEST_SHMEM_XOR(CTX_XOR, unsigned long long, ulonglong); + TEST_SHMEM_XOR(CTX_XOR, int32_t, int32); + TEST_SHMEM_XOR(CTX_XOR, int64_t, int64); + TEST_SHMEM_XOR(CTX_XOR, uint32_t, uint32); + TEST_SHMEM_XOR(CTX_XOR, uint64_t, uint64); + + TEST_SHMEM_XOR(FETCH_XOR, unsigned int, uint); + TEST_SHMEM_XOR(FETCH_XOR, unsigned long, ulong); + TEST_SHMEM_XOR(FETCH_XOR, unsigned long long, ulonglong); + TEST_SHMEM_XOR(FETCH_XOR, int32_t, int32); + TEST_SHMEM_XOR(FETCH_XOR, int64_t, int64); + TEST_SHMEM_XOR(FETCH_XOR, uint32_t, uint32); + TEST_SHMEM_XOR(FETCH_XOR, uint64_t, uint64); + + TEST_SHMEM_XOR(CTX_FETCH_XOR, unsigned int, uint); + TEST_SHMEM_XOR(CTX_FETCH_XOR, unsigned long, ulong); + TEST_SHMEM_XOR(CTX_FETCH_XOR, unsigned long long, ulonglong); + TEST_SHMEM_XOR(CTX_FETCH_XOR, int32_t, int32); + TEST_SHMEM_XOR(CTX_FETCH_XOR, int64_t, int64); + TEST_SHMEM_XOR(CTX_FETCH_XOR, uint32_t, uint32); + TEST_SHMEM_XOR(CTX_FETCH_XOR, uint64_t, uint64); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_g.cpp b/test/unit/cxx_test_shmem_g.cpp new file mode 100644 index 000000000..0ce30716a --- /dev/null +++ b/test/unit/cxx_test_shmem_g.cpp @@ -0,0 +1,117 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#define TEST_SHMEM_G(USE_CTX, TYPE, TYPENAME) \ + do { \ + static TYPE remote; \ + TYPE val; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + remote = (TYPE)mype; \ + shmem_barrier_all(); \ + if (USE_CTX) \ + val = shmem_ctx_##TYPENAME##_g( \ + SHMEM_CTX_DEFAULT, &remote, (mype + 1) % npes); \ + else \ + val = shmem_##TYPENAME##_g(&remote, \ + (mype + 1) % npes); \ + if (val != (TYPE)((mype + 1) % npes)) { \ + printf("PE %i received incorrect value with" \ + "TEST_SHMEM_G(%d, %s)\n", mype, \ + (int)(USE_CTX), #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_G(0, float, float); + TEST_SHMEM_G(0, double, double); + TEST_SHMEM_G(0, long double, longdouble); + TEST_SHMEM_G(0, char, char); + TEST_SHMEM_G(0, signed char, schar); + TEST_SHMEM_G(0, short, short); + TEST_SHMEM_G(0, int, int); + TEST_SHMEM_G(0, long, long); + TEST_SHMEM_G(0, long long, longlong); + TEST_SHMEM_G(0, unsigned char, uchar); + TEST_SHMEM_G(0, unsigned short, ushort); + TEST_SHMEM_G(0, unsigned int, uint); + TEST_SHMEM_G(0, unsigned long, ulong); + TEST_SHMEM_G(0, unsigned long long, ulonglong); + TEST_SHMEM_G(0, int8_t, int8); + TEST_SHMEM_G(0, int16_t, int16); + TEST_SHMEM_G(0, int32_t, int32); + TEST_SHMEM_G(0, int64_t, int64); + TEST_SHMEM_G(0, uint8_t, uint8); + TEST_SHMEM_G(0, uint16_t, uint16); + TEST_SHMEM_G(0, uint32_t, uint32); + TEST_SHMEM_G(0, uint64_t, uint64); + TEST_SHMEM_G(0, size_t, size); + TEST_SHMEM_G(0, ptrdiff_t, ptrdiff); + + TEST_SHMEM_G(1, float, float); + TEST_SHMEM_G(1, double, double); + TEST_SHMEM_G(1, long double, longdouble); + TEST_SHMEM_G(1, char, char); + TEST_SHMEM_G(1, signed char, schar); + TEST_SHMEM_G(1, short, short); + TEST_SHMEM_G(1, int, int); + TEST_SHMEM_G(1, long, long); + TEST_SHMEM_G(1, long long, longlong); + TEST_SHMEM_G(1, unsigned char, uchar); + TEST_SHMEM_G(1, unsigned short, ushort); + TEST_SHMEM_G(1, unsigned int, uint); + TEST_SHMEM_G(1, unsigned long, ulong); + TEST_SHMEM_G(1, unsigned long long, ulonglong); + TEST_SHMEM_G(1, int8_t, int8); + TEST_SHMEM_G(1, int16_t, int16); + TEST_SHMEM_G(1, int32_t, int32); + TEST_SHMEM_G(1, int64_t, int64); + TEST_SHMEM_G(1, uint8_t, uint8); + TEST_SHMEM_G(1, uint16_t, uint16); + TEST_SHMEM_G(1, uint32_t, uint32); + TEST_SHMEM_G(1, uint64_t, uint64); + TEST_SHMEM_G(1, size_t, size); + TEST_SHMEM_G(1, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_get.cpp b/test/unit/cxx_test_shmem_get.cpp new file mode 100644 index 000000000..d37762d43 --- /dev/null +++ b/test/unit/cxx_test_shmem_get.cpp @@ -0,0 +1,246 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +enum op { GET = 0, IGET, GET_NBI }; + +#define TEST_SHMEM_GET(OP, USE_CTX, TYPE, TYPENAME) \ + do { \ + static TYPE remote[10]; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + TYPE local[10]; \ + for (int i = 0; i < 10; i++) \ + remote[i] = (TYPE)mype; \ + shmem_barrier_all(); \ + switch (OP) { \ + case GET: \ + if (USE_CTX) \ + shmem_ctx_##TYPENAME##_get(SHMEM_CTX_DEFAULT, local, \ + remote, 10, (mype + 1) % npes); \ + else \ + shmem_##TYPENAME##_get(local, remote, 10, \ + (mype + 1) % npes); \ + break; \ + case IGET: \ + if (USE_CTX) \ + shmem_ctx_##TYPENAME##_iget(SHMEM_CTX_DEFAULT, local, \ + remote, 1, 1, 10, (mype + 1) % npes); \ + else \ + shmem_##TYPENAME##_iget(local, remote, 1, 1, 10, \ + (mype + 1) % npes); \ + break; \ + case GET_NBI: \ + if (USE_CTX) \ + shmem_ctx_##TYPENAME##_get_nbi(SHMEM_CTX_DEFAULT, \ + local, remote, 10, (mype + 1) % npes); \ + else \ + shmem_##TYPENAME##_get_nbi(local, remote, 10, \ + (mype + 1) % npes); \ + shmem_quiet(); \ + break; \ + default: \ + printf("Invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + for (int i = 0; i < 10; i++) \ + if (local[i] != (TYPE)((mype + 1) % npes)) { \ + printf("PE %i received incorrect value with" \ + "TEST_SHMEM_GET(%s, %d, %s)\n", mype, #OP, \ + (int)(USE_CTX), #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + + TEST_SHMEM_GET(GET, 0, float, float); + TEST_SHMEM_GET(GET, 0, double, double); + TEST_SHMEM_GET(GET, 0, long double, longdouble); + TEST_SHMEM_GET(GET, 0, char, char); + TEST_SHMEM_GET(GET, 0, signed char, schar); + TEST_SHMEM_GET(GET, 0, short, short); + TEST_SHMEM_GET(GET, 0, int, int); + TEST_SHMEM_GET(GET, 0, long, long); + TEST_SHMEM_GET(GET, 0, long long, longlong); + TEST_SHMEM_GET(GET, 0, unsigned char, uchar); + TEST_SHMEM_GET(GET, 0, unsigned short, ushort); + TEST_SHMEM_GET(GET, 0, unsigned int, uint); + TEST_SHMEM_GET(GET, 0, unsigned long, ulong); + TEST_SHMEM_GET(GET, 0, unsigned long long, ulonglong); + TEST_SHMEM_GET(GET, 0, int8_t, int8); + TEST_SHMEM_GET(GET, 0, int16_t, int16); + TEST_SHMEM_GET(GET, 0, int32_t, int32); + TEST_SHMEM_GET(GET, 0, int64_t, int64); + TEST_SHMEM_GET(GET, 0, uint8_t, uint8); + TEST_SHMEM_GET(GET, 0, uint16_t, uint16); + TEST_SHMEM_GET(GET, 0, uint32_t, uint32); + TEST_SHMEM_GET(GET, 0, uint64_t, uint64); + TEST_SHMEM_GET(GET, 0, size_t, size); + TEST_SHMEM_GET(GET, 0, ptrdiff_t, ptrdiff); + + TEST_SHMEM_GET(GET, 1, float, float); + TEST_SHMEM_GET(GET, 1, double, double); + TEST_SHMEM_GET(GET, 1, long double, longdouble); + TEST_SHMEM_GET(GET, 1, char, char); + TEST_SHMEM_GET(GET, 1, signed char, schar); + TEST_SHMEM_GET(GET, 1, short, short); + TEST_SHMEM_GET(GET, 1, int, int); + TEST_SHMEM_GET(GET, 1, long, long); + TEST_SHMEM_GET(GET, 1, long long, longlong); + TEST_SHMEM_GET(GET, 1, unsigned char, uchar); + TEST_SHMEM_GET(GET, 1, unsigned short, ushort); + TEST_SHMEM_GET(GET, 1, unsigned int, uint); + TEST_SHMEM_GET(GET, 1, unsigned long, ulong); + TEST_SHMEM_GET(GET, 1, unsigned long long, ulonglong); + TEST_SHMEM_GET(GET, 1, int8_t, int8); + TEST_SHMEM_GET(GET, 1, int16_t, int16); + TEST_SHMEM_GET(GET, 1, int32_t, int32); + TEST_SHMEM_GET(GET, 1, int64_t, int64); + TEST_SHMEM_GET(GET, 1, uint8_t, uint8); + TEST_SHMEM_GET(GET, 1, uint16_t, uint16); + TEST_SHMEM_GET(GET, 1, uint32_t, uint32); + TEST_SHMEM_GET(GET, 1, uint64_t, uint64); + TEST_SHMEM_GET(GET, 1, size_t, size); + TEST_SHMEM_GET(GET, 1, ptrdiff_t, ptrdiff); + + TEST_SHMEM_GET(IGET, 0, float, float); + TEST_SHMEM_GET(IGET, 0, double, double); + TEST_SHMEM_GET(IGET, 0, long double, longdouble); + TEST_SHMEM_GET(IGET, 0, char, char); + TEST_SHMEM_GET(IGET, 0, signed char, schar); + TEST_SHMEM_GET(IGET, 0, short, short); + TEST_SHMEM_GET(IGET, 0, int, int); + TEST_SHMEM_GET(IGET, 0, long, long); + TEST_SHMEM_GET(IGET, 0, long long, longlong); + TEST_SHMEM_GET(IGET, 0, unsigned char, uchar); + TEST_SHMEM_GET(IGET, 0, unsigned short, ushort); + TEST_SHMEM_GET(IGET, 0, unsigned int, uint); + TEST_SHMEM_GET(IGET, 0, unsigned long, ulong); + TEST_SHMEM_GET(IGET, 0, unsigned long long, ulonglong); + TEST_SHMEM_GET(IGET, 0, int8_t, int8); + TEST_SHMEM_GET(IGET, 0, int16_t, int16); + TEST_SHMEM_GET(IGET, 0, int32_t, int32); + TEST_SHMEM_GET(IGET, 0, int64_t, int64); + TEST_SHMEM_GET(IGET, 0, uint8_t, uint8); + TEST_SHMEM_GET(IGET, 0, uint16_t, uint16); + TEST_SHMEM_GET(IGET, 0, uint32_t, uint32); + TEST_SHMEM_GET(IGET, 0, uint64_t, uint64); + TEST_SHMEM_GET(IGET, 0, size_t, size); + TEST_SHMEM_GET(IGET, 0, ptrdiff_t, ptrdiff); + + TEST_SHMEM_GET(IGET, 1, float, float); + TEST_SHMEM_GET(IGET, 1, double, double); + TEST_SHMEM_GET(IGET, 1, long double, longdouble); + TEST_SHMEM_GET(IGET, 1, char, char); + TEST_SHMEM_GET(IGET, 1, signed char, schar); + TEST_SHMEM_GET(IGET, 1, short, short); + TEST_SHMEM_GET(IGET, 1, int, int); + TEST_SHMEM_GET(IGET, 1, long, long); + TEST_SHMEM_GET(IGET, 1, long long, longlong); + TEST_SHMEM_GET(IGET, 1, unsigned char, uchar); + TEST_SHMEM_GET(IGET, 1, unsigned short, ushort); + TEST_SHMEM_GET(IGET, 1, unsigned int, uint); + TEST_SHMEM_GET(IGET, 1, unsigned long, ulong); + TEST_SHMEM_GET(IGET, 1, unsigned long long, ulonglong); + TEST_SHMEM_GET(IGET, 1, int8_t, int8); + TEST_SHMEM_GET(IGET, 1, int16_t, int16); + TEST_SHMEM_GET(IGET, 1, int32_t, int32); + TEST_SHMEM_GET(IGET, 1, int64_t, int64); + TEST_SHMEM_GET(IGET, 1, uint8_t, uint8); + TEST_SHMEM_GET(IGET, 1, uint16_t, uint16); + TEST_SHMEM_GET(IGET, 1, uint32_t, uint32); + TEST_SHMEM_GET(IGET, 1, uint64_t, uint64); + TEST_SHMEM_GET(IGET, 1, size_t, size); + TEST_SHMEM_GET(IGET, 1, ptrdiff_t, ptrdiff); + + TEST_SHMEM_GET(GET_NBI, 0, float, float); + TEST_SHMEM_GET(GET_NBI, 0, double, double); + TEST_SHMEM_GET(GET_NBI, 0, long double, longdouble); + TEST_SHMEM_GET(GET_NBI, 0, char, char); + TEST_SHMEM_GET(GET_NBI, 0, signed char, schar); + TEST_SHMEM_GET(GET_NBI, 0, short, short); + TEST_SHMEM_GET(GET_NBI, 0, int, int); + TEST_SHMEM_GET(GET_NBI, 0, long, long); + TEST_SHMEM_GET(GET_NBI, 0, long long, longlong); + TEST_SHMEM_GET(GET_NBI, 0, unsigned char, uchar); + TEST_SHMEM_GET(GET_NBI, 0, unsigned short, ushort); + TEST_SHMEM_GET(GET_NBI, 0, unsigned int, uint); + TEST_SHMEM_GET(GET_NBI, 0, unsigned long, ulong); + TEST_SHMEM_GET(GET_NBI, 0, unsigned long long, ulonglong); + TEST_SHMEM_GET(GET_NBI, 0, int8_t, int8); + TEST_SHMEM_GET(GET_NBI, 0, int16_t, int16); + TEST_SHMEM_GET(GET_NBI, 0, int32_t, int32); + TEST_SHMEM_GET(GET_NBI, 0, int64_t, int64); + TEST_SHMEM_GET(GET_NBI, 0, uint8_t, uint8); + TEST_SHMEM_GET(GET_NBI, 0, uint16_t, uint16); + TEST_SHMEM_GET(GET_NBI, 0, uint32_t, uint32); + TEST_SHMEM_GET(GET_NBI, 0, uint64_t, uint64); + TEST_SHMEM_GET(GET_NBI, 0, size_t, size); + TEST_SHMEM_GET(GET_NBI, 0, ptrdiff_t, ptrdiff); + + TEST_SHMEM_GET(GET_NBI, 1, float, float); + TEST_SHMEM_GET(GET_NBI, 1, double, double); + TEST_SHMEM_GET(GET_NBI, 1, long double, longdouble); + TEST_SHMEM_GET(GET_NBI, 1, char, char); + TEST_SHMEM_GET(GET_NBI, 1, signed char, schar); + TEST_SHMEM_GET(GET_NBI, 1, short, short); + TEST_SHMEM_GET(GET_NBI, 1, int, int); + TEST_SHMEM_GET(GET_NBI, 1, long, long); + TEST_SHMEM_GET(GET_NBI, 1, long long, longlong); + TEST_SHMEM_GET(GET_NBI, 1, unsigned char, uchar); + TEST_SHMEM_GET(GET_NBI, 1, unsigned short, ushort); + TEST_SHMEM_GET(GET_NBI, 1, unsigned int, uint); + TEST_SHMEM_GET(GET_NBI, 1, unsigned long, ulong); + TEST_SHMEM_GET(GET_NBI, 1, unsigned long long, ulonglong); + TEST_SHMEM_GET(GET_NBI, 1, int8_t, int8); + TEST_SHMEM_GET(GET_NBI, 1, int16_t, int16); + TEST_SHMEM_GET(GET_NBI, 1, int32_t, int32); + TEST_SHMEM_GET(GET_NBI, 1, int64_t, int64); + TEST_SHMEM_GET(GET_NBI, 1, uint8_t, uint8); + TEST_SHMEM_GET(GET_NBI, 1, uint16_t, uint16); + TEST_SHMEM_GET(GET_NBI, 1, uint32_t, uint32); + TEST_SHMEM_GET(GET_NBI, 1, uint64_t, uint64); + TEST_SHMEM_GET(GET_NBI, 1, size_t, size); + TEST_SHMEM_GET(GET_NBI, 1, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_p.cpp b/test/unit/cxx_test_shmem_p.cpp new file mode 100644 index 000000000..d51a29ab7 --- /dev/null +++ b/test/unit/cxx_test_shmem_p.cpp @@ -0,0 +1,115 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#define TEST_SHMEM_P(USE_CTX, TYPE, TYPENAME) \ + do { \ + static TYPE remote; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + if (USE_CTX) \ + shmem_ctx_##TYPENAME##_p(SHMEM_CTX_DEFAULT, \ + &remote, (TYPE)mype, (mype + 1) % npes); \ + else \ + shmem_##TYPENAME##_p(&remote, (TYPE)mype, \ + (mype + 1) % npes);\ + shmem_barrier_all(); \ + if (remote != (TYPE)((mype + npes - 1) % npes)) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_P(%d, %s)\n", mype, \ + (int)(USE_CTX), #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_P(0, float, float); + TEST_SHMEM_P(0, double, double); + TEST_SHMEM_P(0, long double, longdouble); + TEST_SHMEM_P(0, char, char); + TEST_SHMEM_P(0, signed char, schar); + TEST_SHMEM_P(0, short, short); + TEST_SHMEM_P(0, int, int); + TEST_SHMEM_P(0, long, long); + TEST_SHMEM_P(0, long long, longlong); + TEST_SHMEM_P(0, unsigned char, uchar); + TEST_SHMEM_P(0, unsigned short, ushort); + TEST_SHMEM_P(0, unsigned int, uint); + TEST_SHMEM_P(0, unsigned long, ulong); + TEST_SHMEM_P(0, unsigned long long, ulonglong); + TEST_SHMEM_P(0, int8_t, int8); + TEST_SHMEM_P(0, int16_t, int16); + TEST_SHMEM_P(0, int32_t, int32); + TEST_SHMEM_P(0, int64_t, int64); + TEST_SHMEM_P(0, uint8_t, uint8); + TEST_SHMEM_P(0, uint16_t, uint16); + TEST_SHMEM_P(0, uint32_t, uint32); + TEST_SHMEM_P(0, uint64_t, uint64); + TEST_SHMEM_P(0, size_t, size); + TEST_SHMEM_P(0, ptrdiff_t, ptrdiff); + + TEST_SHMEM_P(1, float, float); + TEST_SHMEM_P(1, double, double); + TEST_SHMEM_P(1, long double, longdouble); + TEST_SHMEM_P(1, char, char); + TEST_SHMEM_P(1, signed char, schar); + TEST_SHMEM_P(1, short, short); + TEST_SHMEM_P(1, int, int); + TEST_SHMEM_P(1, long, long); + TEST_SHMEM_P(1, long long, longlong); + TEST_SHMEM_P(1, unsigned char, uchar); + TEST_SHMEM_P(1, unsigned short, ushort); + TEST_SHMEM_P(1, unsigned int, uint); + TEST_SHMEM_P(1, unsigned long, ulong); + TEST_SHMEM_P(1, unsigned long long, ulonglong); + TEST_SHMEM_P(1, int8_t, int8); + TEST_SHMEM_P(1, int16_t, int16); + TEST_SHMEM_P(1, int32_t, int32); + TEST_SHMEM_P(1, int64_t, int64); + TEST_SHMEM_P(1, uint8_t, uint8); + TEST_SHMEM_P(1, uint16_t, uint16); + TEST_SHMEM_P(1, uint32_t, uint32); + TEST_SHMEM_P(1, uint64_t, uint64); + TEST_SHMEM_P(1, size_t, size); + TEST_SHMEM_P(1, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_put.cpp b/test/unit/cxx_test_shmem_put.cpp new file mode 100644 index 000000000..ce716544d --- /dev/null +++ b/test/unit/cxx_test_shmem_put.cpp @@ -0,0 +1,245 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +enum op { PUT = 0, IPUT, PUT_NBI }; + +#define TEST_SHMEM_PUT(OP, USE_CTX, TYPE, TYPENAME) \ + do { \ + static TYPE remote[10]; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + TYPE local[10]; \ + for (int i = 0; i < 10; i++) \ + local[i] = (TYPE)mype; \ + switch (OP) { \ + case PUT: \ + if (USE_CTX) \ + shmem_ctx_##TYPENAME##_put(SHMEM_CTX_DEFAULT, remote, \ + local, 10, (mype + 1) % npes); \ + else \ + shmem_##TYPENAME##_put(remote, local, 10, \ + (mype + 1) % npes); \ + break; \ + case IPUT: \ + if (USE_CTX) \ + shmem_ctx_##TYPENAME##_iput(SHMEM_CTX_DEFAULT, remote,\ + local, 1, 1, 10, (mype + 1) % npes); \ + else \ + shmem_##TYPENAME##_iput(remote, local, 1, 1, 10, \ + (mype + 1) % npes); \ + break; \ + case PUT_NBI: \ + if (USE_CTX) \ + shmem_ctx_##TYPENAME##_put_nbi(SHMEM_CTX_DEFAULT, \ + remote, local, 10, (mype + 1) % npes); \ + else \ + shmem_##TYPENAME##_put_nbi(remote, local, 10, \ + (mype + 1) % npes); \ + shmem_quiet(); \ + break; \ + default: \ + printf("Invalid operation (%d)\n", OP); \ + shmem_global_exit(1); \ + } \ + shmem_barrier_all(); \ + for (int i = 0; i < 10; i++) \ + if (remote[i] != (TYPE)((mype + npes - 1) % npes)) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_PUT(%s, %d, %s)\n", mype, \ + #OP, (int)(USE_CTX), #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_PUT(PUT, 0, float, float); + TEST_SHMEM_PUT(PUT, 0, double, double); + TEST_SHMEM_PUT(PUT, 0, long double, longdouble); + TEST_SHMEM_PUT(PUT, 0, char, char); + TEST_SHMEM_PUT(PUT, 0, signed char, schar); + TEST_SHMEM_PUT(PUT, 0, short, short); + TEST_SHMEM_PUT(PUT, 0, int, int); + TEST_SHMEM_PUT(PUT, 0, long, long); + TEST_SHMEM_PUT(PUT, 0, long long, longlong); + TEST_SHMEM_PUT(PUT, 0, unsigned char, uchar); + TEST_SHMEM_PUT(PUT, 0, unsigned short, ushort); + TEST_SHMEM_PUT(PUT, 0, unsigned int, uint); + TEST_SHMEM_PUT(PUT, 0, unsigned long, ulong); + TEST_SHMEM_PUT(PUT, 0, unsigned long long, ulonglong); + TEST_SHMEM_PUT(PUT, 0, int8_t, int8); + TEST_SHMEM_PUT(PUT, 0, int16_t, int16); + TEST_SHMEM_PUT(PUT, 0, int32_t, int32); + TEST_SHMEM_PUT(PUT, 0, int64_t, int64); + TEST_SHMEM_PUT(PUT, 0, uint8_t, uint8); + TEST_SHMEM_PUT(PUT, 0, uint16_t, uint16); + TEST_SHMEM_PUT(PUT, 0, uint32_t, uint32); + TEST_SHMEM_PUT(PUT, 0, uint64_t, uint64); + TEST_SHMEM_PUT(PUT, 0, size_t, size); + TEST_SHMEM_PUT(PUT, 0, ptrdiff_t, ptrdiff); + + TEST_SHMEM_PUT(PUT, 1, float, float); + TEST_SHMEM_PUT(PUT, 1, double, double); + TEST_SHMEM_PUT(PUT, 1, long double, longdouble); + TEST_SHMEM_PUT(PUT, 1, char, char); + TEST_SHMEM_PUT(PUT, 1, signed char, schar); + TEST_SHMEM_PUT(PUT, 1, short, short); + TEST_SHMEM_PUT(PUT, 1, int, int); + TEST_SHMEM_PUT(PUT, 1, long, long); + TEST_SHMEM_PUT(PUT, 1, long long, longlong); + TEST_SHMEM_PUT(PUT, 1, unsigned char, uchar); + TEST_SHMEM_PUT(PUT, 1, unsigned short, ushort); + TEST_SHMEM_PUT(PUT, 1, unsigned int, uint); + TEST_SHMEM_PUT(PUT, 1, unsigned long, ulong); + TEST_SHMEM_PUT(PUT, 1, unsigned long long, ulonglong); + TEST_SHMEM_PUT(PUT, 1, int8_t, int8); + TEST_SHMEM_PUT(PUT, 1, int16_t, int16); + TEST_SHMEM_PUT(PUT, 1, int32_t, int32); + TEST_SHMEM_PUT(PUT, 1, int64_t, int64); + TEST_SHMEM_PUT(PUT, 1, uint8_t, uint8); + TEST_SHMEM_PUT(PUT, 1, uint16_t, uint16); + TEST_SHMEM_PUT(PUT, 1, uint32_t, uint32); + TEST_SHMEM_PUT(PUT, 1, uint64_t, uint64); + TEST_SHMEM_PUT(PUT, 1, size_t, size); + TEST_SHMEM_PUT(PUT, 1, ptrdiff_t, ptrdiff); + + TEST_SHMEM_PUT(IPUT, 0, float, float); + TEST_SHMEM_PUT(IPUT, 0, double, double); + TEST_SHMEM_PUT(IPUT, 0, long double, longdouble); + TEST_SHMEM_PUT(IPUT, 0, char, char); + TEST_SHMEM_PUT(IPUT, 0, signed char, schar); + TEST_SHMEM_PUT(IPUT, 0, short, short); + TEST_SHMEM_PUT(IPUT, 0, int, int); + TEST_SHMEM_PUT(IPUT, 0, long, long); + TEST_SHMEM_PUT(IPUT, 0, long long, longlong); + TEST_SHMEM_PUT(IPUT, 0, unsigned char, uchar); + TEST_SHMEM_PUT(IPUT, 0, unsigned short, ushort); + TEST_SHMEM_PUT(IPUT, 0, unsigned int, uint); + TEST_SHMEM_PUT(IPUT, 0, unsigned long, ulong); + TEST_SHMEM_PUT(IPUT, 0, unsigned long long, ulonglong); + TEST_SHMEM_PUT(IPUT, 0, int8_t, int8); + TEST_SHMEM_PUT(IPUT, 0, int16_t, int16); + TEST_SHMEM_PUT(IPUT, 0, int32_t, int32); + TEST_SHMEM_PUT(IPUT, 0, int64_t, int64); + TEST_SHMEM_PUT(IPUT, 0, uint8_t, uint8); + TEST_SHMEM_PUT(IPUT, 0, uint16_t, uint16); + TEST_SHMEM_PUT(IPUT, 0, uint32_t, uint32); + TEST_SHMEM_PUT(IPUT, 0, uint64_t, uint64); + TEST_SHMEM_PUT(IPUT, 0, size_t, size); + TEST_SHMEM_PUT(IPUT, 0, ptrdiff_t, ptrdiff); + + TEST_SHMEM_PUT(IPUT, 1, float, float); + TEST_SHMEM_PUT(IPUT, 1, double, double); + TEST_SHMEM_PUT(IPUT, 1, long double, longdouble); + TEST_SHMEM_PUT(IPUT, 1, char, char); + TEST_SHMEM_PUT(IPUT, 1, signed char, schar); + TEST_SHMEM_PUT(IPUT, 1, short, short); + TEST_SHMEM_PUT(IPUT, 1, int, int); + TEST_SHMEM_PUT(IPUT, 1, long, long); + TEST_SHMEM_PUT(IPUT, 1, long long, longlong); + TEST_SHMEM_PUT(IPUT, 1, unsigned char, uchar); + TEST_SHMEM_PUT(IPUT, 1, unsigned short, ushort); + TEST_SHMEM_PUT(IPUT, 1, unsigned int, uint); + TEST_SHMEM_PUT(IPUT, 1, unsigned long, ulong); + TEST_SHMEM_PUT(IPUT, 1, unsigned long long, ulonglong); + TEST_SHMEM_PUT(IPUT, 1, int8_t, int8); + TEST_SHMEM_PUT(IPUT, 1, int16_t, int16); + TEST_SHMEM_PUT(IPUT, 1, int32_t, int32); + TEST_SHMEM_PUT(IPUT, 1, int64_t, int64); + TEST_SHMEM_PUT(IPUT, 1, uint8_t, uint8); + TEST_SHMEM_PUT(IPUT, 1, uint16_t, uint16); + TEST_SHMEM_PUT(IPUT, 1, uint32_t, uint32); + TEST_SHMEM_PUT(IPUT, 1, uint64_t, uint64); + TEST_SHMEM_PUT(IPUT, 1, size_t, size); + TEST_SHMEM_PUT(IPUT, 1, ptrdiff_t, ptrdiff); + + TEST_SHMEM_PUT(PUT_NBI, 0, float, float); + TEST_SHMEM_PUT(PUT_NBI, 0, double, double); + TEST_SHMEM_PUT(PUT_NBI, 0, long double, longdouble); + TEST_SHMEM_PUT(PUT_NBI, 0, char, char); + TEST_SHMEM_PUT(PUT_NBI, 0, signed char, schar); + TEST_SHMEM_PUT(PUT_NBI, 0, short, short); + TEST_SHMEM_PUT(PUT_NBI, 0, int, int); + TEST_SHMEM_PUT(PUT_NBI, 0, long, long); + TEST_SHMEM_PUT(PUT_NBI, 0, long long, longlong); + TEST_SHMEM_PUT(PUT_NBI, 0, unsigned char, uchar); + TEST_SHMEM_PUT(PUT_NBI, 0, unsigned short, ushort); + TEST_SHMEM_PUT(PUT_NBI, 0, unsigned int, uint); + TEST_SHMEM_PUT(PUT_NBI, 0, unsigned long, ulong); + TEST_SHMEM_PUT(PUT_NBI, 0, unsigned long long, ulonglong); + TEST_SHMEM_PUT(PUT_NBI, 0, int8_t, int8); + TEST_SHMEM_PUT(PUT_NBI, 0, int16_t, int16); + TEST_SHMEM_PUT(PUT_NBI, 0, int32_t, int32); + TEST_SHMEM_PUT(PUT_NBI, 0, int64_t, int64); + TEST_SHMEM_PUT(PUT_NBI, 0, uint8_t, uint8); + TEST_SHMEM_PUT(PUT_NBI, 0, uint16_t, uint16); + TEST_SHMEM_PUT(PUT_NBI, 0, uint32_t, uint32); + TEST_SHMEM_PUT(PUT_NBI, 0, uint64_t, uint64); + TEST_SHMEM_PUT(PUT_NBI, 0, size_t, size); + TEST_SHMEM_PUT(PUT_NBI, 0, ptrdiff_t, ptrdiff); + + TEST_SHMEM_PUT(PUT_NBI, 1, float, float); + TEST_SHMEM_PUT(PUT_NBI, 1, double, double); + TEST_SHMEM_PUT(PUT_NBI, 1, long double, longdouble); + TEST_SHMEM_PUT(PUT_NBI, 1, char, char); + TEST_SHMEM_PUT(PUT_NBI, 1, signed char, schar); + TEST_SHMEM_PUT(PUT_NBI, 1, short, short); + TEST_SHMEM_PUT(PUT_NBI, 1, int, int); + TEST_SHMEM_PUT(PUT_NBI, 1, long, long); + TEST_SHMEM_PUT(PUT_NBI, 1, long long, longlong); + TEST_SHMEM_PUT(PUT_NBI, 1, unsigned char, uchar); + TEST_SHMEM_PUT(PUT_NBI, 1, unsigned short, ushort); + TEST_SHMEM_PUT(PUT_NBI, 1, unsigned int, uint); + TEST_SHMEM_PUT(PUT_NBI, 1, unsigned long, ulong); + TEST_SHMEM_PUT(PUT_NBI, 1, unsigned long long, ulonglong); + TEST_SHMEM_PUT(PUT_NBI, 1, int8_t, int8); + TEST_SHMEM_PUT(PUT_NBI, 1, int16_t, int16); + TEST_SHMEM_PUT(PUT_NBI, 1, int32_t, int32); + TEST_SHMEM_PUT(PUT_NBI, 1, int64_t, int64); + TEST_SHMEM_PUT(PUT_NBI, 1, uint8_t, uint8); + TEST_SHMEM_PUT(PUT_NBI, 1, uint16_t, uint16); + TEST_SHMEM_PUT(PUT_NBI, 1, uint32_t, uint32); + TEST_SHMEM_PUT(PUT_NBI, 1, uint64_t, uint64); + TEST_SHMEM_PUT(PUT_NBI, 1, size_t, size); + TEST_SHMEM_PUT(PUT_NBI, 1, ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_test.cpp b/test/unit/cxx_test_shmem_test.cpp new file mode 100644 index 000000000..b424ed7db --- /dev/null +++ b/test/unit/cxx_test_shmem_test.cpp @@ -0,0 +1,76 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#define TEST_SHMEM_TEST(TYPE, TYPENAME) \ + do { \ + static TYPE remote = 0; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + shmem_##TYPENAME##_p(&remote, (TYPE)mype+1, \ + (mype + 1) % npes); \ + while (!shmem_##TYPENAME##_test(&remote, \ + SHMEM_CMP_NE, 0)) ; \ + if (remote != (TYPE)((mype + npes - 1) % npes)+1) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_TEST(%s)\n", mype, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_TEST(short, short); + TEST_SHMEM_TEST(int, int); + TEST_SHMEM_TEST(long, long); + TEST_SHMEM_TEST(long long, longlong); + TEST_SHMEM_TEST(unsigned short, ushort); + TEST_SHMEM_TEST(unsigned int, uint); + TEST_SHMEM_TEST(unsigned long, ulong); + TEST_SHMEM_TEST(unsigned long long, ulonglong); + TEST_SHMEM_TEST(int32_t, int32); + TEST_SHMEM_TEST(int64_t, int64); + TEST_SHMEM_TEST(uint32_t, uint32); + TEST_SHMEM_TEST(uint64_t, uint64); + TEST_SHMEM_TEST(size_t, size); + TEST_SHMEM_TEST(ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} diff --git a/test/unit/cxx_test_shmem_wait_until.cpp b/test/unit/cxx_test_shmem_wait_until.cpp new file mode 100644 index 000000000..61bf29b9c --- /dev/null +++ b/test/unit/cxx_test_shmem_wait_until.cpp @@ -0,0 +1,76 @@ +/* + * This test program is derived from a unit test created by Nick Park. + * The original unit test is a work of the U.S. Government and is not subject + * to copyright protection in the United States. Foreign copyrights may + * apply. + * + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#define TEST_SHMEM_WAIT_UNTIL(TYPE, TYPENAME) \ + do { \ + static TYPE remote = 0; \ + const int mype = shmem_my_pe(); \ + const int npes = shmem_n_pes(); \ + shmem_##TYPENAME##_p(&remote, (TYPE)mype+1, \ + (mype + 1) % npes); \ + shmem_##TYPENAME##_wait_until(&remote, \ + SHMEM_CMP_NE, 0); \ + if (remote != (TYPE)((mype + npes - 1) % npes)+1) { \ + printf("PE %i received incorrect value with " \ + "TEST_SHMEM_WAIT_UNTIL(%s)\n", mype, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + } while (false) + +int main(int argc, char* argv[]) { + shmem_init(); + + int rc = EXIT_SUCCESS; + TEST_SHMEM_WAIT_UNTIL(short, short); + TEST_SHMEM_WAIT_UNTIL(int, int); + TEST_SHMEM_WAIT_UNTIL(long, long); + TEST_SHMEM_WAIT_UNTIL(long long, longlong); + TEST_SHMEM_WAIT_UNTIL(unsigned short, ushort); + TEST_SHMEM_WAIT_UNTIL(unsigned int, uint); + TEST_SHMEM_WAIT_UNTIL(unsigned long, ulong); + TEST_SHMEM_WAIT_UNTIL(unsigned long long, ulonglong); + TEST_SHMEM_WAIT_UNTIL(int32_t, int32); + TEST_SHMEM_WAIT_UNTIL(int64_t, int64); + TEST_SHMEM_WAIT_UNTIL(uint32_t, uint32); + TEST_SHMEM_WAIT_UNTIL(uint64_t, uint64); + TEST_SHMEM_WAIT_UNTIL(size_t, size); + TEST_SHMEM_WAIT_UNTIL(ptrdiff_t, ptrdiff); + + shmem_finalize(); + return rc; +} From 069eda30236d27c8239dd3d950203117214c029c Mon Sep 17 00:00:00 2001 From: Min Si Date: Mon, 3 Dec 2018 20:42:32 -0600 Subject: [PATCH 18/23] Add non generic NBI AMO in test/unit --- test/unit/Makefile.am | 9 ++-- test/unit/cxx_test_shmem_atomic_add.cpp | 61 ++++++++++++++++++++++- test/unit/cxx_test_shmem_atomic_and.cpp | 51 ++++++++++++++++++- test/unit/cxx_test_shmem_atomic_cswap.cpp | 51 ++++++++++++++++++- test/unit/cxx_test_shmem_atomic_fetch.cpp | 57 ++++++++++++++++++++- test/unit/cxx_test_shmem_atomic_inc.cpp | 61 ++++++++++++++++++++++- test/unit/cxx_test_shmem_atomic_or.cpp | 52 ++++++++++++++++++- test/unit/cxx_test_shmem_atomic_swap.cpp | 54 +++++++++++++++++++- test/unit/cxx_test_shmem_atomic_xor.cpp | 52 ++++++++++++++++++- 9 files changed, 436 insertions(+), 12 deletions(-) diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index d370fee4e..2f78bcdaa 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -165,10 +165,6 @@ LOG_COMPILER = $(TEST_RUNNER) AM_LDFLAGS = $(LIBTOOL_WRAPPER_LDFLAGS) -if SHMEMX_TESTS -AM_CFLAGS = -DENABLE_SHMEMX_TESTS -endif - if EXTERNAL_TESTS bin_PROGRAMS = $(check_PROGRAMS) AM_CPPFLAGS = -I$(top_srcdir)/test/include @@ -184,6 +180,11 @@ if USE_PMI_SIMPLE LDADD += $(top_builddir)/pmi-simple/libpmi_simple.la endif +if SHMEMX_TESTS +AM_CFLAGS = -DENABLE_SHMEMX_TESTS +AM_CPPFLAGS += -DENABLE_SHMEMX_TESTS +endif + # C Tests with special flags rma_coverage_pshmem_SOURCES = rma_coverage.c rma_coverage_pshmem_CFLAGS = -DTEST_PSHMEM diff --git a/test/unit/cxx_test_shmem_atomic_add.cpp b/test/unit/cxx_test_shmem_atomic_add.cpp index bc45323f2..96e673a97 100644 --- a/test/unit/cxx_test_shmem_atomic_add.cpp +++ b/test/unit/cxx_test_shmem_atomic_add.cpp @@ -36,8 +36,12 @@ #include #include +#ifdef ENABLE_SHMEMX_TESTS +#include +#endif + enum op { ADD = 0, ATOMIC_ADD, CTX_ATOMIC_ADD, FADD, ATOMIC_FETCH_ADD, - CTX_ATOMIC_FETCH_ADD }; + CTX_ATOMIC_FETCH_ADD, ATOMIC_FETCH_ADD_NBI, CTX_ATOMIC_FETCH_ADD_NBI }; #ifdef ENABLE_DEPRECATED_TESTS #define DEPRECATED_ADD(TYPENAME, ...) shmem_##TYPENAME##_add(__VA_ARGS__) @@ -47,6 +51,32 @@ enum op { ADD = 0, ATOMIC_ADD, CTX_ATOMIC_ADD, FADD, ATOMIC_FETCH_ADD, #define DEPRECATED_FADD(TYPENAME, ...) shmem_##TYPENAME##_atomic_fetch_add(__VA_ARGS__) #endif +#ifdef ENABLE_SHMEMX_TESTS +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ + case ATOMIC_FETCH_ADD_NBI: \ + shmemx_##TYPENAME##_atomic_fetch_add_nbi(&old, &remote, \ + (TYPE)(mype + 1), i); \ + shmem_quiet(); \ + if (old > (TYPE)(npes * (npes + 1) / 2)) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_ATOMIC_FETCH_ADD_NBI: \ + shmemx_ctx_##TYPENAME##_atomic_fetch_add_nbi(SHMEM_CTX_DEFAULT,\ + &old, &remote, (TYPE)(mype + 1), i);\ + shmem_quiet(); \ + if (old > (TYPE)(npes * (npes + 1) / 2)) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; +#else +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) +#endif + #define TEST_SHMEM_ADD(OP, TYPE, TYPENAME) \ do { \ static TYPE remote; \ @@ -93,6 +123,7 @@ enum op { ADD = 0, ATOMIC_ADD, CTX_ATOMIC_ADD, FADD, ATOMIC_FETCH_ADD, rc = EXIT_FAILURE; \ } \ break; \ + SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ default: \ printf("Invalid operation (%d)\n", OP); \ shmem_global_exit(1); \ @@ -191,6 +222,34 @@ int main(int argc, char* argv[]) { TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, size_t, size); TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, ptrdiff_t, ptrdiff); +#ifdef ENABLE_SHMEMX_TESTS + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, int, int); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, long, long); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, long long, longlong); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, unsigned int, uint); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, unsigned long, ulong); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, unsigned long long, ulonglong); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, int32_t, int32); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, int64_t, int64); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, uint32_t, uint32); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, uint64_t, uint64); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, size_t, size); + TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, ptrdiff_t, ptrdiff); + + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, int, int); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, long, long); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, long long, longlong); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, unsigned int, uint); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, unsigned long, ulong); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, unsigned long long, ulonglong); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, int32_t, int32); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, int64_t, int64); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, uint32_t, uint32); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, uint64_t, uint64); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, size_t, size); + TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, ptrdiff_t, ptrdiff); +#endif + shmem_finalize(); return rc; } diff --git a/test/unit/cxx_test_shmem_atomic_and.cpp b/test/unit/cxx_test_shmem_atomic_and.cpp index fb089fdd5..1d8550ac8 100644 --- a/test/unit/cxx_test_shmem_atomic_and.cpp +++ b/test/unit/cxx_test_shmem_atomic_and.cpp @@ -37,13 +37,44 @@ #include #include -enum op { AND = 0, CTX_AND, FETCH_AND, CTX_FETCH_AND }; +#ifdef ENABLE_SHMEMX_TESTS +#include +#endif + +enum op { AND = 0, CTX_AND, FETCH_AND, CTX_FETCH_AND, FETCH_AND_NBI, + CTX_FETCH_AND_NBI }; /* Initially, remote = 111...b. Each PE performs an atomic AND where the * PEth bit of the input value is set to 0 and all other bits are set to 1. * The result has the NPES least significant bits cleared, 111...000...b. */ +#ifdef ENABLE_SHMEMX_TESTS +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ + case FETCH_AND_NBI: \ + shmemx_##TYPENAME##_atomic_fetch_and_nbi(&old, &remote, \ + ~(TYPE)(1LLU << mype), i); \ + shmem_quiet(); \ + if ((old & (TYPE)(1LLU << mype)) == 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_FETCH_AND_NBI: \ + shmemx_ctx_##TYPENAME##_atomic_fetch_and_nbi(SHMEM_CTX_DEFAULT,\ + &old, &remote, ~(TYPE)(1LLU << mype), i); \ + shmem_quiet(); \ + if ((old & (TYPE)(1LLU << mype)) == 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; +#else +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) +#endif + #define TEST_SHMEM_AND(OP, TYPE, TYPENAME) \ do { \ static TYPE remote = ~(TYPE)0; \ @@ -77,6 +108,7 @@ enum op { AND = 0, CTX_AND, FETCH_AND, CTX_FETCH_AND }; rc = EXIT_FAILURE; \ } \ break; \ + SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ default: \ printf("Invalid operation (%d)\n", OP); \ shmem_global_exit(1); \ @@ -129,6 +161,23 @@ int main(int argc, char* argv[]) { TEST_SHMEM_AND(CTX_FETCH_AND, uint32_t, uint32); TEST_SHMEM_AND(CTX_FETCH_AND, uint64_t, uint64); +#ifdef ENABLE_SHMEMX_TESTS + TEST_SHMEM_AND(FETCH_AND_NBI, unsigned int, uint); + TEST_SHMEM_AND(FETCH_AND_NBI, unsigned long, ulong); + TEST_SHMEM_AND(FETCH_AND_NBI, unsigned long long, ulonglong); + TEST_SHMEM_AND(FETCH_AND_NBI, int32_t, int32); + TEST_SHMEM_AND(FETCH_AND_NBI, int64_t, int64); + TEST_SHMEM_AND(FETCH_AND_NBI, uint32_t, uint32); + TEST_SHMEM_AND(FETCH_AND_NBI, uint64_t, uint64); + + TEST_SHMEM_AND(CTX_FETCH_AND_NBI, unsigned int, uint); + TEST_SHMEM_AND(CTX_FETCH_AND_NBI, unsigned long, ulong); + TEST_SHMEM_AND(CTX_FETCH_AND_NBI, unsigned long long, ulonglong); + TEST_SHMEM_AND(CTX_FETCH_AND_NBI, int32_t, int32); + TEST_SHMEM_AND(CTX_FETCH_AND_NBI, int64_t, int64); + TEST_SHMEM_AND(CTX_FETCH_AND_NBI, uint32_t, uint32); + TEST_SHMEM_AND(CTX_FETCH_AND_NBI, uint64_t, uint64); +#endif shmem_finalize(); return rc; } diff --git a/test/unit/cxx_test_shmem_atomic_cswap.cpp b/test/unit/cxx_test_shmem_atomic_cswap.cpp index 4e0e34582..0a3983c94 100644 --- a/test/unit/cxx_test_shmem_atomic_cswap.cpp +++ b/test/unit/cxx_test_shmem_atomic_cswap.cpp @@ -36,7 +36,12 @@ #include #include -enum op { CSWAP = 0, ATOMIC_COMPARE_SWAP, CTX_ATOMIC_COMPARE_SWAP }; +#ifdef ENABLE_SHMEMX_TESTS +#include +#endif + +enum op { CSWAP = 0, ATOMIC_COMPARE_SWAP, CTX_ATOMIC_COMPARE_SWAP, + ATOMIC_COMPARE_SWAP_NBI, CTX_ATOMIC_COMPARE_SWAP_NBI }; #ifdef ENABLE_DEPRECATED_TESTS #define DEPRECATED_CSWAP(TYPENAME,...) shmem_##TYPENAME##_cswap(__VA_ARGS__) @@ -44,6 +49,20 @@ enum op { CSWAP = 0, ATOMIC_COMPARE_SWAP, CTX_ATOMIC_COMPARE_SWAP }; #define DEPRECATED_CSWAP(TYPENAME,...) shmem_##TYPENAME##_atomic_compare_swap(__VA_ARGS__) #endif +#ifdef ENABLE_SHMEMX_TESTS +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ + case ATOMIC_COMPARE_SWAP_NBI: \ + shmemx_##TYPENAME##_atomic_compare_swap_nbi(&old, &remote, \ + (TYPE)npes, (TYPE)mype, (mype + 1) % npes); \ + break; \ + case CTX_ATOMIC_COMPARE_SWAP_NBI: \ + shmemx_ctx_##TYPENAME##_atomic_compare_swap_nbi(SHMEM_CTX_DEFAULT,\ + &old, &remote, (TYPE)npes, (TYPE)mype, (mype + 1) % npes);\ + break; +#else +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) +#endif + #define TEST_SHMEM_CSWAP(OP, TYPE, TYPENAME) \ do { \ static TYPE remote; \ @@ -67,6 +86,7 @@ enum op { CSWAP = 0, ATOMIC_COMPARE_SWAP, CTX_ATOMIC_COMPARE_SWAP }; (TYPE)npes, (TYPE)mype, \ (mype + 1) % npes); \ break; \ + SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ default: \ printf("invalid operation (%d)\n", OP); \ shmem_global_exit(1); \ @@ -131,6 +151,35 @@ int main(int argc, char* argv[]) { TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, size_t, size); TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP, ptrdiff_t, ptrdiff); + +#ifdef ENABLE_SHMEMX_TESTS + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, int, int); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, long, long); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, long long, longlong); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, unsigned int, uint); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, unsigned long, ulong); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, unsigned long long, ulonglong); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, int32_t, int32); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, int64_t, int64); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, uint32_t, uint32); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, uint64_t, uint64); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, size_t, size); + TEST_SHMEM_CSWAP(ATOMIC_COMPARE_SWAP_NBI, ptrdiff_t, ptrdiff); + + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, int, int); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, long, long); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, long long, longlong); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, unsigned int, uint); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, unsigned long, ulong); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, unsigned long long, ulonglong); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, int32_t, int32); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, int64_t, int64); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, uint32_t, uint32); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, uint64_t, uint64); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, size_t, size); + TEST_SHMEM_CSWAP(CTX_ATOMIC_COMPARE_SWAP_NBI, ptrdiff_t, ptrdiff); +#endif + shmem_finalize(); return rc; } diff --git a/test/unit/cxx_test_shmem_atomic_fetch.cpp b/test/unit/cxx_test_shmem_atomic_fetch.cpp index f65d865f9..981edb3eb 100644 --- a/test/unit/cxx_test_shmem_atomic_fetch.cpp +++ b/test/unit/cxx_test_shmem_atomic_fetch.cpp @@ -36,7 +36,12 @@ #include #include -enum op { FETCH = 0, ATOMIC_FETCH, CTX_ATOMIC_FETCH }; +#ifdef ENABLE_SHMEMX_TESTS +#include +#endif + +enum op { FETCH = 0, ATOMIC_FETCH, CTX_ATOMIC_FETCH, ATOMIC_FETCH_NBI, + CTX_ATOMIC_FETCH_NBI }; #ifdef ENABLE_DEPRECATED_TESTS #define DEPRECATED_FETCH(TYPENAME,...) shmem_##TYPENAME##_fetch(__VA_ARGS__) @@ -44,6 +49,22 @@ enum op { FETCH = 0, ATOMIC_FETCH, CTX_ATOMIC_FETCH }; #define DEPRECATED_FETCH(TYPENAME,...) shmem_##TYPENAME##_atomic_fetch(__VA_ARGS__) #endif +#ifdef ENABLE_SHMEMX_TESTS +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ + case ATOMIC_FETCH_NBI: \ + shmemx_##TYPENAME##_atomic_fetch_nbi(&val, &remote, \ + (mype + 1) % npes); \ + shmem_quiet(); \ + break; \ + case CTX_ATOMIC_FETCH_NBI: \ + shmemx_ctx_##TYPENAME##_atomic_fetch_nbi(SHMEM_CTX_DEFAULT,\ + &val, &remote, (mype + 1) % npes); \ + shmem_quiet(); \ + break; +#else +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) +#endif + #define TEST_SHMEM_FETCH(OP, TYPE, TYPENAME) \ do { \ static TYPE remote; \ @@ -65,6 +86,7 @@ enum op { FETCH = 0, ATOMIC_FETCH, CTX_ATOMIC_FETCH }; val = shmem_ctx_##TYPENAME##_atomic_fetch( \ SHMEM_CTX_DEFAULT, &remote, (mype + 1) % npes); \ break; \ + SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ default: \ printf("Invalid operation (%d)\n", OP); \ shmem_global_exit(1); \ @@ -129,6 +151,39 @@ int main(int argc, char* argv[]) { TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, size_t, size); TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH, ptrdiff_t, ptrdiff); + +#ifdef ENABLE_SHMEMX_TESTS + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, float, float); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, double, double); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, int, int); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, long, long); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, long long, longlong); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, unsigned int, uint); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, unsigned long, ulong); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, unsigned long long, ulonglong); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, int32_t, int32); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, int64_t, int64); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, uint32_t, uint32); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, uint64_t, uint64); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, size_t, size); + TEST_SHMEM_FETCH(ATOMIC_FETCH_NBI, ptrdiff_t, ptrdiff); + + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, float, float); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, double, double); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, int, int); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, long, long); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, long long, longlong); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, unsigned int, uint); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, unsigned long, ulong); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, unsigned long long, ulonglong); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, int32_t, int32); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, int64_t, int64); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, uint32_t, uint32); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, uint64_t, uint64); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, size_t, size); + TEST_SHMEM_FETCH(CTX_ATOMIC_FETCH_NBI, ptrdiff_t, ptrdiff); +#endif + shmem_finalize(); return rc; } diff --git a/test/unit/cxx_test_shmem_atomic_inc.cpp b/test/unit/cxx_test_shmem_atomic_inc.cpp index 6ecc024ca..820023d17 100644 --- a/test/unit/cxx_test_shmem_atomic_inc.cpp +++ b/test/unit/cxx_test_shmem_atomic_inc.cpp @@ -36,8 +36,13 @@ #include #include +#ifdef ENABLE_SHMEMX_TESTS +#include +#endif + enum op { INC = 0, ATOMIC_INC, CTX_ATOMIC_INC, FINC, ATOMIC_FETCH_INC, - CTX_ATOMIC_FETCH_INC }; + CTX_ATOMIC_FETCH_INC, ATOMIC_FETCH_INC_NBI, + CTX_ATOMIC_FETCH_INC_NBI }; #ifdef ENABLE_DEPRECATED_TESTS #define DEPRECATED_INC(TYPENAME,...) shmem_##TYPENAME##_inc(__VA_ARGS__) @@ -47,6 +52,31 @@ enum op { INC = 0, ATOMIC_INC, CTX_ATOMIC_INC, FINC, ATOMIC_FETCH_INC, #define DEPRECATED_FINC(TYPENAME,...) shmem_##TYPENAME##_atomic_fetch_inc(__VA_ARGS__) #endif +#ifdef ENABLE_SHMEMX_TESTS +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ + case ATOMIC_FETCH_INC_NBI: \ + shmemx_##TYPENAME##_atomic_fetch_inc_nbi(&old, &remote, i); \ + shmem_quiet(); \ + if (old > (TYPE) npes) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_ATOMIC_FETCH_INC_NBI: \ + shmemx_ctx_##TYPENAME##_atomic_fetch_inc_nbi(SHMEM_CTX_DEFAULT,\ + &old, &remote, i); \ + shmem_quiet(); \ + if (old > (TYPE) npes) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; +#else +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) +#endif + #define TEST_SHMEM_INC(OP, TYPE, TYPENAME) \ do { \ static TYPE remote = (TYPE)0; \ @@ -92,6 +122,7 @@ enum op { INC = 0, ATOMIC_INC, CTX_ATOMIC_INC, FINC, ATOMIC_FETCH_INC, rc = EXIT_FAILURE; \ } \ break; \ + SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ default: \ printf("Invalid operation (%d)\n", OP); \ shmem_global_exit(1); \ @@ -190,6 +221,34 @@ int main(int argc, char* argv[]) { TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, size_t, size); TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC, ptrdiff_t, ptrdiff); +#ifdef ENABLE_SHMEMX_TESTS + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, int, int); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, long, long); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, long long, longlong); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, unsigned int, uint); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, unsigned long, ulong); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, unsigned long long, ulonglong); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, int32_t, int32); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, int64_t, int64); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, uint32_t, uint32); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, uint64_t, uint64); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, size_t, size); + TEST_SHMEM_INC(ATOMIC_FETCH_INC_NBI, ptrdiff_t, ptrdiff); + + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, int, int); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, long, long); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, long long, longlong); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, unsigned int, uint); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, unsigned long, ulong); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, unsigned long long, ulonglong); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, int32_t, int32); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, int64_t, int64); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, uint32_t, uint32); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, uint64_t, uint64); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, size_t, size); + TEST_SHMEM_INC(CTX_ATOMIC_FETCH_INC_NBI, ptrdiff_t, ptrdiff); +#endif + shmem_finalize(); return rc; } diff --git a/test/unit/cxx_test_shmem_atomic_or.cpp b/test/unit/cxx_test_shmem_atomic_or.cpp index 67378caab..cd0704615 100644 --- a/test/unit/cxx_test_shmem_atomic_or.cpp +++ b/test/unit/cxx_test_shmem_atomic_or.cpp @@ -37,13 +37,44 @@ #include #include -enum op { OR = 0, CTX_OR, FETCH_OR, CTX_FETCH_OR }; +#ifdef ENABLE_SHMEMX_TESTS +#include +#endif + +enum op { OR = 0, CTX_OR, FETCH_OR, CTX_FETCH_OR, FETCH_OR_NBI, + CTX_FETCH_OR_NBI }; /* Initially, remote = 000...b. Each PE performs an atomic OR where the * PEth bit of the input value is set to 1 and all other bits are set to 0. * The result has the NPES least significant bits set, 000...111...b. */ +#ifdef ENABLE_SHMEMX_TESTS +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ + case FETCH_OR_NBI: \ + shmemx_##TYPENAME##_atomic_fetch_or_nbi(&old, &remote, \ + (TYPE)(1LLU << mype), i); \ + shmem_quiet(); \ + if ((old & (TYPE)(1LLU << mype)) != 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_FETCH_OR_NBI: \ + shmemx_ctx_##TYPENAME##_atomic_fetch_or_nbi(SHMEM_CTX_DEFAULT,\ + &old, &remote, (TYPE)(1LLU << mype), i); \ + shmem_quiet(); \ + if ((old & (TYPE)(1LLU << mype)) != 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; +#else +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) +#endif + #define TEST_SHMEM_OR(OP, TYPE, TYPENAME) \ do { \ static TYPE remote = (TYPE)0; \ @@ -77,6 +108,7 @@ enum op { OR = 0, CTX_OR, FETCH_OR, CTX_FETCH_OR }; rc = EXIT_FAILURE; \ } \ break; \ + SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ default: \ printf("Invalid operation (%d)\n", OP); \ shmem_global_exit(1); \ @@ -129,6 +161,24 @@ int main(int argc, char* argv[]) { TEST_SHMEM_OR(CTX_FETCH_OR, uint32_t, uint32); TEST_SHMEM_OR(CTX_FETCH_OR, uint64_t, uint64); +#ifdef ENABLE_SHMEMX_TESTS + TEST_SHMEM_OR(FETCH_OR_NBI, unsigned int, uint); + TEST_SHMEM_OR(FETCH_OR_NBI, unsigned long, ulong); + TEST_SHMEM_OR(FETCH_OR_NBI, unsigned long long, ulonglong); + TEST_SHMEM_OR(FETCH_OR_NBI, int32_t, int32); + TEST_SHMEM_OR(FETCH_OR_NBI, int64_t, int64); + TEST_SHMEM_OR(FETCH_OR_NBI, uint32_t, uint32); + TEST_SHMEM_OR(FETCH_OR_NBI, uint64_t, uint64); + + TEST_SHMEM_OR(CTX_FETCH_OR_NBI, unsigned int, uint); + TEST_SHMEM_OR(CTX_FETCH_OR_NBI, unsigned long, ulong); + TEST_SHMEM_OR(CTX_FETCH_OR_NBI, unsigned long long, ulonglong); + TEST_SHMEM_OR(CTX_FETCH_OR_NBI, int32_t, int32); + TEST_SHMEM_OR(CTX_FETCH_OR_NBI, int64_t, int64); + TEST_SHMEM_OR(CTX_FETCH_OR_NBI, uint32_t, uint32); + TEST_SHMEM_OR(CTX_FETCH_OR_NBI, uint64_t, uint64); +#endif + shmem_finalize(); return rc; } diff --git a/test/unit/cxx_test_shmem_atomic_swap.cpp b/test/unit/cxx_test_shmem_atomic_swap.cpp index eed854b7f..817a7d8ca 100644 --- a/test/unit/cxx_test_shmem_atomic_swap.cpp +++ b/test/unit/cxx_test_shmem_atomic_swap.cpp @@ -36,7 +36,12 @@ #include #include -enum op { SWAP = 0, ATOMIC_SWAP, CTX_ATOMIC_SWAP }; +#ifdef ENABLE_SHMEMX_TESTS +#include +#endif + +enum op { SWAP = 0, ATOMIC_SWAP, CTX_ATOMIC_SWAP, ATOMIC_SWAP_NBI, + CTX_ATOMIC_SWAP_NBI }; #ifdef ENABLE_DEPRECATED_TESTS #define DEPRECATED_SWAP(TYPENAME, ...) shmem_##TYPENAME##_swap(__VA_ARGS__) @@ -44,6 +49,20 @@ enum op { SWAP = 0, ATOMIC_SWAP, CTX_ATOMIC_SWAP }; #define DEPRECATED_SWAP(TYPENAME, ...) shmem_##TYPENAME##_atomic_swap(__VA_ARGS__) #endif +#ifdef ENABLE_SHMEMX_TESTS +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ + case ATOMIC_SWAP_NBI: \ + shmemx_##TYPENAME##_atomic_swap_nbi(&old, &remote, \ + (TYPE)mype, (mype + 1) % npes); \ + break; \ + case CTX_ATOMIC_SWAP_NBI: \ + shmemx_ctx_##TYPENAME##_atomic_swap_nbi(SHMEM_CTX_DEFAULT, \ + &old, &remote, (TYPE)mype, (mype + 1) % npes); \ + break; +#else +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) +#endif + #define TEST_SHMEM_SWAP(OP, TYPE, TYPENAME) \ do { \ static TYPE remote; \ @@ -65,6 +84,7 @@ enum op { SWAP = 0, ATOMIC_SWAP, CTX_ATOMIC_SWAP }; old = shmem_ctx_##TYPENAME##_atomic_swap(SHMEM_CTX_DEFAULT, \ &remote, (TYPE)mype, (mype + 1) % npes); \ break; \ + SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ default: \ printf("invalid operation (%d)\n", OP); \ shmem_global_exit(1); \ @@ -135,6 +155,38 @@ int main(int argc, char* argv[]) { TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, size_t, size); TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP, ptrdiff_t, ptrdiff); +#ifdef ENABLE_SHMEMX_TESTS + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, float, float); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, double, double); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, int, int); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, long, long); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, long long, longlong); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, unsigned int, uint); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, unsigned long, ulong); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, unsigned long long, ulonglong); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, int32_t, int32); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, int64_t, int64); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, uint32_t, uint32); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, uint64_t, uint64); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, size_t, size); + TEST_SHMEM_SWAP(ATOMIC_SWAP_NBI, ptrdiff_t, ptrdiff); + + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, float, float); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, double, double); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, int, int); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, long, long); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, long long, longlong); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, unsigned int, uint); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, unsigned long, ulong); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, unsigned long long, ulonglong); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, int32_t, int32); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, int64_t, int64); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, uint32_t, uint32); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, uint64_t, uint64); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, size_t, size); + TEST_SHMEM_SWAP(CTX_ATOMIC_SWAP_NBI, ptrdiff_t, ptrdiff); +#endif + shmem_finalize(); return rc; } diff --git a/test/unit/cxx_test_shmem_atomic_xor.cpp b/test/unit/cxx_test_shmem_atomic_xor.cpp index 029b2f8b4..e44fb03c4 100644 --- a/test/unit/cxx_test_shmem_atomic_xor.cpp +++ b/test/unit/cxx_test_shmem_atomic_xor.cpp @@ -37,13 +37,44 @@ #include #include -enum op { XOR = 0, CTX_XOR, FETCH_XOR, CTX_FETCH_XOR }; +#ifdef ENABLE_SHMEMX_TESTS +#include +#endif + +enum op { XOR = 0, CTX_XOR, FETCH_XOR, CTX_FETCH_XOR, FETCH_XOR_NBI, + CTX_FETCH_XOR_NBI }; /* Initially, remote = 111...b. Each PE performs an atomic XOR where the * PEth bit of the input value is set to 1 and all other bits are set to 0. * The result has the NPES least significant bits cleared, 111...000...b. */ +#ifdef ENABLE_SHMEMX_TESTS +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ + case FETCH_XOR_NBI: \ + shmemx_##TYPENAME##_atomic_fetch_xor_nbi(&old, &remote, \ + (TYPE)(1LLU << mype), i); \ + shmem_quiet(); \ + if (((old ^ (TYPE)(1LLU << mype)) & (TYPE)(1LLU << mype)) != 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; \ + case CTX_FETCH_XOR_NBI: \ + shmemx_ctx_##TYPENAME##_atomic_fetch_xor_nbi(SHMEM_CTX_DEFAULT,\ + &old, &remote, (TYPE)(1LLU << mype), i); \ + shmem_quiet(); \ + if (((old ^ (TYPE)(1LLU << mype)) & (TYPE)(1LLU << mype)) != 0) { \ + printf("PE %i error inconsistent value of old (%s, %s)\n", \ + mype, #OP, #TYPE); \ + rc = EXIT_FAILURE; \ + } \ + break; +#else +#define SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) +#endif + #define TEST_SHMEM_XOR(OP, TYPE, TYPENAME) \ do { \ static TYPE remote = ~(TYPE)0; \ @@ -77,6 +108,7 @@ enum op { XOR = 0, CTX_XOR, FETCH_XOR, CTX_FETCH_XOR }; rc = EXIT_FAILURE; \ } \ break; \ + SHMEMX_NBI_OPS_CASES(OP, TYPE, TYPENAME) \ default: \ printf("Invalid operation (%d)\n", OP); \ shmem_global_exit(1); \ @@ -129,6 +161,24 @@ int main(int argc, char* argv[]) { TEST_SHMEM_XOR(CTX_FETCH_XOR, uint32_t, uint32); TEST_SHMEM_XOR(CTX_FETCH_XOR, uint64_t, uint64); +#ifdef ENABLE_SHMEMX_TESTS + TEST_SHMEM_XOR(FETCH_XOR_NBI, unsigned int, uint); + TEST_SHMEM_XOR(FETCH_XOR_NBI, unsigned long, ulong); + TEST_SHMEM_XOR(FETCH_XOR_NBI, unsigned long long, ulonglong); + TEST_SHMEM_XOR(FETCH_XOR_NBI, int32_t, int32); + TEST_SHMEM_XOR(FETCH_XOR_NBI, int64_t, int64); + TEST_SHMEM_XOR(FETCH_XOR_NBI, uint32_t, uint32); + TEST_SHMEM_XOR(FETCH_XOR_NBI, uint64_t, uint64); + + TEST_SHMEM_XOR(CTX_FETCH_XOR_NBI, unsigned int, uint); + TEST_SHMEM_XOR(CTX_FETCH_XOR_NBI, unsigned long, ulong); + TEST_SHMEM_XOR(CTX_FETCH_XOR_NBI, unsigned long long, ulonglong); + TEST_SHMEM_XOR(CTX_FETCH_XOR_NBI, int32_t, int32); + TEST_SHMEM_XOR(CTX_FETCH_XOR_NBI, int64_t, int64); + TEST_SHMEM_XOR(CTX_FETCH_XOR_NBI, uint32_t, uint32); + TEST_SHMEM_XOR(CTX_FETCH_XOR_NBI, uint64_t, uint64); +#endif + shmem_finalize(); return rc; } From 08e84c427e91a55149198bbbca440b0406108ea5 Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Wed, 5 Dec 2018 14:19:38 -0500 Subject: [PATCH 19/23] Explicit rand_r casts and make cmpret an int Signed-off-by: David M. Ozog --- src/synchronization_c.c4 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index 6041079e2..fbcf5b278 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -211,7 +211,8 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ SHMEM_ERR_CHECK_CMP_OP(cond); \ \ - size_t cmpret = 0, i = 0, found_idx = SIZE_MAX, num_ignored = 0; \ + size_t i = 0, found_idx = SIZE_MAX, num_ignored = 0; \ + int cmpret = 0; \ \ if (status) { \ for (i = 0; i < nelems; i++) { \ @@ -222,7 +223,8 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') return SIZE_MAX; \ \ SHMEM_MUTEX_LOCK(shmem_internal_mutex_rand_r); \ - size_t start_idx = rand_r(&shmem_internal_rand_seed) / (RAND_MAX + 1.0) * nelems; \ + size_t start_idx = (size_t) (rand_r(&shmem_internal_rand_seed) / \ + (RAND_MAX + 1.0) * (double) nelems); \ SHMEM_MUTEX_UNLOCK(shmem_internal_mutex_rand_r); \ \ while (!cmpret) { \ @@ -268,7 +270,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') return 0; \ \ while (ncompleted == 0) { \ - size_t cmpret = 0; \ + int cmpret = 0; \ for (i = 0; i < nelems; i++) { \ if (status == NULL || !status[i]) { \ COMP(cond, vars[i], value, cmpret); \ @@ -346,11 +348,12 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') \ size_t found_idx = SIZE_MAX, i = 0; \ SHMEM_MUTEX_LOCK(shmem_internal_mutex_rand_r); \ - size_t start_idx = rand_r(&shmem_internal_rand_seed) / (RAND_MAX + 1.0) * nelems; \ + size_t start_idx = (size_t) (rand_r(&shmem_internal_rand_seed) / \ + (RAND_MAX + 1.0) * (double) nelems); \ SHMEM_MUTEX_UNLOCK(shmem_internal_mutex_rand_r); \ \ for (i = 0; i < nelems; i++) { \ - size_t cmpret = 0; \ + int cmpret = 0; \ size_t idx = (i + start_idx) % nelems; \ if (status == NULL || !status[idx]) { \ COMP(cond, vars[idx], value, cmpret); \ @@ -391,7 +394,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') \ for (i = 0; i < nelems; i++) { \ if (status == NULL || !status[i]) { \ - size_t cmpret; \ + int cmpret; \ COMP(cond, vars[i], value, cmpret); \ if (cmpret) { \ if (status) status[i] = 1; \ From 00822921d9b4ba8d9d8a3bc8844016f59112d3a9 Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Wed, 5 Dec 2018 15:49:09 -0500 Subject: [PATCH 20/23] Remove restrict type qualifier from wait/test API Signed-off-by: David M. Ozog --- mpp/shmemx.h4.in | 8 ++++---- src/synchronization_c.c4 | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mpp/shmemx.h4.in b/mpp/shmemx.h4.in index 45ea3fa0d..79da665c3 100644 --- a/mpp/shmemx.h4.in +++ b/mpp/shmemx.h4.in @@ -62,13 +62,13 @@ define(`SHMEM_CXX_WAIT_UNTIL_ALL', SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_ALL') define(`SHMEM_CXX_WAIT_UNTIL_ANY', -`static inline size_t shmemx_wait_until_any($2 *ivars, size_t nelems, int * restrict status, int cmp, $2 cmp_value) { +`static inline size_t shmemx_wait_until_any($2 *ivars, size_t nelems, int *status, int cmp, $2 cmp_value) { shmemx_$1_wait_until_any(ivars, nelems, status, cmp, cmp_value); }')dnl SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_ANY') define(`SHMEM_CXX_WAIT_UNTIL_SOME', -`static inline size_t shmemx_wait_until_some($2 *ivars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, $2 cmp_value) { +`static inline size_t shmemx_wait_until_some($2 *ivars, size_t nelems, size_t *indices, int *status, int cmp, $2 cmp_value) { shmemx_$1_wait_until_some(ivars, nelems, indices, status, cmp, cmp_value); }')dnl SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_SOME') @@ -80,13 +80,13 @@ define(`SHMEM_CXX_TEST_ALL', SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_TEST_ALL') define(`SHMEM_CXX_TEST_ANY', -`static inline size_t shmemx_test_any($2 *ivars, size_t nelems, int * restrict status, int cmp, $2 cmp_value) { +`static inline size_t shmemx_test_any($2 *ivars, size_t nelems, int *status, int cmp, $2 cmp_value) { return shmemx_$1_test_any(ivars, nelems, status, cmp, cmp_value); }')dnl SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_TEST_ANY') define(`SHMEM_CXX_TEST_SOME', -`static inline size_t shmemx_test_some($2 *ivars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, $2 cmp_value) { +`static inline size_t shmemx_test_some($2 *ivars, size_t nelems, size_t *indices, int *status, int cmp, $2 cmp_value) { return shmemx_$1_test_some(ivars, nelems, indices, status, cmp, cmp_value); }')dnl SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_TEST_SOME') diff --git a/src/synchronization_c.c4 b/src/synchronization_c.c4 index fbcf5b278..6ec87d5d4 100644 --- a/src/synchronization_c.c4 +++ b/src/synchronization_c.c4 @@ -205,7 +205,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ALL') #define SHMEM_DEF_WAIT_UNTIL_ANY(STYPE,TYPE) \ size_t SHMEM_FUNCTION_ATTRIBUTES \ shmemx_##STYPE##_wait_until_any(TYPE *vars, size_t nelems, \ - int * restrict status, int cond, TYPE value) \ + int *status, int cond, TYPE value) \ { \ SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ @@ -252,8 +252,8 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_WAIT_UNTIL_ANY') #define SHMEM_DEF_WAIT_UNTIL_SOME(STYPE,TYPE) \ size_t SHMEM_FUNCTION_ATTRIBUTES \ - shmemx_##STYPE##_wait_until_some(TYPE *vars, size_t nelems, size_t * restrict indices, \ - int * restrict status, int cond, TYPE value) \ + shmemx_##STYPE##_wait_until_some(TYPE *vars, size_t nelems, size_t *indices, \ + int *status, int cond, TYPE value) \ { \ SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ @@ -339,7 +339,7 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ALL') #define SHMEM_DEF_TEST_ANY(STYPE,TYPE) \ size_t SHMEM_FUNCTION_ATTRIBUTES \ - shmemx_##STYPE##_test_any(TYPE *vars, size_t nelems, int * restrict status, \ + shmemx_##STYPE##_test_any(TYPE *vars, size_t nelems, int *status, \ int cond, TYPE value) \ { \ SHMEM_ERR_CHECK_INITIALIZED(); \ @@ -375,8 +375,8 @@ SHMEM_BIND_C_SYNC(`SHMEM_DEF_TEST_ANY') #define SHMEM_DEF_TEST_SOME(STYPE,TYPE) \ size_t SHMEM_FUNCTION_ATTRIBUTES \ - shmemx_##STYPE##_test_some(TYPE *vars, size_t nelems, size_t * restrict indices, \ - int * restrict status, int cond, TYPE value) \ + shmemx_##STYPE##_test_some(TYPE *vars, size_t nelems, size_t *indices, \ + int *status, int cond, TYPE value) \ { \ SHMEM_ERR_CHECK_INITIALIZED(); \ SHMEM_ERR_CHECK_SYMMETRIC(vars, sizeof(TYPE)); \ From 85e8645935f604611cade4ccc5452a55bbabcd20 Mon Sep 17 00:00:00 2001 From: David Ozog Date: Wed, 5 Dec 2018 23:13:47 -0500 Subject: [PATCH 21/23] Missed some "restricts" in the shmemx C bindings Signed-off-by: David Ozog --- mpp/shmemx_c_func.h4.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mpp/shmemx_c_func.h4.in b/mpp/shmemx_c_func.h4.in index ed04f4d6f..4d427f2c8 100644 --- a/mpp/shmemx_c_func.h4.in +++ b/mpp/shmemx_c_func.h4.in @@ -45,11 +45,11 @@ define(`SHMEM_C_WAIT_UNTIL_ALL', SHMEM_BIND_C_SYNC(`SHMEM_C_WAIT_UNTIL_ALL') define(`SHMEM_C_WAIT_UNTIL_ANY', -`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_wait_until_any($2 *vars, size_t nelems, int * restrict status, int cmp, $2 value);')dnl +`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_wait_until_any($2 *vars, size_t nelems, int *status, int cmp, $2 value);')dnl SHMEM_BIND_C_SYNC(`SHMEM_C_WAIT_UNTIL_ANY') define(`SHMEM_C_WAIT_UNTIL_SOME', -`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_wait_until_some($2 *vars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, $2 value);')dnl +`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_wait_until_some($2 *vars, size_t nelems, size_t *indices, int *status, int cmp, $2 value);')dnl SHMEM_BIND_C_SYNC(`SHMEM_C_WAIT_UNTIL_SOME') define(`SHMEM_C_TEST_ALL', @@ -57,11 +57,11 @@ define(`SHMEM_C_TEST_ALL', SHMEM_BIND_C_SYNC(`SHMEM_C_TEST_ALL') define(`SHMEM_C_TEST_ANY', -`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_test_any($2 *vars, size_t nelems, int * restrict status, int cmp, $2 value);')dnl +`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_test_any($2 *vars, size_t nelems, int *status, int cmp, $2 value);')dnl SHMEM_BIND_C_SYNC(`SHMEM_C_TEST_ANY') define(`SHMEM_C_TEST_SOME', -`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_test_some($2 *vars, size_t nelems, size_t * restrict indices, int * restrict status, int cmp, $2 value);')dnl +`SHMEM_FUNCTION_ATTRIBUTES size_t SHPRE()shmemx_$1_test_some($2 *vars, size_t nelems, size_t *indices, int *status, int cmp, $2 value);')dnl SHMEM_BIND_C_SYNC(`SHMEM_C_TEST_SOME') /* Nonblocking swap operations, proposed for OpenSHMEM 1.5 */ From ea51f276a90074d888815658a27e654d9e6b606e Mon Sep 17 00:00:00 2001 From: James Dinan Date: Thu, 6 Dec 2018 15:47:37 -0500 Subject: [PATCH 22/23] Fix C++ generic bindings for wait some/any Signed-off-by: James Dinan --- mpp/shmemx.h4.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mpp/shmemx.h4.in b/mpp/shmemx.h4.in index 79da665c3..4937e710c 100644 --- a/mpp/shmemx.h4.in +++ b/mpp/shmemx.h4.in @@ -63,13 +63,13 @@ SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_ALL') define(`SHMEM_CXX_WAIT_UNTIL_ANY', `static inline size_t shmemx_wait_until_any($2 *ivars, size_t nelems, int *status, int cmp, $2 cmp_value) { - shmemx_$1_wait_until_any(ivars, nelems, status, cmp, cmp_value); + return shmemx_$1_wait_until_any(ivars, nelems, status, cmp, cmp_value); }')dnl SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_ANY') define(`SHMEM_CXX_WAIT_UNTIL_SOME', `static inline size_t shmemx_wait_until_some($2 *ivars, size_t nelems, size_t *indices, int *status, int cmp, $2 cmp_value) { - shmemx_$1_wait_until_some(ivars, nelems, indices, status, cmp, cmp_value); + return shmemx_$1_wait_until_some(ivars, nelems, indices, status, cmp, cmp_value); }')dnl SHMEM_CXX_DEFINE_FOR_SYNC(`SHMEM_CXX_WAIT_UNTIL_SOME') From b48bc205b19f87e1b01a58e2b9964ebde86874c2 Mon Sep 17 00:00:00 2001 From: Ralph H Castain Date: Thu, 6 Dec 2018 23:48:10 +0000 Subject: [PATCH 23/23] Fix opal_check_pmi.m4 for newer PMIx Quick fix: provide paragraph for PMIx v4.x Signed-off-by: Ralph H Castain --- config/opal_check_pmi.m4 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/config/opal_check_pmi.m4 b/config/opal_check_pmi.m4 index a1297d427..74bfc8f34 100644 --- a/config/opal_check_pmi.m4 +++ b/config/opal_check_pmi.m4 @@ -13,7 +13,7 @@ # Copyright (c) 2009-2015 Cisco Systems, Inc. All rights reserved. # Copyright (c) 2011-2016 Los Alamos National Security, LLC. All rights # reserved. -# Copyright (c) 2014 Intel, Inc. All rights reserved. +# Copyright (c) 2014-2018 Intel, Inc. All rights reserved. # Copyright (c) 2014 Research Organization for Information Science # and Technology (RIST). All rights reserved. # $COPYRIGHT$ @@ -303,6 +303,19 @@ AC_DEFUN([OPAL_CHECK_PMIX],[ # if it does exist, then we need to parse it to find # the actual release series + AS_IF([test "$opal_external_pmix_version_found" = "0"], + [AC_MSG_CHECKING([version 4x]) + AC_PREPROC_IFELSE([AC_LANG_PROGRAM([ + #include + #if (PMIX_VERSION_MAJOR < 4L) + #error "not version 4" + #endif + ], [])], + [AC_MSG_RESULT([found]) + opal_external_pmix_version=4x + opal_external_pmix_version_found=1], + [AC_MSG_RESULT([not found])])]) + AS_IF([test "$opal_external_pmix_version_found" = "0"], [AC_MSG_CHECKING([version 3x]) AC_PREPROC_IFELSE([AC_LANG_PROGRAM([