From 1de7c958df603cbda4f0ed6b40ecc28fac5bf94a Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Fri, 3 Aug 2018 09:13:06 -0400 Subject: [PATCH 01/23] Add example numbering --- utils/defs.tex | 24 ++++++++++++++---------- utils/packages.tex | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/utils/defs.tex b/utils/defs.tex index dbfdffdcf..d3f27dce2 100644 --- a/utils/defs.tex +++ b/utils/defs.tex @@ -511,24 +511,28 @@ \end{description} } +\theoremstyle{definition} +\newtheorem{example}{Example} \newenvironment{apiexamples}{ -\newcommand{\apicexample}[3]{ - ##1 + \newcommand{\apicexample}[3]{ + \begin{example} + ##1 + \end{example} \lstinputlisting[language={C}, tabsize=2, basicstyle=\ttfamily\footnotesize, morekeywords={size_t, ptrdiff_t, shmem_ctx_t}]{##2} ##3 } -\newcommand{\apifexample}[3]{ - ##1 + \newcommand{\apifexample}[3]{ + \begin{example} + ##1 + \end{example} \lstinputlisting[language={Fortran}, tabsize=2, - basicstyle=\ttfamily\footnotesize, deletekeywords={TARGET}]{##2} + basicstyle=\ttfamily\footnotesize, deletekeywords={TARGET}]{##2} ##3 } -\vspace{-2pt} + \vspace{-2pt} \item[EXAMPLES] \hfill \\ -\vspace{-2pt} -} -{ -} + \vspace{-2pt} +}{} % % End library API description template commands diff --git a/utils/packages.tex b/utils/packages.tex index 8ff6beef6..75f1fd4f3 100644 --- a/utils/packages.tex +++ b/utils/packages.tex @@ -7,6 +7,7 @@ \usepackage{float} \usepackage[usenames,dvipsnames]{color} \usepackage{amsmath} +\usepackage{amsthm} \usepackage[table]{xcolor} \usepackage{xspace} \usepackage{xhfill} @@ -15,7 +16,6 @@ \usepackage{listings} % note sure after here \usepackage{makeidx} -\usepackage{amsmath} \usepackage[UKenglish]{isodate} \usepackage{ifthen} \usepackage{textcomp} From d61e6f4bb56a2a2099fe672b0214fc37f7ce66b6 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Fri, 3 Aug 2018 16:03:55 -0400 Subject: [PATCH 02/23] improve-examples: Tweak examples Makefile, add .gitignore - Enable OpenMP where needed - Add some extra warning flags - Adds .gitignore to ignore the compiled binaries --- example_code/.gitignore | 1 + example_code/Makefile | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 example_code/.gitignore diff --git a/example_code/.gitignore b/example_code/.gitignore new file mode 100644 index 000000000..43c1827e9 --- /dev/null +++ b/example_code/.gitignore @@ -0,0 +1 @@ +*.[cf]x diff --git a/example_code/Makefile b/example_code/Makefile index c37cfc99f..f80fc2a13 100644 --- a/example_code/Makefile +++ b/example_code/Makefile @@ -1,5 +1,5 @@ CC = oshcc -CFLAGS ?= -Wall -Wextra +CFLAGS ?= -Wall -Wextra -pedantic -Werror FC = oshfort FFLAGS ?= -Wall -Wextra @@ -13,6 +13,8 @@ C_BINS = $(C_TESTS:.c=.cx) F_TESTS = $(wildcard *.f90) F_BINS = $(F_TESTS:.f90=.fx) +shmem_ctx.cx: CFLAGS += -fopenmp + .PHONY: all run clean all: $(C_BINS) $(F_BINS) @@ -24,9 +26,10 @@ all: $(C_BINS) $(F_BINS) $(FC) $(FFLAGS) -o $@ $+ run: $(C_BINS) - @for bin in $+; do \ - echo --$$bin------------------------------; \ - $(RUNCMD) $(RUNOPT) ./$$bin || exit $$?; \ + @for bin in $+; do \ + echo -- $$bin ------------------------------; \ + $(RUNCMD) $(RUNOPT) ./$$bin; \ + echo -- exit status: $$?; \ done clean: From 8d655f735d15ce0ce123417a4d62a1f642028acd Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Fri, 3 Aug 2018 16:06:43 -0400 Subject: [PATCH 03/23] improve-examples: Fix misuse of \apicexample vs. \apifexample --- content/shmem_init.tex | 4 ++-- content/shmem_wait_until.tex | 2 +- content/start_pes.tex | 2 +- .../{shmem_wait3_example.f90 => shmem_wait3_example.c} | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) rename example_code/{shmem_wait3_example.f90 => shmem_wait3_example.c} (60%) diff --git a/content/shmem_init.tex b/content/shmem_init.tex index 2bf3b9c70..c2c68acdb 100644 --- a/content/shmem_init.tex +++ b/content/shmem_init.tex @@ -45,8 +45,8 @@ \begin{apiexamples} -\apifexample -{ The following \FUNC{shmem\_init} example is for \Cstd[11] programs: } +\apicexample + { The following \FUNC{shmem\_init} example is for \Cstd[11] programs: } { example_code/shmem_init_example.c } {} diff --git a/content/shmem_wait_until.tex b/content/shmem_wait_until.tex index e5943b468..d861e0f16 100644 --- a/content/shmem_wait_until.tex +++ b/content/shmem_wait_until.tex @@ -114,7 +114,7 @@ \apicexample {The following \CorCpp{} call waits until the value in \VAR{ivar} is set to be less than zero by a transfer from a remote PE:} -{./example_code/shmem_wait3_example.f90} +{./example_code/shmem_wait3_example.c} {} \apifexample diff --git a/content/start_pes.tex b/content/start_pes.tex index a88d55fc0..bc0585150 100644 --- a/content/start_pes.tex +++ b/content/start_pes.tex @@ -52,7 +52,7 @@ \begin{apiexamples} -\apicexample +\apifexample { This is a simple program that calls \FUNC{start\_pes}:} {./example_code/shmem_startpes_example.f90} {} diff --git a/example_code/shmem_wait3_example.f90 b/example_code/shmem_wait3_example.c similarity index 60% rename from example_code/shmem_wait3_example.f90 rename to example_code/shmem_wait3_example.c index 16c3cd57b..4b4608215 100644 --- a/example_code/shmem_wait3_example.f90 +++ b/example_code/shmem_wait3_example.c @@ -1,4 +1,5 @@ -#include #include +#include +#include int ivar; shmem_int_wait_until(&ivar, SHMEM_CMP_LT, 0); From b591e831b9b22e2b799313e87a6c14b3a0968d55 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Fri, 3 Aug 2018 17:32:11 -0400 Subject: [PATCH 04/23] improve-examples: Add API example numbering --- utils/defs.tex | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/utils/defs.tex b/utils/defs.tex index d3f27dce2..89200f12d 100644 --- a/utils/defs.tex +++ b/utils/defs.tex @@ -514,21 +514,23 @@ \theoremstyle{definition} \newtheorem{example}{Example} \newenvironment{apiexamples}{ - \newcommand{\apicexample}[3]{ + \newcommand{\apicexample}[4][]{ \begin{example} - ##1 + \ifthenelse{\equal{##1}{}}{}{\label{##1}} + ##2 \end{example} \lstinputlisting[language={C}, tabsize=2, basicstyle=\ttfamily\footnotesize, - morekeywords={size_t, ptrdiff_t, shmem_ctx_t}]{##2} - ##3 } - \newcommand{\apifexample}[3]{ + morekeywords={size_t, ptrdiff_t, shmem_ctx_t}]{##3} + ##4} + \newcommand{\apifexample}[4][]{ \begin{example} - ##1 + \ifthenelse{\equal{##1}{}}{}{\label{##1}} + ##2 \end{example} \lstinputlisting[language={Fortran}, tabsize=2, - basicstyle=\ttfamily\footnotesize, deletekeywords={TARGET}]{##2} - ##3 } + basicstyle=\ttfamily\footnotesize, deletekeywords={TARGET}]{##3} + ##4} \vspace{-2pt} \item[EXAMPLES] \hfill \\ \vspace{-2pt} From 58459845d3e8e2ba43b789eba4378ed0cd75c7bc Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Fri, 3 Aug 2018 17:39:59 -0400 Subject: [PATCH 05/23] improve-examples: clang-format-ify --- example_code/hello-openshmem.c | 17 ++-- example_code/shmem_alltoall_example.c | 71 +++++++------- example_code/shmem_alltoalls_example.c | 78 +++++++-------- example_code/shmem_atomic_add_example.c | 23 +++-- .../shmem_atomic_compare_swap_example.c | 20 ++-- example_code/shmem_atomic_fetch_add_example.c | 25 +++-- example_code/shmem_atomic_fetch_inc_example.c | 25 +++-- example_code/shmem_atomic_inc_example.c | 23 +++-- example_code/shmem_atomic_swap_example.c | 31 +++--- example_code/shmem_barrier_example.c | 37 ++++---- example_code/shmem_barrierall_example.c | 27 +++--- example_code/shmem_broadcast_example.c | 33 ++++--- example_code/shmem_collect_example.c | 55 ++++++----- example_code/shmem_ctx.c | 87 ++++++++--------- example_code/shmem_ctx_pipelined_reduce.c | 94 ++++++++++--------- example_code/shmem_fence_example.c | 39 ++++---- example_code/shmem_finalize_example.c | 25 +++-- example_code/shmem_g_example.c | 25 +++-- example_code/shmem_global_exit_example.c | 23 +++-- example_code/shmem_init_example.c | 28 +++--- example_code/shmem_iput_example.c | 31 +++--- example_code/shmem_lock_example.c | 31 +++--- example_code/shmem_npes_example.c | 17 ++-- example_code/shmem_p_example.c | 29 +++--- example_code/shmem_ptr_example.c | 38 ++++---- example_code/shmem_put_example.c | 25 +++-- example_code/shmem_quiet_example.c | 49 +++++----- example_code/shmem_sync_example.c | 41 ++++---- example_code/shmem_test_example1.c | 14 +-- example_code/shmem_wait3_example.c | 2 +- example_code/writing_shmem_example.c | 59 ++++++------ 31 files changed, 550 insertions(+), 572 deletions(-) diff --git a/example_code/hello-openshmem.c b/example_code/hello-openshmem.c index 8432b20dd..7b14a5c18 100644 --- a/example_code/hello-openshmem.c +++ b/example_code/hello-openshmem.c @@ -1,12 +1,11 @@ -#include #include /* The OpenSHMEM header file */ +#include -int main (void) -{ - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); - printf("Hello from %d of %d\n", me, npes); - shmem_finalize(); - return 0; +int main(void) { + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); + printf("Hello from %d of %d\n", me, npes); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_alltoall_example.c b/example_code/shmem_alltoall_example.c index 13d11b75e..e9e67b19f 100644 --- a/example_code/shmem_alltoall_example.c +++ b/example_code/shmem_alltoall_example.c @@ -1,46 +1,45 @@ -#include #include #include +#include -int main(void) -{ - static long pSync[SHMEM_ALLTOALL_SYNC_SIZE]; - for (int i = 0; i < SHMEM_ALLTOALL_SYNC_SIZE; i++) - pSync[i] = SHMEM_SYNC_VALUE; +int main(void) { + static long pSync[SHMEM_ALLTOALL_SYNC_SIZE]; + for (int i = 0; i < SHMEM_ALLTOALL_SYNC_SIZE; i++) + pSync[i] = SHMEM_SYNC_VALUE; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); - const int count = 2; - int64_t* dest = (int64_t*) shmem_malloc(count * npes * sizeof(int64_t)); - int64_t* source = (int64_t*) shmem_malloc(count * npes * sizeof(int64_t)); + const int count = 2; + int64_t *dest = (int64_t *)shmem_malloc(count * npes * sizeof(int64_t)); + int64_t *source = (int64_t *)shmem_malloc(count * npes * sizeof(int64_t)); - /* assign source values */ - for (int pe = 0; pe < npes; pe++) { - for (int i = 0; i < count; i++) { - source[(pe * count) + i] = me + pe; - dest[(pe * count) + i] = 9999; - } - } - /* wait for all PEs to update source/dest */ - shmem_barrier_all(); + /* assign source values */ + for (int pe = 0; pe < npes; pe++) { + for (int i = 0; i < count; i++) { + source[(pe * count) + i] = me + pe; + dest[(pe * count) + i] = 9999; + } + } + /* wait for all PEs to update source/dest */ + shmem_barrier_all(); - /* alltoall on all PES */ - shmem_alltoall64(dest, source, count, 0, 0, npes, pSync); + /* alltoall on all PES */ + shmem_alltoall64(dest, source, count, 0, 0, npes, pSync); - /* verify results */ - for (int pe = 0; pe < npes; pe++) { - for (int i = 0; i < count; i++) { - if (dest[(pe * count) + i] != pe + me) { - printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", - me, (pe * count) + i, dest[(pe * count) + i], pe + me); - } - } - } + /* verify results */ + for (int pe = 0; pe < npes; pe++) { + for (int i = 0; i < count; i++) { + if (dest[(pe * count) + i] != pe + me) { + printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", me, + (pe * count) + i, dest[(pe * count) + i], pe + me); + } + } + } - shmem_free(dest); - shmem_free(source); - shmem_finalize(); - return 0; + shmem_free(dest); + shmem_free(source); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_alltoalls_example.c b/example_code/shmem_alltoalls_example.c index f78ff5687..076457c29 100644 --- a/example_code/shmem_alltoalls_example.c +++ b/example_code/shmem_alltoalls_example.c @@ -1,49 +1,49 @@ -#include #include #include +#include -int main(void) -{ - static long pSync[SHMEM_ALLTOALLS_SYNC_SIZE]; - for (int i = 0; i < SHMEM_ALLTOALLS_SYNC_SIZE; i++) - pSync[i] = SHMEM_SYNC_VALUE; +int main(void) { + static long pSync[SHMEM_ALLTOALLS_SYNC_SIZE]; + for (int i = 0; i < SHMEM_ALLTOALLS_SYNC_SIZE; i++) + pSync[i] = SHMEM_SYNC_VALUE; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); - const int count = 2; - const ptrdiff_t dst = 2; - const ptrdiff_t sst = 3; - int64_t* dest = (int64_t*) shmem_malloc(count * dst * npes * sizeof(int64_t)); - int64_t* source = (int64_t*) shmem_malloc(count * sst * npes * sizeof(int64_t)); + const int count = 2; + const ptrdiff_t dst = 2; + const ptrdiff_t sst = 3; + int64_t *dest = (int64_t *)shmem_malloc(count * dst * npes * sizeof(int64_t)); + int64_t *source = + (int64_t *)shmem_malloc(count * sst * npes * sizeof(int64_t)); - /* assign source values */ - for (int pe = 0; pe < npes; pe++) { - for (int i = 0; i < count; i++) { - source[sst * ((pe * count) + i)] = me + pe; - dest[dst * ((pe * count) + i)] = 9999; - } - } - /* wait for all PEs to update source/dest */ - shmem_barrier_all(); + /* assign source values */ + for (int pe = 0; pe < npes; pe++) { + for (int i = 0; i < count; i++) { + source[sst * ((pe * count) + i)] = me + pe; + dest[dst * ((pe * count) + i)] = 9999; + } + } + /* wait for all PEs to update source/dest */ + shmem_barrier_all(); - /* alltoalls on all PES */ - shmem_alltoalls64(dest, source, dst, sst, count, 0, 0, npes, pSync); + /* alltoalls on all PES */ + shmem_alltoalls64(dest, source, dst, sst, count, 0, 0, npes, pSync); - /* verify results */ - for (int pe = 0; pe < npes; pe++) { - for (int i = 0; i < count; i++) { - int j = dst * ((pe * count) + i); - if (dest[j] != pe + me) { - printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", - me, j, dest[j], pe + me); - } - } - } + /* verify results */ + for (int pe = 0; pe < npes; pe++) { + for (int i = 0; i < count; i++) { + int j = dst * ((pe * count) + i); + if (dest[j] != pe + me) { + printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", me, j, + dest[j], pe + me); + } + } + } - shmem_free(dest); - shmem_free(source); - shmem_finalize(); - return 0; + shmem_free(dest); + shmem_free(source); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_atomic_add_example.c b/example_code/shmem_atomic_add_example.c index 022b8ecfc..11a7ab9df 100644 --- a/example_code/shmem_atomic_add_example.c +++ b/example_code/shmem_atomic_add_example.c @@ -1,15 +1,14 @@ -#include #include +#include -int main(void) -{ - static int dst = 22; - shmem_init(); - int me = shmem_my_pe(); - if (me == 1) - shmem_atomic_add(&dst, 44, 0); - shmem_barrier_all(); - printf("%d: dst = %d\n", me, dst); - shmem_finalize(); - return 0; +int main(void) { + static int dst = 22; + shmem_init(); + int me = shmem_my_pe(); + if (me == 1) + shmem_atomic_add(&dst, 44, 0); + shmem_barrier_all(); + printf("%d: dst = %d\n", me, dst); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_atomic_compare_swap_example.c b/example_code/shmem_atomic_compare_swap_example.c index a3b7743fb..297b4ac72 100644 --- a/example_code/shmem_atomic_compare_swap_example.c +++ b/example_code/shmem_atomic_compare_swap_example.c @@ -1,13 +1,13 @@ -#include #include +#include -int main(void) -{ - static int race_winner = -1; - shmem_init(); - int me = shmem_my_pe(); - int oldval = shmem_atomic_compare_swap(&race_winner, -1, me, 0); - if (oldval == -1) printf("PE %d was first\n", me); - shmem_finalize(); - return 0; +int main(void) { + static int race_winner = -1; + shmem_init(); + int me = shmem_my_pe(); + int oldval = shmem_atomic_compare_swap(&race_winner, -1, me, 0); + if (oldval == -1) + printf("PE %d was first\n", me); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_atomic_fetch_add_example.c b/example_code/shmem_atomic_fetch_add_example.c index 21a32cc5b..770cac006 100644 --- a/example_code/shmem_atomic_fetch_add_example.c +++ b/example_code/shmem_atomic_fetch_add_example.c @@ -1,16 +1,15 @@ -#include #include +#include -int main(void) -{ - int old = -1; - static int dst = 22; - shmem_init(); - int me = shmem_my_pe(); - if (me == 1) - old = shmem_atomic_fetch_add(&dst, 44, 0); - shmem_barrier_all(); - printf("%d: old = %d, dst = %d\n", me, old, dst); - shmem_finalize(); - return 0; +int main(void) { + int old = -1; + static int dst = 22; + shmem_init(); + int me = shmem_my_pe(); + if (me == 1) + old = shmem_atomic_fetch_add(&dst, 44, 0); + shmem_barrier_all(); + printf("%d: old = %d, dst = %d\n", me, old, dst); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_atomic_fetch_inc_example.c b/example_code/shmem_atomic_fetch_inc_example.c index f064136a4..2149ef017 100644 --- a/example_code/shmem_atomic_fetch_inc_example.c +++ b/example_code/shmem_atomic_fetch_inc_example.c @@ -1,16 +1,15 @@ -#include #include +#include -int main(void) -{ - int old = -1; - static int dst = 22; - shmem_init(); - int me = shmem_my_pe(); - if (me == 0) - old = shmem_atomic_fetch_inc(&dst, 1); - shmem_barrier_all(); - printf("%d: old = %d, dst = %d\n", me, old, dst); - shmem_finalize(); - return 0; +int main(void) { + int old = -1; + static int dst = 22; + shmem_init(); + int me = shmem_my_pe(); + if (me == 0) + old = shmem_atomic_fetch_inc(&dst, 1); + shmem_barrier_all(); + printf("%d: old = %d, dst = %d\n", me, old, dst); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_atomic_inc_example.c b/example_code/shmem_atomic_inc_example.c index a51f59d0e..a514b0df8 100644 --- a/example_code/shmem_atomic_inc_example.c +++ b/example_code/shmem_atomic_inc_example.c @@ -1,15 +1,14 @@ -#include #include +#include -int main(void) -{ - static int dst = 74; - shmem_init(); - int me = shmem_my_pe(); - if (me == 0) - shmem_atomic_inc(&dst, 1); - shmem_barrier_all(); - printf("%d: dst = %d\n", me, dst); - shmem_finalize(); - return 0; +int main(void) { + static int dst = 74; + shmem_init(); + int me = shmem_my_pe(); + if (me == 0) + shmem_atomic_inc(&dst, 1); + shmem_barrier_all(); + printf("%d: dst = %d\n", me, dst); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_atomic_swap_example.c b/example_code/shmem_atomic_swap_example.c index ac817271d..b941107da 100644 --- a/example_code/shmem_atomic_swap_example.c +++ b/example_code/shmem_atomic_swap_example.c @@ -1,19 +1,18 @@ -#include #include +#include -int main(void) -{ - static long dest; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); - dest = me; - shmem_barrier_all(); - long new_val = me; - if (me & 1) { - long swapped_val = shmem_atomic_swap(&dest, new_val, (me + 1) % npes); - printf("%d: dest = %ld, swapped = %ld\n", me, dest, swapped_val); - } - shmem_finalize(); - return 0; +int main(void) { + static long dest; + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); + dest = me; + shmem_barrier_all(); + long new_val = me; + if (me & 1) { + long swapped_val = shmem_atomic_swap(&dest, new_val, (me + 1) % npes); + printf("%d: dest = %ld, swapped = %ld\n", me, dest, swapped_val); + } + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_barrier_example.c b/example_code/shmem_barrier_example.c index 5fa27bec4..1aaece3f7 100644 --- a/example_code/shmem_barrier_example.c +++ b/example_code/shmem_barrier_example.c @@ -1,24 +1,23 @@ -#include #include +#include -int main(void) -{ - static int x = 10101; - static long pSync[SHMEM_BARRIER_SYNC_SIZE]; - for (int i = 0; i < SHMEM_BARRIER_SYNC_SIZE; i++) - pSync[i] = SHMEM_SYNC_VALUE; +int main(void) { + static int x = 10101; + static long pSync[SHMEM_BARRIER_SYNC_SIZE]; + for (int i = 0; i < SHMEM_BARRIER_SYNC_SIZE; i++) + pSync[i] = SHMEM_SYNC_VALUE; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); - if (me % 2 == 0) { - /* put to next even PE in a circular fashion */ - shmem_p(&x, 4, (me + 2) % npes); - /* synchronize all even pes */ - shmem_barrier(0, 1, (npes / 2 + npes % 2), pSync); - } - printf("%d: x = %d\n", me, x); - shmem_finalize(); - return 0; + if (me % 2 == 0) { + /* put to next even PE in a circular fashion */ + shmem_p(&x, 4, (me + 2) % npes); + /* synchronize all even pes */ + shmem_barrier(0, 1, (npes / 2 + npes % 2), pSync); + } + printf("%d: x = %d\n", me, x); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_barrierall_example.c b/example_code/shmem_barrierall_example.c index bf23be573..b34872719 100644 --- a/example_code/shmem_barrierall_example.c +++ b/example_code/shmem_barrierall_example.c @@ -1,20 +1,19 @@ -#include #include +#include -int main(void) -{ - static int x = 1010; +int main(void) { + static int x = 1010; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); - /* put to next PE in a circular fashion */ - shmem_p(&x, 4, (me + 1) % npes); + /* put to next PE in a circular fashion */ + shmem_p(&x, 4, (me + 1) % npes); - /* synchronize all PEs */ - shmem_barrier_all(); - printf("%d: x = %d\n", me, x); - shmem_finalize(); - return 0; + /* synchronize all PEs */ + shmem_barrier_all(); + printf("%d: x = %d\n", me, x); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_broadcast_example.c b/example_code/shmem_broadcast_example.c index a829448ea..fada7efe2 100644 --- a/example_code/shmem_broadcast_example.c +++ b/example_code/shmem_broadcast_example.c @@ -1,24 +1,23 @@ +#include #include #include -#include -int main(void) -{ - static long pSync[SHMEM_BCAST_SYNC_SIZE]; - for (int i = 0; i < SHMEM_BCAST_SYNC_SIZE; i++) - pSync[i] = SHMEM_SYNC_VALUE; - static long source[4], dest[4]; +int main(void) { + static long pSync[SHMEM_BCAST_SYNC_SIZE]; + for (int i = 0; i < SHMEM_BCAST_SYNC_SIZE; i++) + pSync[i] = SHMEM_SYNC_VALUE; + static long source[4], dest[4]; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); - if (me == 0) - for (int i = 0; i < 4; i++) - source[i] = i; + if (me == 0) + for (int i = 0; i < 4; i++) + source[i] = i; - shmem_broadcast64(dest, source, 4, 0, 0, 0, npes, pSync); - printf("%d: %ld, %ld, %ld, %ld\n", me, dest[0], dest[1], dest[2], dest[3]); - shmem_finalize(); - return 0; + shmem_broadcast64(dest, source, 4, 0, 0, 0, npes, pSync); + printf("%d: %ld, %ld, %ld, %ld\n", me, dest[0], dest[1], dest[2], dest[3]); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_collect_example.c b/example_code/shmem_collect_example.c index b73733368..b5e51e1b4 100644 --- a/example_code/shmem_collect_example.c +++ b/example_code/shmem_collect_example.c @@ -1,38 +1,37 @@ +#include #include #include -#include -int main(void) -{ - static long lock = 0; - static long pSync[SHMEM_COLLECT_SYNC_SIZE]; - for (int i = 0; i < SHMEM_COLLECT_SYNC_SIZE; i++) - pSync[i] = SHMEM_SYNC_VALUE; +int main(void) { + static long lock = 0; + static long pSync[SHMEM_COLLECT_SYNC_SIZE]; + for (int i = 0; i < SHMEM_COLLECT_SYNC_SIZE; i++) + pSync[i] = SHMEM_SYNC_VALUE; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); - int my_nelem = me + 1; /* linearly increasing number of elements with PE */ - int total_nelem = (npes * (npes + 1)) / 2; + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); + int my_nelem = me + 1; /* linearly increasing number of elements with PE */ + int total_nelem = (npes * (npes + 1)) / 2; - int* source = (int*) shmem_malloc(npes*sizeof(int)); /* symmetric alloc */ - int* dest = (int*) shmem_malloc(total_nelem*sizeof(int)); + int *source = (int *)shmem_malloc(npes * sizeof(int)); /* symmetric alloc */ + int *dest = (int *)shmem_malloc(total_nelem * sizeof(int)); - for (int i = 0; i < my_nelem; i++) - source[i] = (me * (me + 1)) / 2 + i; - for (int i = 0; i < total_nelem; i++) - dest[i] = -9999; + for (int i = 0; i < my_nelem; i++) + source[i] = (me * (me + 1)) / 2 + i; + for (int i = 0; i < total_nelem; i++) + dest[i] = -9999; - shmem_barrier_all(); /* Wait for all PEs to update source/dest */ + shmem_barrier_all(); /* Wait for all PEs to update source/dest */ - shmem_collect32(dest, source, my_nelem, 0, 0, npes, pSync); + shmem_collect32(dest, source, my_nelem, 0, 0, npes, pSync); - shmem_set_lock(&lock); /* Lock prevents interleaving printfs */ - printf("%d: %d", me, dest[0]); - for (int i = 1; i < total_nelem; i++) - printf(", %d", dest[i]); - printf("\n"); - shmem_clear_lock(&lock); - shmem_finalize(); - return 0; + shmem_set_lock(&lock); /* Lock prevents interleaving printfs */ + printf("%d: %d", me, dest[0]); + for (int i = 1; i < total_nelem; i++) + printf(", %d", dest[i]); + printf("\n"); + shmem_clear_lock(&lock); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_ctx.c b/example_code/shmem_ctx.c index 61837f8f5..db65896da 100644 --- a/example_code/shmem_ctx.c +++ b/example_code/shmem_ctx.c @@ -1,56 +1,57 @@ -#include #include +#include long pwrk[SHMEM_REDUCE_MIN_WRKDATA_SIZE]; long psync[SHMEM_REDUCE_SYNC_SIZE]; -long task_cntr = 0; /* Next task counter */ +long task_cntr = 0; /* Next task counter */ long tasks_done = 0; /* Tasks done by this PE */ long total_done = 0; /* Total tasks done by all PEs */ int main(void) { - int tl, i; - long ntasks = 1024; /* Total tasks per PE */ - - for (i = 0; i < SHMEM_REDUCE_SYNC_SIZE; i++) - psync[i] = SHMEM_SYNC_VALUE; - - shmem_init_thread(SHMEM_THREAD_MULTIPLE, &tl); - if (tl != SHMEM_THREAD_MULTIPLE) shmem_global_exit(1); - - int me = shmem_my_pe(); - int npes = shmem_n_pes(); - -#pragma omp parallel reduction (+:tasks_done) - { - shmem_ctx_t ctx; - int task_pe = me, pes_done = 0; - int ret = shmem_ctx_create(SHMEM_CTX_PRIVATE, &ctx); - - if (ret != 0) { - printf("%d: Error creating context (%d)\n", me, ret); - shmem_global_exit(2); - } - - /* Process tasks on all PEs, starting with the local PE. After - * all tasks on a PE are completed, help the next PE. */ - while (pes_done < npes) { - long task = shmem_atomic_fetch_inc(ctx, &task_cntr, task_pe); - while (task < ntasks) { - /* Perform task (task_pe, task) */ - tasks_done++; - task = shmem_atomic_fetch_inc(ctx, &task_cntr, task_pe); - } - pes_done++; - task_pe = (task_pe + 1) % npes; - } - - shmem_ctx_destroy(ctx); + int tl, i; + long ntasks = 1024; /* Total tasks per PE */ + + for (i = 0; i < SHMEM_REDUCE_SYNC_SIZE; i++) + psync[i] = SHMEM_SYNC_VALUE; + + shmem_init_thread(SHMEM_THREAD_MULTIPLE, &tl); + if (tl != SHMEM_THREAD_MULTIPLE) + shmem_global_exit(1); + + int me = shmem_my_pe(); + int npes = shmem_n_pes(); + +#pragma omp parallel reduction(+ : tasks_done) + { + shmem_ctx_t ctx; + int task_pe = me, pes_done = 0; + int ret = shmem_ctx_create(SHMEM_CTX_PRIVATE, &ctx); + + if (ret != 0) { + printf("%d: Error creating context (%d)\n", me, ret); + shmem_global_exit(2); } - shmem_long_sum_to_all(&total_done, &tasks_done, 1, 0, 0, npes, pwrk, psync); + /* Process tasks on all PEs, starting with the local PE. After + * all tasks on a PE are completed, help the next PE. */ + while (pes_done < npes) { + long task = shmem_atomic_fetch_inc(ctx, &task_cntr, task_pe); + while (task < ntasks) { + /* Perform task (task_pe, task) */ + tasks_done++; + task = shmem_atomic_fetch_inc(ctx, &task_cntr, task_pe); + } + pes_done++; + task_pe = (task_pe + 1) % npes; + } + + shmem_ctx_destroy(ctx); + } + + shmem_long_sum_to_all(&total_done, &tasks_done, 1, 0, 0, npes, pwrk, psync); - int result = (total_done != ntasks * npes); - shmem_finalize(); - return result; + int result = (total_done != ntasks * npes); + shmem_finalize(); + return result; } diff --git a/example_code/shmem_ctx_pipelined_reduce.c b/example_code/shmem_ctx_pipelined_reduce.c index c21d7ff89..b95ca5bbc 100644 --- a/example_code/shmem_ctx_pipelined_reduce.c +++ b/example_code/shmem_ctx_pipelined_reduce.c @@ -1,56 +1,60 @@ +#include #include #include -#include -#define LEN 8192 /* Full buffer length */ -#define PLEN 512 /* Length of each pipeline stage */ +#define LEN 8192 /* Full buffer length */ +#define PLEN 512 /* Length of each pipeline stage */ int in_buf[LEN], out_buf[LEN]; int main(void) { - int i, j, *pbuf[2]; - shmem_ctx_t ctx[2]; - - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); - - pbuf[0] = shmem_malloc(PLEN * npes * sizeof(int)); - pbuf[1] = shmem_malloc(PLEN * npes * sizeof(int)); - - int ret_0 = shmem_ctx_create(0, &ctx[0]); - int ret_1 = shmem_ctx_create(0, &ctx[1]); - if (ret_0 || ret_1) shmem_global_exit(1); - - for (i = 0; i < LEN; i++) { - in_buf[i] = me; out_buf[i] = 0; - } - - int p_idx = 0, p = 0; /* Index of ctx and pbuf (p_idx) for current pipeline stage (p) */ + int i, j, *pbuf[2]; + shmem_ctx_t ctx[2]; + + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); + + pbuf[0] = shmem_malloc(PLEN * npes * sizeof(int)); + pbuf[1] = shmem_malloc(PLEN * npes * sizeof(int)); + + int ret_0 = shmem_ctx_create(0, &ctx[0]); + int ret_1 = shmem_ctx_create(0, &ctx[1]); + if (ret_0 || ret_1) + shmem_global_exit(1); + + for (i = 0; i < LEN; i++) { + in_buf[i] = me; + out_buf[i] = 0; + } + + int p_idx = 0, + p = 0; /* Index of ctx and pbuf (p_idx) for current pipeline stage (p) */ + for (i = 1; i <= npes; i++) + shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * me], &in_buf[PLEN * p], PLEN, + (me + i) % npes); + + /* Issue communication for pipeline stage p, then accumulate results for stage + * p-1 */ + for (p = 1; p < LEN / PLEN; p++) { + p_idx ^= 1; for (i = 1; i <= npes; i++) - shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN*me], &in_buf[PLEN*p], - PLEN, (me+i) % npes); - - /* Issue communication for pipeline stage p, then accumulate results for stage p-1 */ - for (p = 1; p < LEN/PLEN; p++) { - p_idx ^= 1; - for (i = 1; i <= npes; i++) - shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN*me], &in_buf[PLEN*p], - PLEN, (me+i) % npes); - - shmem_ctx_quiet(ctx[p_idx^1]); - shmem_sync_all(); - for (i = 0; i < npes; i++) - for (j = 0; j < PLEN; j++) - out_buf[PLEN*(p-1)+j] += pbuf[p_idx^1][PLEN*i+j]; - } - - shmem_ctx_quiet(ctx[p_idx]); + shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * me], &in_buf[PLEN * p], + PLEN, (me + i) % npes); + + shmem_ctx_quiet(ctx[p_idx ^ 1]); shmem_sync_all(); for (i = 0; i < npes; i++) - for (j = 0; j < PLEN; j++) - out_buf[PLEN*(p-1)+j] += pbuf[p_idx][PLEN*i+j]; - - shmem_finalize(); - return 0; + for (j = 0; j < PLEN; j++) + out_buf[PLEN * (p - 1) + j] += pbuf[p_idx ^ 1][PLEN * i + j]; + } + + shmem_ctx_quiet(ctx[p_idx]); + shmem_sync_all(); + for (i = 0; i < npes; i++) + for (j = 0; j < PLEN; j++) + out_buf[PLEN * (p - 1) + j] += pbuf[p_idx][PLEN * i + j]; + + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_fence_example.c b/example_code/shmem_fence_example.c index 3f72c8fb1..f17ccb68f 100644 --- a/example_code/shmem_fence_example.c +++ b/example_code/shmem_fence_example.c @@ -1,23 +1,22 @@ -#include #include +#include -int main(void) -{ - int src = 99; - long source[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - static long dest[10]; - static int targ; - shmem_init(); - int me = shmem_my_pe(); - if (me == 0) { - shmem_put(dest, source, 10, 1); /* put1 */ - shmem_put(dest, source, 10, 2); /* put2 */ - shmem_fence(); - shmem_put(&targ, &src, 1, 1); /* put3 */ - shmem_put(&targ, &src, 1, 2); /* put4 */ - } - shmem_barrier_all(); /* sync sender and receiver */ - printf("dest[0] on PE %d is %ld\n", me, dest[0]); - shmem_finalize(); - return 0; +int main(void) { + int src = 99; + long source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + static long dest[10]; + static int targ; + shmem_init(); + int me = shmem_my_pe(); + if (me == 0) { + shmem_put(dest, source, 10, 1); /* put1 */ + shmem_put(dest, source, 10, 2); /* put2 */ + shmem_fence(); + shmem_put(&targ, &src, 1, 1); /* put3 */ + shmem_put(&targ, &src, 1, 2); /* put4 */ + } + shmem_barrier_all(); /* sync sender and receiver */ + printf("dest[0] on PE %d is %ld\n", me, dest[0]); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_finalize_example.c b/example_code/shmem_finalize_example.c index 26d7860ea..6ed2c06be 100644 --- a/example_code/shmem_finalize_example.c +++ b/example_code/shmem_finalize_example.c @@ -1,20 +1,19 @@ +#include #include -#include -int main(void) -{ - static long x = 10101; - long y = -1; +int main(void) { + static long x = 10101; + long y = -1; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); - if (me == 0) - y = shmem_g(&x, npes-1); + if (me == 0) + y = shmem_g(&x, npes - 1); - printf("%d: y = %ld\n", me, y); + printf("%d: y = %ld\n", me, y); - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_g_example.c b/example_code/shmem_g_example.c index f1f49ee38..cc11b48b9 100644 --- a/example_code/shmem_g_example.c +++ b/example_code/shmem_g_example.c @@ -1,16 +1,15 @@ -#include #include +#include -int main(void) -{ - long y = -1; - static long x = 10101; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); - if (me == 0) - y = shmem_g(&x, npes-1); - printf("%d: y = %ld\n", me, y); - shmem_finalize(); - return 0; +int main(void) { + long y = -1; + static long x = 10101; + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); + if (me == 0) + y = shmem_g(&x, npes - 1); + printf("%d: y = %ld\n", me, y); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_global_exit_example.c b/example_code/shmem_global_exit_example.c index a3c21e379..b88af2977 100644 --- a/example_code/shmem_global_exit_example.c +++ b/example_code/shmem_global_exit_example.c @@ -1,18 +1,17 @@ +#include #include #include -#include -int main(void) -{ - shmem_init(); - int me = shmem_my_pe(); - if (me == 0) { - FILE *fp = fopen("input.txt", "r"); - if (fp == NULL) { /* Input file required by program is not available */ - shmem_global_exit(EXIT_FAILURE); - } - /* do something with the file */ - fclose(fp); +int main(void) { + shmem_init(); + int me = shmem_my_pe(); + if (me == 0) { + FILE *fp = fopen("input.txt", "r"); + if (fp == NULL) { /* Input file required by program is not available */ + shmem_global_exit(EXIT_FAILURE); + } + /* do something with the file */ + fclose(fp); } shmem_finalize(); return 0; diff --git a/example_code/shmem_init_example.c b/example_code/shmem_init_example.c index e3192e9ff..3662f28b5 100644 --- a/example_code/shmem_init_example.c +++ b/example_code/shmem_init_example.c @@ -1,23 +1,23 @@ -#include #include +#include int main(void) { - static int targ = 0; + static int targ = 0; - shmem_init(); - int me = shmem_my_pe(); - int receiver = 1 % shmem_n_pes(); + shmem_init(); + int me = shmem_my_pe(); + int receiver = 1 % shmem_n_pes(); - if (me == 0) { - int src = 33; - shmem_put(&targ, &src, 1, receiver); - } + if (me == 0) { + int src = 33; + shmem_put(&targ, &src, 1, receiver); + } - shmem_barrier_all(); /* Synchronizes sender and receiver */ + shmem_barrier_all(); /* Synchronizes sender and receiver */ - if (me == receiver) - printf("PE %d targ=%d (expect 33)\n", me, targ); + if (me == receiver) + printf("PE %d targ=%d (expect 33)\n", me, targ); - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_iput_example.c b/example_code/shmem_iput_example.c index 101533563..00a50bace 100644 --- a/example_code/shmem_iput_example.c +++ b/example_code/shmem_iput_example.c @@ -1,19 +1,18 @@ -#include #include +#include -int main(void) -{ - short source[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - static short dest[10]; - shmem_init(); - int me = shmem_my_pe(); - if (me == 0) /* put 5 elements into dest on PE 1 */ - shmem_iput(dest, source, 1, 2, 5, 1); - shmem_barrier_all(); /* sync sender and receiver */ - if (me == 1) { - printf("dest on PE %d is %hd %hd %hd %hd %hd\n", me, - dest[0], dest[1], dest[2], dest[3], dest[4]); - } - shmem_finalize(); - return 0; +int main(void) { + short source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + static short dest[10]; + shmem_init(); + int me = shmem_my_pe(); + if (me == 0) /* put 5 elements into dest on PE 1 */ + shmem_iput(dest, source, 1, 2, 5, 1); + shmem_barrier_all(); /* sync sender and receiver */ + if (me == 1) { + printf("dest on PE %d is %hd %hd %hd %hd %hd\n", me, dest[0], dest[1], + dest[2], dest[3], dest[4]); + } + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_lock_example.c b/example_code/shmem_lock_example.c index ab2a13fa3..d1bacf1ca 100644 --- a/example_code/shmem_lock_example.c +++ b/example_code/shmem_lock_example.c @@ -1,19 +1,18 @@ -#include #include +#include -int main(void) -{ - static long lock = 0; - static int count = 0; - shmem_init(); - int me = shmem_my_pe(); - shmem_set_lock(&lock); - int val = shmem_g(&count, 0); /* get count value on PE 0 */ - printf("%d: count is %d\n", me, val); - val++; /* incrementing and updating count on PE 0 */ - shmem_p(&count, val, 0); - shmem_quiet(); - shmem_clear_lock(&lock); - shmem_finalize(); - return 0; +int main(void) { + static long lock = 0; + static int count = 0; + shmem_init(); + int me = shmem_my_pe(); + shmem_set_lock(&lock); + int val = shmem_g(&count, 0); /* get count value on PE 0 */ + printf("%d: count is %d\n", me, val); + val++; /* incrementing and updating count on PE 0 */ + shmem_p(&count, val, 0); + shmem_quiet(); + shmem_clear_lock(&lock); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_npes_example.c b/example_code/shmem_npes_example.c index 6c6812841..4da650d0b 100644 --- a/example_code/shmem_npes_example.c +++ b/example_code/shmem_npes_example.c @@ -1,12 +1,11 @@ -#include #include +#include -int main(void) -{ - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); - printf("I am #%d of %d PEs executing this program\n", me, npes); - shmem_finalize(); - return 0; +int main(void) { + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); + printf("I am #%d of %d PEs executing this program\n", me, npes); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_p_example.c b/example_code/shmem_p_example.c index 8ebfd4e61..467096583 100644 --- a/example_code/shmem_p_example.c +++ b/example_code/shmem_p_example.c @@ -1,19 +1,18 @@ -#include #include #include +#include -int main(void) -{ - const double e = 2.71828182; - const double epsilon = 0.00000001; - static double f = 3.1415927; - shmem_init(); - int me = shmem_my_pe(); - if (me == 0) - shmem_p(&f, e, 1); - shmem_barrier_all(); - if (me == 1) - printf("%s\n", (fabs(f - e) < epsilon) ? "OK" : "FAIL"); - shmem_finalize(); - return 0; +int main(void) { + const double e = 2.71828182; + const double epsilon = 0.00000001; + static double f = 3.1415927; + shmem_init(); + int me = shmem_my_pe(); + if (me == 0) + shmem_p(&f, e, 1); + shmem_barrier_all(); + if (me == 1) + printf("%s\n", (fabs(f - e) < epsilon) ? "OK" : "FAIL"); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_ptr_example.c b/example_code/shmem_ptr_example.c index 9ac26ca4d..c78863de0 100644 --- a/example_code/shmem_ptr_example.c +++ b/example_code/shmem_ptr_example.c @@ -1,23 +1,21 @@ -#include #include +#include -int main(void) -{ - static int dest[4]; - shmem_init(); - int me = shmem_my_pe(); - if (me == 0) { /* initialize PE 1's dest array */ - int* ptr = shmem_ptr(dest, 1); - if (ptr == NULL) - printf("can't use pointer to directly access PE 1's dest array\n"); - else - for (int i = 0; i < 4; i++) - *ptr++ = i + 1; - } - shmem_barrier_all(); - if (me == 1) - printf("PE 1 dest: %d, %d, %d, %d\n", - dest[0], dest[1], dest[2], dest[3]); - shmem_finalize(); - return 0; +int main(void) { + static int dest[4]; + shmem_init(); + int me = shmem_my_pe(); + if (me == 0) { /* initialize PE 1's dest array */ + int *ptr = shmem_ptr(dest, 1); + if (ptr == NULL) + printf("can't use pointer to directly access PE 1's dest array\n"); + else + for (int i = 0; i < 4; i++) + *ptr++ = i + 1; + } + shmem_barrier_all(); + if (me == 1) + printf("PE 1 dest: %d, %d, %d, %d\n", dest[0], dest[1], dest[2], dest[3]); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_put_example.c b/example_code/shmem_put_example.c index a5f6ffb44..5eea5f4cd 100644 --- a/example_code/shmem_put_example.c +++ b/example_code/shmem_put_example.c @@ -1,16 +1,15 @@ -#include #include +#include -int main(void) -{ - long source[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - static long dest[10]; - shmem_init(); - int me = shmem_my_pe(); - if (me == 0) /* put 10 words into dest on PE 1 */ - shmem_put(dest, source, 10, 1); - shmem_barrier_all(); /* sync sender and receiver */ - printf("dest[0] on PE %d is %ld\n", me, dest[0]); - shmem_finalize(); - return 0; +int main(void) { + long source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + static long dest[10]; + shmem_init(); + int me = shmem_my_pe(); + if (me == 0) /* put 10 words into dest on PE 1 */ + shmem_put(dest, source, 10, 1); + shmem_barrier_all(); /* sync sender and receiver */ + printf("dest[0] on PE %d is %ld\n", me, dest[0]); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_quiet_example.c b/example_code/shmem_quiet_example.c index a23163eb0..09e771a4e 100644 --- a/example_code/shmem_quiet_example.c +++ b/example_code/shmem_quiet_example.c @@ -1,27 +1,28 @@ -#include #include +#include -int main(void) -{ - static long dest[3]; - static long source[3] = { 1, 2, 3 }; - static int targ; - static int src = 90; - long x[3] = { 0 }; - int y = 0; - shmem_init(); - int me = shmem_my_pe(); - if (me == 0) { - shmem_put(dest, source, 3, 1); /* put1 */ - shmem_put(&targ, &src, 1, 2); /* put2 */ - shmem_quiet(); - shmem_get(x, dest, 3, 1); /* gets updated value from dest on PE 1 to local array x */ - shmem_get(&y, &targ, 1, 2); /* gets updated value from targ on PE 2 to local variable y */ - printf("x: { %ld, %ld, %ld }\n", x[0], x[1], x[2]); /* x: { 1, 2, 3 } */ - printf("y: %d\n", y); /* y: 90 */ - shmem_put(&targ, &src, 1, 1); /* put3 */ - shmem_put(&targ, &src, 1, 2); /* put4 */ - } - shmem_finalize(); - return 0; +int main(void) { + static long dest[3]; + static long source[3] = {1, 2, 3}; + static int targ; + static int src = 90; + long x[3] = {0}; + int y = 0; + shmem_init(); + int me = shmem_my_pe(); + if (me == 0) { + shmem_put(dest, source, 3, 1); /* put1 */ + shmem_put(&targ, &src, 1, 2); /* put2 */ + shmem_quiet(); + shmem_get(x, dest, 3, + 1); /* gets updated value from dest on PE 1 to local array x */ + shmem_get(&y, &targ, 1, + 2); /* gets updated value from targ on PE 2 to local variable y */ + printf("x: { %ld, %ld, %ld }\n", x[0], x[1], x[2]); /* x: { 1, 2, 3 } */ + printf("y: %d\n", y); /* y: 90 */ + shmem_put(&targ, &src, 1, 1); /* put3 */ + shmem_put(&targ, &src, 1, 2); /* put4 */ + } + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_sync_example.c b/example_code/shmem_sync_example.c index 8c447beee..85a9851c4 100644 --- a/example_code/shmem_sync_example.c +++ b/example_code/shmem_sync_example.c @@ -1,28 +1,27 @@ -#include #include +#include -int main(void) -{ - static int x = 10101; - static long pSync[SHMEM_BARRIER_SYNC_SIZE]; +int main(void) { + static int x = 10101; + static long pSync[SHMEM_BARRIER_SYNC_SIZE]; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); - for (int i = 0; i < SHMEM_BARRIER_SYNC_SIZE; i++) - pSync[i] = SHMEM_SYNC_VALUE; + for (int i = 0; i < SHMEM_BARRIER_SYNC_SIZE; i++) + pSync[i] = SHMEM_SYNC_VALUE; - shmem_sync_all(); + shmem_sync_all(); - if (me % 2 == 0) { - /* put to next even PE in a circular fashion */ - shmem_p(&x, 4, (me + 2) % npes); - /* synchronize all even pes */ - shmem_quiet(); - shmem_sync(0, 1, (npes / 2 + npes % 2), pSync); - } - printf("%d: x = %d\n", me, x); - shmem_finalize(); - return 0; + if (me % 2 == 0) { + /* put to next even PE in a circular fashion */ + shmem_p(&x, 4, (me + 2) % npes); + /* synchronize all even pes */ + shmem_quiet(); + shmem_sync(0, 1, (npes / 2 + npes % 2), pSync); + } + printf("%d: x = %d\n", me, x); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_test_example1.c b/example_code/shmem_test_example1.c index d3f760f44..95d30244a 100644 --- a/example_code/shmem_test_example1.c +++ b/example_code/shmem_test_example1.c @@ -1,27 +1,23 @@ -#include #include +#include -int user_wait_any(long *ivar, int count, int cmp, long value) -{ +int user_wait_any(long *ivar, int count, int cmp, long value) { int idx = 0; while (!shmem_test(&ivar[idx], cmp, value)) idx = (idx + 1) % count; return idx; } -int main(void) -{ +int main(void) { shmem_init(); const int mype = shmem_my_pe(); const int npes = shmem_n_pes(); long *wait_vars = shmem_calloc(npes, sizeof(long)); - if (mype == 0) - { + if (mype == 0) { int who = user_wait_any(wait_vars, npes, SHMEM_CMP_NE, 0); printf("PE %d observed first update from PE %d\n", mype, who); - } - else + } else shmem_p(&wait_vars[mype], mype, 0); shmem_free(wait_vars); diff --git a/example_code/shmem_wait3_example.c b/example_code/shmem_wait3_example.c index 4b4608215..78864971b 100644 --- a/example_code/shmem_wait3_example.c +++ b/example_code/shmem_wait3_example.c @@ -1,5 +1,5 @@ -#include #include +#include int ivar; shmem_int_wait_until(&ivar, SHMEM_CMP_LT, 0); diff --git a/example_code/writing_shmem_example.c b/example_code/writing_shmem_example.c index e04139e09..4b0f614ea 100644 --- a/example_code/writing_shmem_example.c +++ b/example_code/writing_shmem_example.c @@ -1,35 +1,34 @@ -#include #include +#include #define SIZE 16 -int main(void) -{ - short source[SIZE]; - static short dest[SIZE]; - static long lock = 0; - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); - if (me == 0) { - /* initialize array */ - for (int i = 0; i < SIZE; i++) - source[i] = i; - /* local, not symmetric */ - /* static makes it symmetric */ - /* put "size" words into dest on each PE */ - for (int i = 1; i < npes; i++) - shmem_put(dest, source, SIZE, i); - } - shmem_barrier_all(); /* sync sender and receiver */ - if (me != 0) { - shmem_set_lock(&lock); - printf("dest on PE %d is \t", me); - for (int i = 0; i < SIZE; i++) - printf("%hd \t", dest[i]); - printf("\n"); - shmem_clear_lock(&lock); - } - shmem_finalize(); - return 0; +int main(void) { + short source[SIZE]; + static short dest[SIZE]; + static long lock = 0; + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); + if (me == 0) { + /* initialize array */ + for (int i = 0; i < SIZE; i++) + source[i] = i; + /* local, not symmetric */ + /* static makes it symmetric */ + /* put "size" words into dest on each PE */ + for (int i = 1; i < npes; i++) + shmem_put(dest, source, SIZE, i); + } + shmem_barrier_all(); /* sync sender and receiver */ + if (me != 0) { + shmem_set_lock(&lock); + printf("dest on PE %d is \t", me); + for (int i = 0; i < SIZE; i++) + printf("%hd \t", dest[i]); + printf("\n"); + shmem_clear_lock(&lock); + } + shmem_finalize(); + return 0; } From 558da4f86ef0871a985836c872598e7185c06bd9 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Fri, 3 Aug 2018 17:51:00 -0400 Subject: [PATCH 06/23] improve-examples: Colorized syntax highlighting for C examples --- Makefile | 2 +- utils/defs.tex | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0a48e04d4..60aa7a1c1 100644 --- a/Makefile +++ b/Makefile @@ -15,5 +15,5 @@ ${TARGET}.pdf: ${SOURCES} ${FIGURES} ${EXAMPLES} .PHONY: clean clean: - rm -f ${TARGET}.{log,aux,ps,dvi,bbl,blg,log,idx,out,toc,pdf,out} chappage.txt + rm -f ${TARGET}.{log,aux,ps,dvi,bbl,blg,log,idx,ind,ilg,out,toc,pdf,out} chappage.txt diff --git a/utils/defs.tex b/utils/defs.tex index 89200f12d..ed0b5e82b 100644 --- a/utils/defs.tex +++ b/utils/defs.tex @@ -521,7 +521,32 @@ \end{example} \lstinputlisting[language={C}, tabsize=2, basicstyle=\ttfamily\footnotesize, - morekeywords={size_t, ptrdiff_t, shmem_ctx_t}]{##3} + % Preprocessor directives + classoffset=0, + keywords={\#include, \#pragma, \#if, \#ifdef, \#else, \#endif}, + keywordstyle=\bfseries\color{CadetBlue}, + % Language keywords + classoffset=1, + keywords={if, else, for, while, return, break, static, const, volatile, + sizeof}, + keywordstyle=\bfseries\color{Orchid}, + % Types + classoffset=2, + keywords={void, bool, _Bool, unsigned, char, short, int, long, + float, double, _Complex, complex, size_t, ptrdiff_t, shmem_ctx_t, + int8_t, int16_t, int32_t, int64_t, + uint8_t, uint16_t, uint32_t, uint64_t}, + keywordstyle=\color{OliveGreen}, + % Other elements + classoffset=3, + keywords={NULL}, + keywordstyle=\color{Cyan}, + % Other syntax elements + classoffset=0, + % morecomment=[s]{\<}{\>}, + commentstyle=\itshape\color{BrickRed}, + stringstyle=\color{DarkOrchid}, + ]{##3} ##4} \newcommand{\apifexample}[4][]{ \begin{example} From 7588935d27c1e74dd40623a243e124f916ac3e6c Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Mon, 3 Feb 2020 16:36:44 -0500 Subject: [PATCH 07/23] Set .clang-format to avoid cuddled else + format examples --- .clang-format | 4 + example_code/amo_scenario_2.c | 20 +-- example_code/amo_scenario_3.c | 27 ++-- example_code/amo_scenario_4.c | 20 +-- example_code/hybrid_mpi_mapping_id.c | 37 +++--- .../hybrid_mpi_mapping_id_shmem_comm.c | 31 +++-- example_code/pshmem_example.c | 30 ++--- example_code/pshmem_no_weak_symbol_1.c | 4 +- example_code/pshmem_no_weak_symbol_2.c | 4 +- example_code/pshmem_weak_symbol_1.c | 4 +- example_code/pshmem_weak_symbol_2.c | 7 +- example_code/shmem_alltoall_example.c | 31 +++-- example_code/shmem_alltoalls_example.c | 31 +++-- example_code/shmem_broadcast_example.c | 13 +- example_code/shmem_collect_example.c | 11 +- example_code/shmem_ctx_invalid.c | 8 +- example_code/shmem_lock_example.c | 28 ++--- example_code/shmem_put_signal_example.c | 48 ++++---- example_code/shmem_reduce_example.c | 18 ++- example_code/shmem_sync_example.c | 116 +++++++++--------- example_code/shmem_team_context.c | 25 ++-- example_code/shmem_team_split_2D.c | 16 +-- example_code/shmem_team_split_strided.c | 39 +++--- example_code/shmem_team_translate_pe.c | 45 ++++--- example_code/shmem_test_any_example.c | 20 +-- example_code/shmem_test_some_example.c | 35 +++--- example_code/shmem_wait_until_all.c | 5 +- .../shmem_wait_until_any_all2all_sum.c | 22 ++-- example_code/shmem_wait_until_any_vector.c | 19 ++- .../shmem_wait_until_some_all2all_sum.c | 25 ++-- 30 files changed, 365 insertions(+), 378 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..46384c277 --- /dev/null +++ b/.clang-format @@ -0,0 +1,4 @@ +BasedOnStyle: LLVM +BreakBeforeBraces: Custom +BraceWrapping: + BeforeElse: true diff --git a/example_code/amo_scenario_2.c b/example_code/amo_scenario_2.c index 0ab058cb8..9b538f40d 100644 --- a/example_code/amo_scenario_2.c +++ b/example_code/amo_scenario_2.c @@ -1,16 +1,16 @@ #include int main(void) { - static uint64_t x = 0; + static uint64_t x = 0; - shmem_init(); - /* Undefined behavior: The following AMOs access the same location concurrently using - * different types. */ - if (shmem_my_pe() > 0) - shmem_uint32_atomic_or((uint32_t*)&x, shmem_my_pe()+1, 0); - else - shmem_uint64_atomic_or(&x, shmem_my_pe()+1, 0); + shmem_init(); + /* Undefined behavior: The following AMOs access the same location + * concurrently using different types. */ + if (shmem_my_pe() > 0) + shmem_uint32_atomic_or((uint32_t *)&x, shmem_my_pe() + 1, 0); + else + shmem_uint64_atomic_or(&x, shmem_my_pe() + 1, 0); - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } diff --git a/example_code/amo_scenario_3.c b/example_code/amo_scenario_3.c index d89b7696f..93586779c 100644 --- a/example_code/amo_scenario_3.c +++ b/example_code/amo_scenario_3.c @@ -1,21 +1,20 @@ #include int main(void) { - static long psync[SHMEM_REDUCE_SYNC_SIZE]; - static int pwrk[SHMEM_REDUCE_MIN_WRKDATA_SIZE]; - static int x = 0, y = 0; + static long psync[SHMEM_REDUCE_SYNC_SIZE]; + static int pwrk[SHMEM_REDUCE_MIN_WRKDATA_SIZE]; + static int x = 0, y = 0; - for (int i = 0; i < SHMEM_REDUCE_SYNC_SIZE; i++) - psync[i] = SHMEM_SYNC_VALUE; + for (int i = 0; i < SHMEM_REDUCE_SYNC_SIZE; i++) + psync[i] = SHMEM_SYNC_VALUE; - shmem_init(); - shmem_int_atomic_inc(&x, (shmem_my_pe()+1) % shmem_n_pes()); - /* Undefined behavior: The following reduction operation performs accesses to symmetric - * variable 'x' that are concurrent with previously issued atomic increment operations - * on the same variable. */ - shmem_int_sum_to_all(&y, &x, 1, 0, 0, shmem_n_pes(), pwrk, psync); + shmem_init(); + shmem_int_atomic_inc(&x, (shmem_my_pe() + 1) % shmem_n_pes()); + /* Undefined behavior: The following reduction operation performs accesses to + * symmetric variable 'x' that are concurrent with previously issued atomic + * increment operations on the same variable. */ + shmem_int_sum_to_all(&y, &x, 1, 0, 0, shmem_n_pes(), pwrk, psync); - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } - diff --git a/example_code/amo_scenario_4.c b/example_code/amo_scenario_4.c index 9c5f16e97..4b0a83f48 100644 --- a/example_code/amo_scenario_4.c +++ b/example_code/amo_scenario_4.c @@ -1,16 +1,16 @@ #include int main(void) { - static int x = 0; + static int x = 0; - shmem_init(); - /* Undefined behavior: OpenSHMEM atomic increment operations are concurrent with the local - * increment of symmetric variable 'x'. */ - if (shmem_my_pe() > 0) - shmem_int_atomic_inc(&x, 0); - else - x++; + shmem_init(); + /* Undefined behavior: OpenSHMEM atomic increment operations are concurrent + * with the local increment of symmetric variable 'x'. */ + if (shmem_my_pe() > 0) + shmem_int_atomic_inc(&x, 0); + else + x++; - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } diff --git a/example_code/hybrid_mpi_mapping_id.c b/example_code/hybrid_mpi_mapping_id.c index e99ff5bcc..4afae6c81 100644 --- a/example_code/hybrid_mpi_mapping_id.c +++ b/example_code/hybrid_mpi_mapping_id.c @@ -1,29 +1,28 @@ -#include -#include #include +#include +#include -int main(int argc, char *argv[]) -{ - MPI_Init(&argc, &argv); - shmem_init(); +int main(int argc, char *argv[]) { + MPI_Init(&argc, &argv); + shmem_init(); - int mype = shmem_team_my_pe(SHMEM_TEAM_WORLD); - int npes = shmem_team_n_pes(SHMEM_TEAM_WORLD); + int mype = shmem_team_my_pe(SHMEM_TEAM_WORLD); + int npes = shmem_team_n_pes(SHMEM_TEAM_WORLD); - static int myrank; - MPI_Comm_rank(MPI_COMM_WORLD, &myrank); + static int myrank; + MPI_Comm_rank(MPI_COMM_WORLD, &myrank); - int *mpi_ranks = shmem_calloc(npes, sizeof(int)); + int *mpi_ranks = shmem_calloc(npes, sizeof(int)); - shmem_int_collect(SHMEM_TEAM_WORLD, mpi_ranks, &myrank, 1); - if (mype == 0) - for (int i = 0; i < npes; i++) - printf("PE %d's MPI rank is %d\n", i, mpi_ranks[i]); + shmem_int_collect(SHMEM_TEAM_WORLD, mpi_ranks, &myrank, 1); + if (mype == 0) + for (int i = 0; i < npes; i++) + printf("PE %d's MPI rank is %d\n", i, mpi_ranks[i]); - shmem_free(mpi_ranks); + shmem_free(mpi_ranks); - shmem_finalize(); - MPI_Finalize(); + shmem_finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/example_code/hybrid_mpi_mapping_id_shmem_comm.c b/example_code/hybrid_mpi_mapping_id_shmem_comm.c index cf2b86809..54a05e98b 100644 --- a/example_code/hybrid_mpi_mapping_id_shmem_comm.c +++ b/example_code/hybrid_mpi_mapping_id_shmem_comm.c @@ -1,24 +1,23 @@ -#include -#include #include +#include +#include -int main(int argc, char *argv[]) -{ - MPI_Init(&argc, &argv); - shmem_init(); +int main(int argc, char *argv[]) { + MPI_Init(&argc, &argv); + shmem_init(); - int mype = shmem_my_pe(); + int mype = shmem_my_pe(); - MPI_Comm shmem_comm; - MPI_Comm_split(MPI_COMM_WORLD, 0, mype, &shmem_comm); + MPI_Comm shmem_comm; + MPI_Comm_split(MPI_COMM_WORLD, 0, mype, &shmem_comm); - int myrank; - MPI_Comm_rank(shmem_comm, &myrank); - printf("PE %d's MPI rank is %d\n", mype, myrank); + int myrank; + MPI_Comm_rank(shmem_comm, &myrank); + printf("PE %d's MPI rank is %d\n", mype, myrank); - MPI_Comm_free(&shmem_comm); - shmem_finalize(); - MPI_Finalize(); + MPI_Comm_free(&shmem_comm); + shmem_finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/example_code/pshmem_example.c b/example_code/pshmem_example.c index 8e14f55f4..37c7678f8 100644 --- a/example_code/pshmem_example.c +++ b/example_code/pshmem_example.c @@ -1,27 +1,27 @@ +#include #include #include -#include static double total_put_time = 0.0; static double avg_put_time = 0.0; static long put_count = 0; static inline double get_wtime(void) { - double wtime = 0.0; - struct timeval tv; - gettimeofday(&tv, NULL); - wtime = tv.tv_sec; - wtime += (double)tv.tv_usec / 1.0e6; - return wtime; + double wtime = 0.0; + struct timeval tv; + gettimeofday(&tv, NULL); + wtime = tv.tv_sec; + wtime += (double)tv.tv_usec / 1.0e6; + return wtime; } -void shmem_long_put(long *dest, const long *source, size_t nelems, int pe) -{ - double t_start = get_wtime(); /* Start timer */ - pshmem_long_put(dest, source, nelems, pe); /* Name shifted call to put */ - total_put_time += get_wtime() - t_start; /* Calculate total time elapsed */ - put_count += 1; /* Increment put counts */ - avg_put_time = total_put_time / (double) put_count; /* Calculate average put latency */ +void shmem_long_put(long *dest, const long *source, size_t nelems, int pe) { + double t_start = get_wtime(); /* Start timer */ + pshmem_long_put(dest, source, nelems, pe); /* Name shifted call to put */ + total_put_time += get_wtime() - t_start; /* Calculate total time elapsed */ + put_count += 1; /* Increment put counts */ + avg_put_time = + total_put_time / (double)put_count; /* Calculate average put latency */ - return; + return; } diff --git a/example_code/pshmem_no_weak_symbol_1.c b/example_code/pshmem_no_weak_symbol_1.c index cde2053c0..3d27025c4 100644 --- a/example_code/pshmem_no_weak_symbol_1.c +++ b/example_code/pshmem_no_weak_symbol_1.c @@ -1,5 +1,5 @@ #ifdef BUILD_PSHMEM_INTERFACES -# define SHFN(fn) p##fn +#define SHFN(fn) p##fn #else -# define SHFN(fn) fn +#define SHFN(fn) fn #endif diff --git a/example_code/pshmem_no_weak_symbol_2.c b/example_code/pshmem_no_weak_symbol_2.c index c4074f773..7d0ae3a43 100644 --- a/example_code/pshmem_no_weak_symbol_2.c +++ b/example_code/pshmem_no_weak_symbol_2.c @@ -1,4 +1,2 @@ -void SHFN(shmem_example)(/* appropriate arguments */) -{ - /* function body */ +void SHFN(shmem_example)(/* appropriate arguments */) { /* function body */ } diff --git a/example_code/pshmem_weak_symbol_1.c b/example_code/pshmem_weak_symbol_1.c index a15e29d62..51182ca0e 100644 --- a/example_code/pshmem_weak_symbol_1.c +++ b/example_code/pshmem_weak_symbol_1.c @@ -1,6 +1,4 @@ #pragma weak shmem_example = pshmem_example -void pshmem_example(/* appropriate arguments */) -{ - /* function body */ +void pshmem_example(/* appropriate arguments */) { /* function body */ } diff --git a/example_code/pshmem_weak_symbol_2.c b/example_code/pshmem_weak_symbol_2.c index dde07c925..b269ceca7 100644 --- a/example_code/pshmem_weak_symbol_2.c +++ b/example_code/pshmem_weak_symbol_2.c @@ -1,6 +1,5 @@ -void pshmem_example(/* appropriate arguments */) -{ - /* function body */ +void pshmem_example(/* appropriate arguments */) { /* function body */ } -void shmem_example(/* appropriate arguments */) __attribute__ ((weak, alias("pshmem_example"))); +void shmem_example(/* appropriate arguments */) + __attribute__((weak, alias("pshmem_example"))); diff --git a/example_code/shmem_alltoall_example.c b/example_code/shmem_alltoall_example.c index 75d488748..6560ae993 100644 --- a/example_code/shmem_alltoall_example.c +++ b/example_code/shmem_alltoall_example.c @@ -2,28 +2,27 @@ #include #include -int main(void) -{ - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); +int main(void) { + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); const int count = 2; int64_t *dest = (int64_t *)shmem_malloc(count * npes * sizeof(int64_t)); int64_t *source = (int64_t *)shmem_malloc(count * npes * sizeof(int64_t)); - /* assign source values */ - for (int pe = 0; pe < npes; pe++) { - for (int i = 0; i < count; i++) { - source[(pe * count) + i] = me + pe; - dest[(pe * count) + i] = 9999; - } - } - /* wait for all PEs to initialize source/dest */ - shmem_team_sync(SHMEM_TEAM_WORLD); + /* assign source values */ + for (int pe = 0; pe < npes; pe++) { + for (int i = 0; i < count; i++) { + source[(pe * count) + i] = me + pe; + dest[(pe * count) + i] = 9999; + } + } + /* wait for all PEs to initialize source/dest */ + shmem_team_sync(SHMEM_TEAM_WORLD); - /* alltoall on all PES */ - shmem_int64_alltoall(SHMEM_TEAM_WORLD, dest, source, count); + /* alltoall on all PES */ + shmem_int64_alltoall(SHMEM_TEAM_WORLD, dest, source, count); /* verify results */ for (int pe = 0; pe < npes; pe++) { diff --git a/example_code/shmem_alltoalls_example.c b/example_code/shmem_alltoalls_example.c index 774b7588c..9f458f753 100644 --- a/example_code/shmem_alltoalls_example.c +++ b/example_code/shmem_alltoalls_example.c @@ -2,11 +2,10 @@ #include #include -int main(void) -{ - shmem_init(); - int me = shmem_my_pe(); - int npes = shmem_n_pes(); +int main(void) { + shmem_init(); + int me = shmem_my_pe(); + int npes = shmem_n_pes(); const int count = 2; const ptrdiff_t dst = 2; @@ -15,18 +14,18 @@ int main(void) int64_t *source = (int64_t *)shmem_malloc(count * sst * npes * sizeof(int64_t)); - /* assign source values */ - for (int pe = 0; pe < npes; pe++) { - for (int i = 0; i < count; i++) { - source[sst * ((pe * count) + i)] = me + pe; - dest[dst * ((pe * count) + i)] = 9999; - } - } - /* wait for all PEs to initialize source/dest */ - shmem_team_sync(SHMEM_TEAM_WORLD); + /* assign source values */ + for (int pe = 0; pe < npes; pe++) { + for (int i = 0; i < count; i++) { + source[sst * ((pe * count) + i)] = me + pe; + dest[dst * ((pe * count) + i)] = 9999; + } + } + /* wait for all PEs to initialize source/dest */ + shmem_team_sync(SHMEM_TEAM_WORLD); - /* alltoalls on all PES */ - shmem_int64_alltoalls(SHMEM_TEAM_WORLD, dest, source, dst, sst, count); + /* alltoalls on all PES */ + shmem_int64_alltoalls(SHMEM_TEAM_WORLD, dest, source, dst, sst, count); /* verify results */ for (int pe = 0; pe < npes; pe++) { diff --git a/example_code/shmem_broadcast_example.c b/example_code/shmem_broadcast_example.c index e3926e343..d6909e085 100644 --- a/example_code/shmem_broadcast_example.c +++ b/example_code/shmem_broadcast_example.c @@ -2,9 +2,8 @@ #include #include -int main(void) -{ - static long source[4], dest[4]; +int main(void) { + static long source[4], dest[4]; shmem_init(); int me = shmem_my_pe(); @@ -14,9 +13,9 @@ int main(void) for (int i = 0; i < 4; i++) source[i] = i; - shmem_broadcast(SHMEM_TEAM_WORLD, dest, source, 4, 0); + shmem_broadcast(SHMEM_TEAM_WORLD, dest, source, 4, 0); - printf("%d: %ld, %ld, %ld, %ld\n", me, dest[0], dest[1], dest[2], dest[3]); - shmem_finalize(); - return 0; + printf("%d: %ld, %ld, %ld, %ld\n", me, dest[0], dest[1], dest[2], dest[3]); + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_collect_example.c b/example_code/shmem_collect_example.c index d85f2a4f4..95ff45197 100644 --- a/example_code/shmem_collect_example.c +++ b/example_code/shmem_collect_example.c @@ -2,9 +2,8 @@ #include #include -int main(void) -{ - static long lock = 0; +int main(void) { + static long lock = 0; shmem_init(); int me = shmem_my_pe(); @@ -20,10 +19,10 @@ int main(void) for (int i = 0; i < total_nelem; i++) dest[i] = -9999; - /* Wait for all PEs to initialize source/dest: */ - shmem_team_sync(SHMEM_TEAM_WORLD); + /* Wait for all PEs to initialize source/dest: */ + shmem_team_sync(SHMEM_TEAM_WORLD); - shmem_int_collect(SHMEM_TEAM_WORLD, dest, source, my_nelem); + shmem_int_collect(SHMEM_TEAM_WORLD, dest, source, my_nelem); shmem_set_lock(&lock); /* Lock prevents interleaving printfs */ printf("%d: %d", me, dest[0]); diff --git a/example_code/shmem_ctx_invalid.c b/example_code/shmem_ctx_invalid.c index d7962d3fb..843d4a940 100644 --- a/example_code/shmem_ctx_invalid.c +++ b/example_code/shmem_ctx_invalid.c @@ -1,13 +1,13 @@ -#include -#include #include +#include +#include _Thread_local shmem_ctx_t thread_ctx = SHMEM_CTX_INVALID; void lib_thread_register(void) { if (thread_ctx == SHMEM_CTX_INVALID) if (shmem_ctx_create(SHMEM_CTX_PRIVATE, &thread_ctx) && - shmem_ctx_create( 0, &thread_ctx)) + shmem_ctx_create(0, &thread_ctx)) thread_ctx = SHMEM_CTX_DEFAULT; } @@ -57,7 +57,7 @@ int main() { #pragma omp for for (int i = 0; i < n_pes; i++) lib_thread_putmem(dst_bufs[my_pe], src_bufs[i], - count * sizeof(*src_bufs[i]), i); + count * sizeof(*src_bufs[i]), i); lib_thread_unregister(); } diff --git a/example_code/shmem_lock_example.c b/example_code/shmem_lock_example.c index 204532f55..13df831a5 100644 --- a/example_code/shmem_lock_example.c +++ b/example_code/shmem_lock_example.c @@ -1,18 +1,18 @@ #include #include -int main(void) -{ - static long lock = 0; - static int count = 0; - shmem_init(); - int me = shmem_my_pe(); - shmem_set_lock(&lock); - int val = shmem_g(&count, 0); /* get count value on PE 0 */ - printf("%d: count is %d\n", me, val); - val++; /* incrementing and updating count on PE 0 */ - shmem_p(&count, val, 0); - shmem_clear_lock(&lock); /* ensures count update has completed before clearing the lock */ - shmem_finalize(); - return 0; +int main(void) { + static long lock = 0; + static int count = 0; + shmem_init(); + int me = shmem_my_pe(); + shmem_set_lock(&lock); + int val = shmem_g(&count, 0); /* get count value on PE 0 */ + printf("%d: count is %d\n", me, val); + val++; /* incrementing and updating count on PE 0 */ + shmem_p(&count, val, 0); + shmem_clear_lock( + &lock); /* ensures count update has completed before clearing the lock */ + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_put_signal_example.c b/example_code/shmem_put_signal_example.c index 179da6d26..bee428254 100644 --- a/example_code/shmem_put_signal_example.c +++ b/example_code/shmem_put_signal_example.c @@ -3,35 +3,35 @@ #include #include -int main(void) -{ - int i, err_count = 0; +int main(void) { + int i, err_count = 0; - shmem_init(); + shmem_init(); - size_t size = 2048; - int me = shmem_my_pe(); - int n = shmem_n_pes(); - int pe = (me + 1) % n; - uint64_t * message = malloc(size * sizeof(uint64_t)); - static uint64_t sig_addr = 0; + size_t size = 2048; + int me = shmem_my_pe(); + int n = shmem_n_pes(); + int pe = (me + 1) % n; + uint64_t *message = malloc(size * sizeof(uint64_t)); + static uint64_t sig_addr = 0; - for (i = 0; i < size; i++) { - message[i] = me; - } + for (i = 0; i < size; i++) { + message[i] = me; + } - uint64_t *data = shmem_calloc(size, sizeof(uint64_t)); + uint64_t *data = shmem_calloc(size, sizeof(uint64_t)); - if (me == 0) { - shmem_put_signal(data, message, size, &sig_addr, 1, SHMEM_SIGNAL_SET, pe); - } else { - shmem_wait_until(&sig_addr, SHMEM_CMP_EQ, 1); - shmem_put_signal(data, data, size, &sig_addr, 1, SHMEM_SIGNAL_SET, pe); - } + if (me == 0) { + shmem_put_signal(data, message, size, &sig_addr, 1, SHMEM_SIGNAL_SET, pe); + } + else { + shmem_wait_until(&sig_addr, SHMEM_CMP_EQ, 1); + shmem_put_signal(data, data, size, &sig_addr, 1, SHMEM_SIGNAL_SET, pe); + } - free(message); - shmem_free(data); + free(message); + shmem_free(data); - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_reduce_example.c b/example_code/shmem_reduce_example.c index 24f8cbb2b..3a5e0e131 100644 --- a/example_code/shmem_reduce_example.c +++ b/example_code/shmem_reduce_example.c @@ -1,6 +1,6 @@ +#include #include #include -#include /* As if we receive some value from external source */ long recv_a_value(unsigned seed, int npes) { @@ -10,14 +10,12 @@ long recv_a_value(unsigned seed, int npes) { /* Validate the value we recieved */ unsigned char is_valid(long value, int npes) { - if (value == (npes-1)) + if (value == (npes - 1)) return 0; return 1; } -int main(void) -{ - +int main(void) { shmem_init(); int me = shmem_my_pe(); int npes = shmem_n_pes(); @@ -32,8 +30,8 @@ int main(void) values[0] = recv_a_value((unsigned)me, npes); valid_me[0] = is_valid(values[0], npes); - for (int i=1; i < num; i++) { - values[i] = recv_a_value((unsigned)values[i-1], npes); + for (int i = 1; i < num; i++) { + values[i] = recv_a_value((unsigned)values[i - 1], npes); valid_me[i] = is_valid(values[i], npes); } @@ -43,12 +41,12 @@ int main(void) shmem_and_reduce(SHMEM_TEAM_WORLD, valid_all, valid_me, num); shmem_sum_reduce(SHMEM_TEAM_WORLD, sums, values, num); - for (int i=0; i < num; i++) { + for (int i = 0; i < num; i++) { if (valid_all[i]) { - printf ("[%d] = %ld\n", i, sums[i]); + printf("[%d] = %ld\n", i, sums[i]); } else { - printf ("[%d] = invalid on one or more pe\n", i); + printf("[%d] = invalid on one or more pe\n", i); } } diff --git a/example_code/shmem_sync_example.c b/example_code/shmem_sync_example.c index 6893f1ef9..6d2bd7840 100644 --- a/example_code/shmem_sync_example.c +++ b/example_code/shmem_sync_example.c @@ -1,60 +1,64 @@ #include #include -int main(void) -{ - static int x = 10101; - - shmem_team_t twos_team = SHMEM_TEAM_INVALID; - shmem_team_t threes_team = SHMEM_TEAM_INVALID; - shmem_team_config_t *config; - - shmem_init(); - config = NULL; - int me = shmem_my_pe(); - int npes = shmem_n_pes(); - - if (npes > 2) - shmem_team_split_strided(SHMEM_TEAM_WORLD, 2, 2, (npes-1) / 2, config, - 0, &twos_team); - - if (npes > 3) - shmem_team_split_strided(SHMEM_TEAM_WORLD, 3, 3, (npes-1) / 3, config, - 0, &threes_team); - - int my_pe_twos = shmem_team_my_pe(twos_team); - int my_pe_threes = shmem_team_my_pe(threes_team); - int npes_twos = shmem_team_n_pes(twos_team); - int npes_threes = shmem_team_n_pes(threes_team); - - if (twos_team != SHMEM_TEAM_INVALID) { - /* put the value 2 to the next team member in a circular fashion */ - shmem_p(&x, 2, shmem_team_translate_pe(twos_team, (my_pe_twos + 1) % - npes_twos, SHMEM_TEAM_WORLD)); - shmem_quiet(); - shmem_sync(twos_team); - } - - shmem_sync(SHMEM_TEAM_WORLD); - - if (threes_team != SHMEM_TEAM_INVALID) { - /* put the value 3 to the next team member in a circular fashion */ - shmem_p(&x, 3, shmem_team_translate_pe(threes_team, (my_pe_threes + 1) % - npes_threes, SHMEM_TEAM_WORLD)); - shmem_quiet(); - shmem_sync(threes_team); - } - - if (me && me % 3 == 0) { - if (x != 3) shmem_global_exit(3); - } - else if (me && me % 2 == 0) { - if (x != 2) shmem_global_exit(2); - } - else if (x != 10101) { - shmem_global_exit(1); - } - - shmem_finalize(); - return 0; +int main(void) { + static int x = 10101; + + shmem_team_t twos_team = SHMEM_TEAM_INVALID; + shmem_team_t threes_team = SHMEM_TEAM_INVALID; + shmem_team_config_t *config; + + shmem_init(); + config = NULL; + int me = shmem_my_pe(); + int npes = shmem_n_pes(); + + if (npes > 2) + shmem_team_split_strided(SHMEM_TEAM_WORLD, 2, 2, (npes - 1) / 2, config, 0, + &twos_team); + + if (npes > 3) + shmem_team_split_strided(SHMEM_TEAM_WORLD, 3, 3, (npes - 1) / 3, config, 0, + &threes_team); + + int my_pe_twos = shmem_team_my_pe(twos_team); + int my_pe_threes = shmem_team_my_pe(threes_team); + int npes_twos = shmem_team_n_pes(twos_team); + int npes_threes = shmem_team_n_pes(threes_team); + + if (twos_team != SHMEM_TEAM_INVALID) { + /* put the value 2 to the next team member in a circular fashion */ + shmem_p(&x, 2, + shmem_team_translate_pe(twos_team, (my_pe_twos + 1) % npes_twos, + SHMEM_TEAM_WORLD)); + shmem_quiet(); + shmem_sync(twos_team); + } + + shmem_sync(SHMEM_TEAM_WORLD); + + if (threes_team != SHMEM_TEAM_INVALID) { + /* put the value 3 to the next team member in a circular fashion */ + shmem_p(&x, 3, + shmem_team_translate_pe(threes_team, + (my_pe_threes + 1) % npes_threes, + SHMEM_TEAM_WORLD)); + shmem_quiet(); + shmem_sync(threes_team); + } + + if (me && me % 3 == 0) { + if (x != 3) + shmem_global_exit(3); + } + else if (me && me % 2 == 0) { + if (x != 2) + shmem_global_exit(2); + } + else if (x != 10101) { + shmem_global_exit(1); + } + + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_team_context.c b/example_code/shmem_team_context.c index 5b1e07ffc..0cb9f09cd 100644 --- a/example_code/shmem_team_context.c +++ b/example_code/shmem_team_context.c @@ -3,8 +3,7 @@ int isum, ival; -int my_ctx_translate_pe(shmem_ctx_t src_ctx, int src_pe, shmem_ctx_t dest_ctx) -{ +int my_ctx_translate_pe(shmem_ctx_t src_ctx, int src_pe, shmem_ctx_t dest_ctx) { if (src_ctx == SHMEM_CTX_INVALID) { return -1; } @@ -25,16 +24,15 @@ shmem_ctx_t my_team_create_ctx(shmem_team_t team) { shmem_ctx_t ctx; if (shmem_team_create_ctx(team, 0, &ctx) != 0) { - fprintf (stderr, "Failed to create context for PE team\n"); + fprintf(stderr, "Failed to create context for PE team\n"); return SHMEM_CTX_INVALID; } return ctx; } -void my_send_to_neighbor(shmem_ctx_t ctx, int *val) -{ +void my_send_to_neighbor(shmem_ctx_t ctx, int *val) { if (ctx == SHMEM_CTX_INVALID) { - fprintf (stderr, "Send to neighbor fail due to invalid context\n"); + fprintf(stderr, "Send to neighbor fail due to invalid context\n"); return; } @@ -48,10 +46,7 @@ void my_send_to_neighbor(shmem_ctx_t ctx, int *val) shmem_ctx_int_put(ctx, val, &pe, 1, rpe); } - - -int main() -{ +int main() { shmem_init(); int npes = shmem_n_pes(); @@ -64,9 +59,11 @@ int main() long cmask = SHMEM_TEAM_NUM_CONTEXTS; // Create team with PEs numbered 0, 2, 4, ... - shmem_team_spit_strided(SHMEM_TEAM_WORLD, 0, 2, npes / 2, &conf, cmask, &team_2s); + shmem_team_spit_strided(SHMEM_TEAM_WORLD, 0, 2, npes / 2, &conf, cmask, + &team_2s); // Create team with PEs numbered 0, 3, 6, ... - shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 3, npes / 3, &conf, cmask, &team_3s); + shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 3, npes / 3, &conf, cmask, + &team_3s); ctx_2s = my_team_create_ctx(team_2s); ctx_3s = my_team_create_ctx(team_3s); @@ -85,7 +82,7 @@ int main() int pe4_of_3s_in_2s = my_ctx_translate_pe(ctx_3s, 4, ctx_2s); if (pe4_of_3s_in_2s < 0) { - fprintf (stderr, "Fail to translate pe 4 from 3s context to 2s context\n"); + fprintf(stderr, "Fail to translate pe 4 from 3s context to 2s context\n"); } else { // Add up the results on pe 4 of the 3s team, using the 2s team context @@ -98,7 +95,7 @@ int main() shmem_team_sync(SHMEM_TEAM_WORLD); if (shmem_team_my_pe(team_3s) == 4) { - printf ("The total value on PE 4 of the 3s team is %d\n", isum); + printf("The total value on PE 4 of the 3s team is %d\n", isum); } // Destroy contexts before teams diff --git a/example_code/shmem_team_split_2D.c b/example_code/shmem_team_split_2D.c index 2059f3279..39d61a3fb 100644 --- a/example_code/shmem_team_split_2D.c +++ b/example_code/shmem_team_split_2D.c @@ -1,8 +1,7 @@ -#include #include +#include -int main(void) -{ +int main(void) { int xdim = 3; int ydim = 4; @@ -10,15 +9,16 @@ int main(void) int pe = shmem_my_pe(); int npes = shmem_n_pes(); - if (npes < (xdim*ydim)) { - printf ("Not enough PEs to create 4x3xN layout\n"); + if (npes < (xdim * ydim)) { + printf("Not enough PEs to create 4x3xN layout\n"); exit(1); } - int zdim = (npes / (xdim*ydim)) + ( ((npes % (xdim*ydim)) > 0) ? 1 : 0 ); + int zdim = (npes / (xdim * ydim)) + (((npes % (xdim * ydim)) > 0) ? 1 : 0); shmem_team_t xteam, yzteam, yteam, zteam; - shmem_team_split_2d(SHMEM_TEAM_WORLD, xdim, NULL, 0, &xteam, NULL, 0, &yzteam); + shmem_team_split_2d(SHMEM_TEAM_WORLD, xdim, NULL, 0, &xteam, NULL, 0, + &yzteam); // yzteam is immediately ready to be used in collectives shmem_team_split_2d(yzteam, ydim, NULL, 0, &yteam, NULL, 0, &zteam); @@ -33,7 +33,7 @@ int main(void) for (int ydx = 0; ydx < ydim; ydx++) for (int xdx = 0; xdx < xdim; xdx++) { if ((my_x == xdx) && (my_y == ydx) && (my_z == zdx)) { - printf ("(%d, %d, %d) is me = %d\n", my_x, my_y, my_z, pe); + printf("(%d, %d, %d) is me = %d\n", my_x, my_y, my_z, pe); } shmem_team_sync(SHMEM_TEAM_WORLD); } diff --git a/example_code/shmem_team_split_strided.c b/example_code/shmem_team_split_strided.c index 42973ba57..09e685676 100644 --- a/example_code/shmem_team_split_strided.c +++ b/example_code/shmem_team_split_strided.c @@ -6,30 +6,29 @@ #include #include -int main(int argc, char *argv[]) -{ - int rank, npes; - int t_pe, t_size; - shmem_team_t new_team; - shmem_team_config_t *config; +int main(int argc, char *argv[]) { + int rank, npes; + int t_pe, t_size; + shmem_team_t new_team; + shmem_team_config_t *config; - shmem_init(); - config = NULL; - rank = shmem_my_pe(); - npes = shmem_n_pes(); + shmem_init(); + config = NULL; + rank = shmem_my_pe(); + npes = shmem_n_pes(); - shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, npes / 2, config, 0, - &new_team); + shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, npes / 2, config, 0, + &new_team); - if (new_team != SHMEM_TEAM_INVALID) { - t_size = shmem_team_n_pes(new_team); - t_pe = shmem_team_my_pe(new_team); + if (new_team != SHMEM_TEAM_INVALID) { + t_size = shmem_team_n_pes(new_team); + t_pe = shmem_team_my_pe(new_team); - if ((rank % 2 != 0) || (rank / 2 != t_pe) || (npes / 2 != t_size)) { - shmem_global_exit(1); - } + if ((rank % 2 != 0) || (rank / 2 != t_pe) || (npes / 2 != t_size)) { + shmem_global_exit(1); } + } - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_team_translate_pe.c b/example_code/shmem_team_translate_pe.c index 15aec0a6e..a7a852c27 100644 --- a/example_code/shmem_team_translate_pe.c +++ b/example_code/shmem_team_translate_pe.c @@ -1,32 +1,31 @@ -#include #include +#include -int main(void) -{ - int my_pe; - int n_pes; - int t_pe; - int t_global; - shmem_team_t new_team; - shmem_team_config_t *config; +int main(void) { + int my_pe; + int n_pes; + int t_pe; + int t_global; + shmem_team_t new_team; + shmem_team_config_t *config; - shmem_init(); - config = NULL; - my_pe = shmem_my_pe(); - n_pes = shmem_n_pes(); + shmem_init(); + config = NULL; + my_pe = shmem_my_pe(); + n_pes = shmem_n_pes(); - shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, (n_pes + 1) / 2, - config, 0, &new_team); + shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, (n_pes + 1) / 2, config, 0, + &new_team); - if (new_team != SHMEM_TEAM_INVALID) { - t_pe = shmem_team_my_pe(new_team); - t_global = shmem_team_translate_pe(new_team, t_pe, SHMEM_TEAM_WORLD); + if (new_team != SHMEM_TEAM_INVALID) { + t_pe = shmem_team_my_pe(new_team); + t_global = shmem_team_translate_pe(new_team, t_pe, SHMEM_TEAM_WORLD); - if (t_global != my_pe) { - shmem_global_exit(1); - } + if (t_global != my_pe) { + shmem_global_exit(1); } + } - shmem_finalize(); - return 0; + shmem_finalize(); + return 0; } diff --git a/example_code/shmem_test_any_example.c b/example_code/shmem_test_any_example.c index 64c784c3e..e4c5a6941 100644 --- a/example_code/shmem_test_any_example.c +++ b/example_code/shmem_test_any_example.c @@ -1,8 +1,7 @@ #include #include -int main(void) -{ +int main(void) { shmem_init(); int mype = shmem_my_pe(); int npes = shmem_n_pes(); @@ -11,19 +10,20 @@ int main(void) int *status = calloc(npes, sizeof(int)); for (int i = 0; i < npes; i++) - shmem_atomic_set(&flags[mype], 1, i); + shmem_atomic_set(&flags[mype], 1, i); int ncompleted = 0; size_t completed_idx; while (ncompleted < npes) { - completed_idx = shmem_test_any(flags, npes, status, SHMEM_CMP_EQ, 1); - if (completed_idx != SIZE_MAX) { - ncompleted++; - status[completed_idx] = 1; - } else { - /* Overlap some computation here */ - } + completed_idx = shmem_test_any(flags, npes, status, SHMEM_CMP_EQ, 1); + if (completed_idx != SIZE_MAX) { + ncompleted++; + status[completed_idx] = 1; + } + else { + /* Overlap some computation here */ + } } free(status); diff --git a/example_code/shmem_test_some_example.c b/example_code/shmem_test_some_example.c index 9c73a6cdc..260ae945a 100644 --- a/example_code/shmem_test_some_example.c +++ b/example_code/shmem_test_some_example.c @@ -3,8 +3,7 @@ #define N 100 -int main(void) -{ +int main(void) { int total_sum = 0; shmem_init(); @@ -19,37 +18,39 @@ int main(void) int *status = calloc(npes, sizeof(int)); for (int i = 0; i < N; i++) - my_data[i] = mype*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_put_nbi(&all_data[mype * N], my_data, N, i); shmem_fence(); for (int i = 0; i < npes; i++) - shmem_atomic_set(&flags[mype], 1, i); + shmem_atomic_set(&flags[mype], 1, i); int ncompleted = 0; while (ncompleted < npes) { - int ntested = shmem_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]; - } - status[indices[i]] = 1; - } - ncompleted += ntested; - } else { - /* Overlap some computation here */ + int ntested = + shmem_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]; + } + status[indices[i]] = 1; } + ncompleted += ntested; + } + else { + /* Overlap some computation here */ + } } /* check the result */ int M = N * npes - 1; if (total_sum != M * (M + 1) / 2) { - shmem_global_exit(1); + shmem_global_exit(1); } shmem_finalize(); diff --git a/example_code/shmem_wait_until_all.c b/example_code/shmem_wait_until_all.c index ed2eacaf7..a2e9724f6 100644 --- a/example_code/shmem_wait_until_all.c +++ b/example_code/shmem_wait_until_all.c @@ -1,7 +1,6 @@ #include -int main(void) -{ +int main(void) { shmem_init(); int mype = shmem_my_pe(); int npes = shmem_n_pes(); @@ -10,7 +9,7 @@ int main(void) int *status = NULL; for (int i = 0; i < npes; i++) - shmem_atomic_set(&flags[mype], 1, i); + shmem_atomic_set(&flags[mype], 1, i); shmem_wait_until_all(flags, npes, status, SHMEM_CMP_EQ, 1); diff --git a/example_code/shmem_wait_until_any_all2all_sum.c b/example_code/shmem_wait_until_any_all2all_sum.c index 3317fec6a..dd7a840ce 100644 --- a/example_code/shmem_wait_until_any_all2all_sum.c +++ b/example_code/shmem_wait_until_any_all2all_sum.c @@ -3,8 +3,7 @@ #define N 100 -int main(void) -{ +int main(void) { int total_sum = 0; shmem_init(); @@ -18,28 +17,29 @@ int main(void) int *status = calloc(npes, sizeof(int)); for (int i = 0; i < N; i++) - my_data[i] = mype*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_put_nbi(&all_data[mype * N], my_data, N, i); shmem_fence(); for (int i = 0; i < npes; i++) - shmem_atomic_set(&flags[mype], 1, i); + shmem_atomic_set(&flags[mype], 1, i); for (int i = 0; i < npes; i++) { - size_t completed_idx = shmem_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]; - } - status[completed_idx] = 1; + size_t completed_idx = + shmem_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]; + } + status[completed_idx] = 1; } /* check the result */ int M = N * npes - 1; if (total_sum != M * (M + 1) / 2) { - shmem_global_exit(1); + shmem_global_exit(1); } shmem_finalize(); diff --git a/example_code/shmem_wait_until_any_vector.c b/example_code/shmem_wait_until_any_vector.c index 266585e51..e01ee5d36 100644 --- a/example_code/shmem_wait_until_any_vector.c +++ b/example_code/shmem_wait_until_any_vector.c @@ -3,8 +3,7 @@ #define N 100 -int main(void) -{ +int main(void) { int total_sum = 0; shmem_init(); @@ -17,24 +16,24 @@ int main(void) /* All odd PEs put 2 and all even PEs put 1 */ for (int i = 0; i < npes; i++) { - shmem_atomic_set(&ivars[mype], mype % 2 + 1, i); + shmem_atomic_set(&ivars[mype], mype % 2 + 1, i); - /* Set cmp_values to the expected values coming from each PE */ - cmp_values[i] = i % 2 + 1; + /* Set cmp_values to the expected values coming from each PE */ + cmp_values[i] = i % 2 + 1; } for (int i = 0; i < npes; i++) { - size_t completed_idx = shmem_wait_until_any_vector(ivars, npes, status, - SHMEM_CMP_EQ, cmp_values); - status[completed_idx] = 1; - total_sum += ivars[completed_idx]; + size_t completed_idx = shmem_wait_until_any_vector( + ivars, npes, status, SHMEM_CMP_EQ, cmp_values); + status[completed_idx] = 1; + total_sum += ivars[completed_idx]; } /* check the result */ int correct_result = npes + npes / 2; if (total_sum != correct_result) { - shmem_global_exit(1); + shmem_global_exit(1); } shmem_finalize(); diff --git a/example_code/shmem_wait_until_some_all2all_sum.c b/example_code/shmem_wait_until_some_all2all_sum.c index 1c1a2f951..f7d93ece0 100644 --- a/example_code/shmem_wait_until_some_all2all_sum.c +++ b/example_code/shmem_wait_until_some_all2all_sum.c @@ -3,8 +3,7 @@ #define N 100 -int main(void) -{ +int main(void) { int total_sum = 0; shmem_init(); @@ -19,31 +18,31 @@ int main(void) int *status = calloc(npes, sizeof(int)); for (int i = 0; i < N; i++) - my_data[i] = mype*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_put_nbi(&all_data[mype * N], my_data, N, i); shmem_fence(); for (int i = 0; i < npes; i++) - shmem_atomic_set(&flags[mype], 1, i); + shmem_atomic_set(&flags[mype], 1, i); size_t ncompleted; - while ((ncompleted = shmem_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]; - } - status[indices[i]] = 1; + while ((ncompleted = shmem_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]; } + status[indices[i]] = 1; + } } /* check the result */ int M = N * npes - 1; if (total_sum != M * (M + 1) / 2) { - shmem_global_exit(1); + shmem_global_exit(1); } shmem_finalize(); From 2c55b8a0fa0bcc6b065875167e5ec947a07f35e1 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Mon, 3 Feb 2020 19:37:21 -0500 Subject: [PATCH 08/23] Rename (my_pe, n_pes) -> (mype, npes) for consistency --- example_code/shmem_ctx_invalid.c | 12 ++++++------ example_code/shmem_team_translate_pe.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example_code/shmem_ctx_invalid.c b/example_code/shmem_ctx_invalid.c index 843d4a940..843c2a1b3 100644 --- a/example_code/shmem_ctx_invalid.c +++ b/example_code/shmem_ctx_invalid.c @@ -30,12 +30,12 @@ int main() { shmem_global_exit(2); const int my_pe = shmem_my_pe(); - const int n_pes = shmem_n_pes(); + const int npes = shmem_n_pes(); const int count = 1 << 15; - int *src_bufs[n_pes]; - int *dst_bufs[n_pes]; - for (int i = 0; i < n_pes; i++) { + int *src_bufs[npes]; + int *dst_bufs[npes]; + for (int i = 0; i < npes; i++) { src_bufs[i] = shmem_calloc(count, sizeof(*src_bufs[i])); if (src_bufs[i] == NULL) shmem_global_exit(3); @@ -48,14 +48,14 @@ int main() { { int my_thrd = omp_get_thread_num(); #pragma omp for - for (int i = 0; i < n_pes; i++) + for (int i = 0; i < npes; i++) for (int j = 0; j < count; j++) src_bufs[i][j] = (my_pe << 10) + my_thrd; lib_thread_register(); #pragma omp for - for (int i = 0; i < n_pes; i++) + for (int i = 0; i < npes; i++) lib_thread_putmem(dst_bufs[my_pe], src_bufs[i], count * sizeof(*src_bufs[i]), i); diff --git a/example_code/shmem_team_translate_pe.c b/example_code/shmem_team_translate_pe.c index a7a852c27..4b5adf990 100644 --- a/example_code/shmem_team_translate_pe.c +++ b/example_code/shmem_team_translate_pe.c @@ -3,7 +3,7 @@ int main(void) { int my_pe; - int n_pes; + int npes; int t_pe; int t_global; shmem_team_t new_team; @@ -12,9 +12,9 @@ int main(void) { shmem_init(); config = NULL; my_pe = shmem_my_pe(); - n_pes = shmem_n_pes(); + npes = shmem_n_pes(); - shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, (n_pes + 1) / 2, config, 0, + shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, (npes + 1) / 2, config, 0, &new_team); if (new_team != SHMEM_TEAM_INVALID) { From f2c03aaa5e819fa7f4523e0a60e813eee7d7e8b3 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Mon, 3 Feb 2020 19:41:49 -0500 Subject: [PATCH 09/23] Rename me -> mype for consistency --- example_code/hello-openshmem.c | 4 ++-- example_code/shmem_alltoall_example.c | 10 +++++----- example_code/shmem_alltoalls_example.c | 10 +++++----- example_code/shmem_atomic_add_example.c | 6 +++--- example_code/shmem_atomic_compare_swap_example.c | 6 +++--- example_code/shmem_atomic_fetch_add_example.c | 6 +++--- example_code/shmem_atomic_fetch_inc_example.c | 6 +++--- example_code/shmem_atomic_inc_example.c | 6 +++--- example_code/shmem_atomic_swap_example.c | 12 ++++++------ example_code/shmem_barrier_example.c | 8 ++++---- example_code/shmem_barrierall_example.c | 6 +++--- example_code/shmem_broadcast_example.c | 6 +++--- example_code/shmem_collect_example.c | 8 ++++---- example_code/shmem_ctx.c | 6 +++--- example_code/shmem_ctx_pipelined_reduce.c | 12 ++++++------ example_code/shmem_fence_example.c | 6 +++--- example_code/shmem_finalize_example.c | 6 +++--- example_code/shmem_g_example.c | 6 +++--- example_code/shmem_global_exit_example.c | 4 ++-- example_code/shmem_init_example.c | 8 ++++---- example_code/shmem_iput_example.c | 8 ++++---- example_code/shmem_lock_example.c | 4 ++-- example_code/shmem_npes_example.c | 4 ++-- example_code/shmem_p_example.c | 6 +++--- example_code/shmem_ptr_example.c | 6 +++--- example_code/shmem_put_example.c | 6 +++--- example_code/shmem_put_signal_example.c | 8 ++++---- example_code/shmem_quiet_example.c | 4 ++-- example_code/shmem_reduce_example.c | 4 ++-- example_code/shmem_sync_example.c | 6 +++--- example_code/shmem_team_split_2D.c | 2 +- example_code/writing_shmem_example.c | 8 ++++---- 32 files changed, 104 insertions(+), 104 deletions(-) diff --git a/example_code/hello-openshmem.c b/example_code/hello-openshmem.c index 7b14a5c18..1d6e0f32e 100644 --- a/example_code/hello-openshmem.c +++ b/example_code/hello-openshmem.c @@ -3,9 +3,9 @@ int main(void) { shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); - printf("Hello from %d of %d\n", me, npes); + printf("Hello from %d of %d\n", mype, npes); shmem_finalize(); return 0; } diff --git a/example_code/shmem_alltoall_example.c b/example_code/shmem_alltoall_example.c index 6560ae993..5ec199002 100644 --- a/example_code/shmem_alltoall_example.c +++ b/example_code/shmem_alltoall_example.c @@ -4,7 +4,7 @@ int main(void) { shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); const int count = 2; @@ -14,7 +14,7 @@ int main(void) { /* assign source values */ for (int pe = 0; pe < npes; pe++) { for (int i = 0; i < count; i++) { - source[(pe * count) + i] = me + pe; + source[(pe * count) + i] = mype + pe; dest[(pe * count) + i] = 9999; } } @@ -27,9 +27,9 @@ int main(void) { /* verify results */ for (int pe = 0; pe < npes; pe++) { for (int i = 0; i < count; i++) { - if (dest[(pe * count) + i] != pe + me) { - printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", me, - (pe * count) + i, dest[(pe * count) + i], pe + me); + if (dest[(pe * count) + i] != pe + mype) { + printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", mype, + (pe * count) + i, dest[(pe * count) + i], pe + mype); } } } diff --git a/example_code/shmem_alltoalls_example.c b/example_code/shmem_alltoalls_example.c index 9f458f753..24aad9a68 100644 --- a/example_code/shmem_alltoalls_example.c +++ b/example_code/shmem_alltoalls_example.c @@ -4,7 +4,7 @@ int main(void) { shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); const int count = 2; @@ -17,7 +17,7 @@ int main(void) { /* assign source values */ for (int pe = 0; pe < npes; pe++) { for (int i = 0; i < count; i++) { - source[sst * ((pe * count) + i)] = me + pe; + source[sst * ((pe * count) + i)] = mype + pe; dest[dst * ((pe * count) + i)] = 9999; } } @@ -31,9 +31,9 @@ int main(void) { for (int pe = 0; pe < npes; pe++) { for (int i = 0; i < count; i++) { int j = dst * ((pe * count) + i); - if (dest[j] != pe + me) { - printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", me, j, - dest[j], pe + me); + if (dest[j] != pe + mype) { + printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", mype, j, + dest[j], pe + mype); } } } diff --git a/example_code/shmem_atomic_add_example.c b/example_code/shmem_atomic_add_example.c index 11a7ab9df..1caf33cf1 100644 --- a/example_code/shmem_atomic_add_example.c +++ b/example_code/shmem_atomic_add_example.c @@ -4,11 +4,11 @@ int main(void) { static int dst = 22; shmem_init(); - int me = shmem_my_pe(); - if (me == 1) + int mype = shmem_my_pe(); + if (mype == 1) shmem_atomic_add(&dst, 44, 0); shmem_barrier_all(); - printf("%d: dst = %d\n", me, dst); + printf("%d: dst = %d\n", mype, dst); shmem_finalize(); return 0; } diff --git a/example_code/shmem_atomic_compare_swap_example.c b/example_code/shmem_atomic_compare_swap_example.c index 297b4ac72..dfa4e7bb5 100644 --- a/example_code/shmem_atomic_compare_swap_example.c +++ b/example_code/shmem_atomic_compare_swap_example.c @@ -4,10 +4,10 @@ int main(void) { static int race_winner = -1; shmem_init(); - int me = shmem_my_pe(); - int oldval = shmem_atomic_compare_swap(&race_winner, -1, me, 0); + int mype = shmem_my_pe(); + int oldval = shmem_atomic_compare_swap(&race_winner, -1, mype, 0); if (oldval == -1) - printf("PE %d was first\n", me); + printf("PE %d was first\n", mype); shmem_finalize(); return 0; } diff --git a/example_code/shmem_atomic_fetch_add_example.c b/example_code/shmem_atomic_fetch_add_example.c index 770cac006..571e8feab 100644 --- a/example_code/shmem_atomic_fetch_add_example.c +++ b/example_code/shmem_atomic_fetch_add_example.c @@ -5,11 +5,11 @@ int main(void) { int old = -1; static int dst = 22; shmem_init(); - int me = shmem_my_pe(); - if (me == 1) + int mype = shmem_my_pe(); + if (mype == 1) old = shmem_atomic_fetch_add(&dst, 44, 0); shmem_barrier_all(); - printf("%d: old = %d, dst = %d\n", me, old, dst); + printf("%d: old = %d, dst = %d\n", mype, old, dst); shmem_finalize(); return 0; } diff --git a/example_code/shmem_atomic_fetch_inc_example.c b/example_code/shmem_atomic_fetch_inc_example.c index 2149ef017..e183bf0ea 100644 --- a/example_code/shmem_atomic_fetch_inc_example.c +++ b/example_code/shmem_atomic_fetch_inc_example.c @@ -5,11 +5,11 @@ int main(void) { int old = -1; static int dst = 22; shmem_init(); - int me = shmem_my_pe(); - if (me == 0) + int mype = shmem_my_pe(); + if (mype == 0) old = shmem_atomic_fetch_inc(&dst, 1); shmem_barrier_all(); - printf("%d: old = %d, dst = %d\n", me, old, dst); + printf("%d: old = %d, dst = %d\n", mype, old, dst); shmem_finalize(); return 0; } diff --git a/example_code/shmem_atomic_inc_example.c b/example_code/shmem_atomic_inc_example.c index a514b0df8..7112486b8 100644 --- a/example_code/shmem_atomic_inc_example.c +++ b/example_code/shmem_atomic_inc_example.c @@ -4,11 +4,11 @@ int main(void) { static int dst = 74; shmem_init(); - int me = shmem_my_pe(); - if (me == 0) + int mype = shmem_my_pe(); + if (mype == 0) shmem_atomic_inc(&dst, 1); shmem_barrier_all(); - printf("%d: dst = %d\n", me, dst); + printf("%d: dst = %d\n", mype, dst); shmem_finalize(); return 0; } diff --git a/example_code/shmem_atomic_swap_example.c b/example_code/shmem_atomic_swap_example.c index b941107da..710e6a5d5 100644 --- a/example_code/shmem_atomic_swap_example.c +++ b/example_code/shmem_atomic_swap_example.c @@ -4,14 +4,14 @@ int main(void) { static long dest; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); - dest = me; + dest = mype; shmem_barrier_all(); - long new_val = me; - if (me & 1) { - long swapped_val = shmem_atomic_swap(&dest, new_val, (me + 1) % npes); - printf("%d: dest = %ld, swapped = %ld\n", me, dest, swapped_val); + long new_val = mype; + if (mype & 1) { + long swapped_val = shmem_atomic_swap(&dest, new_val, (mype + 1) % npes); + printf("%d: dest = %ld, swapped = %ld\n", mype, dest, swapped_val); } shmem_finalize(); return 0; diff --git a/example_code/shmem_barrier_example.c b/example_code/shmem_barrier_example.c index 1aaece3f7..32aea43db 100644 --- a/example_code/shmem_barrier_example.c +++ b/example_code/shmem_barrier_example.c @@ -8,16 +8,16 @@ int main(void) { pSync[i] = SHMEM_SYNC_VALUE; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); - if (me % 2 == 0) { + if (mype % 2 == 0) { /* put to next even PE in a circular fashion */ - shmem_p(&x, 4, (me + 2) % npes); + shmem_p(&x, 4, (mype + 2) % npes); /* synchronize all even pes */ shmem_barrier(0, 1, (npes / 2 + npes % 2), pSync); } - printf("%d: x = %d\n", me, x); + printf("%d: x = %d\n", mype, x); shmem_finalize(); return 0; } diff --git a/example_code/shmem_barrierall_example.c b/example_code/shmem_barrierall_example.c index b34872719..cadc93c02 100644 --- a/example_code/shmem_barrierall_example.c +++ b/example_code/shmem_barrierall_example.c @@ -5,15 +5,15 @@ int main(void) { static int x = 1010; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); /* put to next PE in a circular fashion */ - shmem_p(&x, 4, (me + 1) % npes); + shmem_p(&x, 4, (mype + 1) % npes); /* synchronize all PEs */ shmem_barrier_all(); - printf("%d: x = %d\n", me, x); + printf("%d: x = %d\n", mype, x); shmem_finalize(); return 0; } diff --git a/example_code/shmem_broadcast_example.c b/example_code/shmem_broadcast_example.c index d6909e085..a88c2084c 100644 --- a/example_code/shmem_broadcast_example.c +++ b/example_code/shmem_broadcast_example.c @@ -6,16 +6,16 @@ int main(void) { static long source[4], dest[4]; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); - if (me == 0) + if (mype == 0) for (int i = 0; i < 4; i++) source[i] = i; shmem_broadcast(SHMEM_TEAM_WORLD, dest, source, 4, 0); - printf("%d: %ld, %ld, %ld, %ld\n", me, dest[0], dest[1], dest[2], dest[3]); + printf("%d: %ld, %ld, %ld, %ld\n", mype, dest[0], dest[1], dest[2], dest[3]); shmem_finalize(); return 0; } diff --git a/example_code/shmem_collect_example.c b/example_code/shmem_collect_example.c index 95ff45197..b3329c9fd 100644 --- a/example_code/shmem_collect_example.c +++ b/example_code/shmem_collect_example.c @@ -6,16 +6,16 @@ int main(void) { static long lock = 0; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); - int my_nelem = me + 1; /* linearly increasing number of elements with PE */ + int my_nelem = mype + 1; /* linearly increasing number of elements with PE */ int total_nelem = (npes * (npes + 1)) / 2; int *source = (int *)shmem_malloc(npes * sizeof(int)); /* symmetric alloc */ int *dest = (int *)shmem_malloc(total_nelem * sizeof(int)); for (int i = 0; i < my_nelem; i++) - source[i] = (me * (me + 1)) / 2 + i; + source[i] = (mype * (mype + 1)) / 2 + i; for (int i = 0; i < total_nelem; i++) dest[i] = -9999; @@ -25,7 +25,7 @@ int main(void) { shmem_int_collect(SHMEM_TEAM_WORLD, dest, source, my_nelem); shmem_set_lock(&lock); /* Lock prevents interleaving printfs */ - printf("%d: %d", me, dest[0]); + printf("%d: %d", mype, dest[0]); for (int i = 1; i < total_nelem; i++) printf(", %d", dest[i]); printf("\n"); diff --git a/example_code/shmem_ctx.c b/example_code/shmem_ctx.c index db65896da..b122e874a 100644 --- a/example_code/shmem_ctx.c +++ b/example_code/shmem_ctx.c @@ -19,17 +19,17 @@ int main(void) { if (tl != SHMEM_THREAD_MULTIPLE) shmem_global_exit(1); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); #pragma omp parallel reduction(+ : tasks_done) { shmem_ctx_t ctx; - int task_pe = me, pes_done = 0; + int task_pe = mype, pes_done = 0; int ret = shmem_ctx_create(SHMEM_CTX_PRIVATE, &ctx); if (ret != 0) { - printf("%d: Error creating context (%d)\n", me, ret); + printf("%d: Error creating context (%d)\n", mype, ret); shmem_global_exit(2); } diff --git a/example_code/shmem_ctx_pipelined_reduce.c b/example_code/shmem_ctx_pipelined_reduce.c index b95ca5bbc..7bdd9059d 100644 --- a/example_code/shmem_ctx_pipelined_reduce.c +++ b/example_code/shmem_ctx_pipelined_reduce.c @@ -12,7 +12,7 @@ int main(void) { shmem_ctx_t ctx[2]; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); pbuf[0] = shmem_malloc(PLEN * npes * sizeof(int)); @@ -24,23 +24,23 @@ int main(void) { shmem_global_exit(1); for (i = 0; i < LEN; i++) { - in_buf[i] = me; + in_buf[i] = mype; out_buf[i] = 0; } int p_idx = 0, p = 0; /* Index of ctx and pbuf (p_idx) for current pipeline stage (p) */ for (i = 1; i <= npes; i++) - shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * me], &in_buf[PLEN * p], PLEN, - (me + i) % npes); + shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * mype], &in_buf[PLEN * p], PLEN, + (mype + i) % npes); /* Issue communication for pipeline stage p, then accumulate results for stage * p-1 */ for (p = 1; p < LEN / PLEN; p++) { p_idx ^= 1; for (i = 1; i <= npes; i++) - shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * me], &in_buf[PLEN * p], - PLEN, (me + i) % npes); + shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * mype], &in_buf[PLEN * p], + PLEN, (mype + i) % npes); shmem_ctx_quiet(ctx[p_idx ^ 1]); shmem_sync_all(); diff --git a/example_code/shmem_fence_example.c b/example_code/shmem_fence_example.c index f17ccb68f..ac34b40dd 100644 --- a/example_code/shmem_fence_example.c +++ b/example_code/shmem_fence_example.c @@ -7,8 +7,8 @@ int main(void) { static long dest[10]; static int targ; shmem_init(); - int me = shmem_my_pe(); - if (me == 0) { + int mype = shmem_my_pe(); + if (mype == 0) { shmem_put(dest, source, 10, 1); /* put1 */ shmem_put(dest, source, 10, 2); /* put2 */ shmem_fence(); @@ -16,7 +16,7 @@ int main(void) { shmem_put(&targ, &src, 1, 2); /* put4 */ } shmem_barrier_all(); /* sync sender and receiver */ - printf("dest[0] on PE %d is %ld\n", me, dest[0]); + printf("dest[0] on PE %d is %ld\n", mype, dest[0]); shmem_finalize(); return 0; } diff --git a/example_code/shmem_finalize_example.c b/example_code/shmem_finalize_example.c index 6ed2c06be..370c2b26c 100644 --- a/example_code/shmem_finalize_example.c +++ b/example_code/shmem_finalize_example.c @@ -6,13 +6,13 @@ int main(void) { long y = -1; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); - if (me == 0) + if (mype == 0) y = shmem_g(&x, npes - 1); - printf("%d: y = %ld\n", me, y); + printf("%d: y = %ld\n", mype, y); shmem_finalize(); return 0; diff --git a/example_code/shmem_g_example.c b/example_code/shmem_g_example.c index cc11b48b9..9e4e530df 100644 --- a/example_code/shmem_g_example.c +++ b/example_code/shmem_g_example.c @@ -5,11 +5,11 @@ int main(void) { long y = -1; static long x = 10101; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); - if (me == 0) + if (mype == 0) y = shmem_g(&x, npes - 1); - printf("%d: y = %ld\n", me, y); + printf("%d: y = %ld\n", mype, y); shmem_finalize(); return 0; } diff --git a/example_code/shmem_global_exit_example.c b/example_code/shmem_global_exit_example.c index b88af2977..e01360764 100644 --- a/example_code/shmem_global_exit_example.c +++ b/example_code/shmem_global_exit_example.c @@ -4,8 +4,8 @@ int main(void) { shmem_init(); - int me = shmem_my_pe(); - if (me == 0) { + int mype = shmem_my_pe(); + if (mype == 0) { FILE *fp = fopen("input.txt", "r"); if (fp == NULL) { /* Input file required by program is not available */ shmem_global_exit(EXIT_FAILURE); diff --git a/example_code/shmem_init_example.c b/example_code/shmem_init_example.c index 3662f28b5..13b63df4d 100644 --- a/example_code/shmem_init_example.c +++ b/example_code/shmem_init_example.c @@ -5,18 +5,18 @@ int main(void) { static int targ = 0; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int receiver = 1 % shmem_n_pes(); - if (me == 0) { + if (mype == 0) { int src = 33; shmem_put(&targ, &src, 1, receiver); } shmem_barrier_all(); /* Synchronizes sender and receiver */ - if (me == receiver) - printf("PE %d targ=%d (expect 33)\n", me, targ); + if (mype == receiver) + printf("PE %d targ=%d (expect 33)\n", mype, targ); shmem_finalize(); return 0; diff --git a/example_code/shmem_iput_example.c b/example_code/shmem_iput_example.c index 00a50bace..e73db1867 100644 --- a/example_code/shmem_iput_example.c +++ b/example_code/shmem_iput_example.c @@ -5,12 +5,12 @@ int main(void) { short source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; static short dest[10]; shmem_init(); - int me = shmem_my_pe(); - if (me == 0) /* put 5 elements into dest on PE 1 */ + int mype = shmem_my_pe(); + if (mype == 0) /* put 5 elements into dest on PE 1 */ shmem_iput(dest, source, 1, 2, 5, 1); shmem_barrier_all(); /* sync sender and receiver */ - if (me == 1) { - printf("dest on PE %d is %hd %hd %hd %hd %hd\n", me, dest[0], dest[1], + if (mype == 1) { + printf("dest on PE %d is %hd %hd %hd %hd %hd\n", mype, dest[0], dest[1], dest[2], dest[3], dest[4]); } shmem_finalize(); diff --git a/example_code/shmem_lock_example.c b/example_code/shmem_lock_example.c index 13df831a5..88d8ca6bb 100644 --- a/example_code/shmem_lock_example.c +++ b/example_code/shmem_lock_example.c @@ -5,10 +5,10 @@ int main(void) { static long lock = 0; static int count = 0; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); shmem_set_lock(&lock); int val = shmem_g(&count, 0); /* get count value on PE 0 */ - printf("%d: count is %d\n", me, val); + printf("%d: count is %d\n", mype, val); val++; /* incrementing and updating count on PE 0 */ shmem_p(&count, val, 0); shmem_clear_lock( diff --git a/example_code/shmem_npes_example.c b/example_code/shmem_npes_example.c index 4da650d0b..d4158950c 100644 --- a/example_code/shmem_npes_example.c +++ b/example_code/shmem_npes_example.c @@ -3,9 +3,9 @@ int main(void) { shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); - printf("I am #%d of %d PEs executing this program\n", me, npes); + printf("I am #%d of %d PEs executing this program\n", mype, npes); shmem_finalize(); return 0; } diff --git a/example_code/shmem_p_example.c b/example_code/shmem_p_example.c index 467096583..e7bb97968 100644 --- a/example_code/shmem_p_example.c +++ b/example_code/shmem_p_example.c @@ -7,11 +7,11 @@ int main(void) { const double epsilon = 0.00000001; static double f = 3.1415927; shmem_init(); - int me = shmem_my_pe(); - if (me == 0) + int mype = shmem_my_pe(); + if (mype == 0) shmem_p(&f, e, 1); shmem_barrier_all(); - if (me == 1) + if (mype == 1) printf("%s\n", (fabs(f - e) < epsilon) ? "OK" : "FAIL"); shmem_finalize(); return 0; diff --git a/example_code/shmem_ptr_example.c b/example_code/shmem_ptr_example.c index c78863de0..6f4d0a2c6 100644 --- a/example_code/shmem_ptr_example.c +++ b/example_code/shmem_ptr_example.c @@ -4,8 +4,8 @@ int main(void) { static int dest[4]; shmem_init(); - int me = shmem_my_pe(); - if (me == 0) { /* initialize PE 1's dest array */ + int mype = shmem_my_pe(); + if (mype == 0) { /* initialize PE 1's dest array */ int *ptr = shmem_ptr(dest, 1); if (ptr == NULL) printf("can't use pointer to directly access PE 1's dest array\n"); @@ -14,7 +14,7 @@ int main(void) { *ptr++ = i + 1; } shmem_barrier_all(); - if (me == 1) + if (mype == 1) printf("PE 1 dest: %d, %d, %d, %d\n", dest[0], dest[1], dest[2], dest[3]); shmem_finalize(); return 0; diff --git a/example_code/shmem_put_example.c b/example_code/shmem_put_example.c index 5eea5f4cd..84990c6cc 100644 --- a/example_code/shmem_put_example.c +++ b/example_code/shmem_put_example.c @@ -5,11 +5,11 @@ int main(void) { long source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; static long dest[10]; shmem_init(); - int me = shmem_my_pe(); - if (me == 0) /* put 10 words into dest on PE 1 */ + int mype = shmem_my_pe(); + if (mype == 0) /* put 10 words into dest on PE 1 */ shmem_put(dest, source, 10, 1); shmem_barrier_all(); /* sync sender and receiver */ - printf("dest[0] on PE %d is %ld\n", me, dest[0]); + printf("dest[0] on PE %d is %ld\n", mype, dest[0]); shmem_finalize(); return 0; } diff --git a/example_code/shmem_put_signal_example.c b/example_code/shmem_put_signal_example.c index bee428254..c77d87bb9 100644 --- a/example_code/shmem_put_signal_example.c +++ b/example_code/shmem_put_signal_example.c @@ -9,19 +9,19 @@ int main(void) { shmem_init(); size_t size = 2048; - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int n = shmem_n_pes(); - int pe = (me + 1) % n; + int pe = (mype + 1) % n; uint64_t *message = malloc(size * sizeof(uint64_t)); static uint64_t sig_addr = 0; for (i = 0; i < size; i++) { - message[i] = me; + message[i] = mype; } uint64_t *data = shmem_calloc(size, sizeof(uint64_t)); - if (me == 0) { + if (mype == 0) { shmem_put_signal(data, message, size, &sig_addr, 1, SHMEM_SIGNAL_SET, pe); } else { diff --git a/example_code/shmem_quiet_example.c b/example_code/shmem_quiet_example.c index 09e771a4e..ba75e87e7 100644 --- a/example_code/shmem_quiet_example.c +++ b/example_code/shmem_quiet_example.c @@ -9,8 +9,8 @@ int main(void) { long x[3] = {0}; int y = 0; shmem_init(); - int me = shmem_my_pe(); - if (me == 0) { + int mype = shmem_my_pe(); + if (mype == 0) { shmem_put(dest, source, 3, 1); /* put1 */ shmem_put(&targ, &src, 1, 2); /* put2 */ shmem_quiet(); diff --git a/example_code/shmem_reduce_example.c b/example_code/shmem_reduce_example.c index 3a5e0e131..7d5b28b16 100644 --- a/example_code/shmem_reduce_example.c +++ b/example_code/shmem_reduce_example.c @@ -17,7 +17,7 @@ unsigned char is_valid(long value, int npes) { int main(void) { shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); size_t num = 32; @@ -27,7 +27,7 @@ int main(void) { unsigned char *valid_me = shmem_malloc(num * sizeof(unsigned char)); unsigned char *valid_all = shmem_malloc(num * sizeof(unsigned char)); - values[0] = recv_a_value((unsigned)me, npes); + values[0] = recv_a_value((unsigned)mype, npes); valid_me[0] = is_valid(values[0], npes); for (int i = 1; i < num; i++) { diff --git a/example_code/shmem_sync_example.c b/example_code/shmem_sync_example.c index 6d2bd7840..afc22794d 100644 --- a/example_code/shmem_sync_example.c +++ b/example_code/shmem_sync_example.c @@ -10,7 +10,7 @@ int main(void) { shmem_init(); config = NULL; - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); if (npes > 2) @@ -47,11 +47,11 @@ int main(void) { shmem_sync(threes_team); } - if (me && me % 3 == 0) { + if (mype && mype % 3 == 0) { if (x != 3) shmem_global_exit(3); } - else if (me && me % 2 == 0) { + else if (mype && mype % 2 == 0) { if (x != 2) shmem_global_exit(2); } diff --git a/example_code/shmem_team_split_2D.c b/example_code/shmem_team_split_2D.c index 39d61a3fb..acb2be653 100644 --- a/example_code/shmem_team_split_2D.c +++ b/example_code/shmem_team_split_2D.c @@ -33,7 +33,7 @@ int main(void) { for (int ydx = 0; ydx < ydim; ydx++) for (int xdx = 0; xdx < xdim; xdx++) { if ((my_x == xdx) && (my_y == ydx) && (my_z == zdx)) { - printf("(%d, %d, %d) is me = %d\n", my_x, my_y, my_z, pe); + printf("(%d, %d, %d) is mype = %d\n", my_x, my_y, my_z, pe); } shmem_team_sync(SHMEM_TEAM_WORLD); } diff --git a/example_code/writing_shmem_example.c b/example_code/writing_shmem_example.c index 4b0f614ea..e25be6fae 100644 --- a/example_code/writing_shmem_example.c +++ b/example_code/writing_shmem_example.c @@ -8,9 +8,9 @@ int main(void) { static short dest[SIZE]; static long lock = 0; shmem_init(); - int me = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); - if (me == 0) { + if (mype == 0) { /* initialize array */ for (int i = 0; i < SIZE; i++) source[i] = i; @@ -21,9 +21,9 @@ int main(void) { shmem_put(dest, source, SIZE, i); } shmem_barrier_all(); /* sync sender and receiver */ - if (me != 0) { + if (mype != 0) { shmem_set_lock(&lock); - printf("dest on PE %d is \t", me); + printf("dest on PE %d is \t", mype); for (int i = 0; i < SIZE; i++) printf("%hd \t", dest[i]); printf("\n"); From c3e23cf869fe610b63e1598e0c8fbda797c4fb8a Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Mon, 3 Feb 2020 19:46:21 -0500 Subject: [PATCH 10/23] Rename n -> npes for consistency --- example_code/shmem_put_signal_example.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example_code/shmem_put_signal_example.c b/example_code/shmem_put_signal_example.c index c77d87bb9..9e463f542 100644 --- a/example_code/shmem_put_signal_example.c +++ b/example_code/shmem_put_signal_example.c @@ -10,8 +10,8 @@ int main(void) { size_t size = 2048; int mype = shmem_my_pe(); - int n = shmem_n_pes(); - int pe = (mype + 1) % n; + int npes = shmem_n_pes(); + int pe = (mype + 1) % npes; uint64_t *message = malloc(size * sizeof(uint64_t)); static uint64_t sig_addr = 0; From b0b375bdeed10b04c31bfd034b3a9f30fd8741a3 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Tue, 4 Feb 2020 09:29:46 -0600 Subject: [PATCH 11/23] Manual example fixup --- example_code/shmem_ctx_pipelined_reduce.c | 4 ++-- example_code/shmem_team_split_2D.c | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/example_code/shmem_ctx_pipelined_reduce.c b/example_code/shmem_ctx_pipelined_reduce.c index 7bdd9059d..dbf555a2d 100644 --- a/example_code/shmem_ctx_pipelined_reduce.c +++ b/example_code/shmem_ctx_pipelined_reduce.c @@ -31,8 +31,8 @@ int main(void) { int p_idx = 0, p = 0; /* Index of ctx and pbuf (p_idx) for current pipeline stage (p) */ for (i = 1; i <= npes; i++) - shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * mype], &in_buf[PLEN * p], PLEN, - (mype + i) % npes); + shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * mype], &in_buf[PLEN * p], + PLEN, (mype + i) % npes); /* Issue communication for pipeline stage p, then accumulate results for stage * p-1 */ diff --git a/example_code/shmem_team_split_2D.c b/example_code/shmem_team_split_2D.c index acb2be653..4a7026fdc 100644 --- a/example_code/shmem_team_split_2D.c +++ b/example_code/shmem_team_split_2D.c @@ -6,7 +6,7 @@ int main(void) { int ydim = 4; shmem_init(); - int pe = shmem_my_pe(); + int mype = shmem_my_pe(); int npes = shmem_n_pes(); if (npes < (xdim * ydim)) { @@ -29,14 +29,17 @@ int main(void) { int my_y = shmem_team_my_pe(yteam); int my_z = shmem_team_my_pe(zteam); - for (int zdx = 0; zdx < zdim; zdx++) - for (int ydx = 0; ydx < ydim; ydx++) + for (int zdx = 0; zdx < zdim; zdx++) { + for (int ydx = 0; ydx < ydim; ydx++) { for (int xdx = 0; xdx < xdim; xdx++) { if ((my_x == xdx) && (my_y == ydx) && (my_z == zdx)) { - printf("(%d, %d, %d) is mype = %d\n", my_x, my_y, my_z, pe); + printf("(%d, %d, %d) is mype = %d\n", my_x, my_y, my_z, mype); } shmem_team_sync(SHMEM_TEAM_WORLD); } + } + } shmem_finalize(); + return 0; } From 44128abe2dc50077d55ac7b91df56926cf2de232 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Tue, 4 Feb 2020 15:06:41 -0600 Subject: [PATCH 12/23] Unify (colorized) formatting of API listing, examples --- content/backmatter.tex | 37 +++-- content/interoperability.tex | 33 ++-- content/memory_model.tex | 62 ++++---- utils/defs.tex | 288 ++++++++++------------------------- 4 files changed, 143 insertions(+), 277 deletions(-) diff --git a/content/backmatter.tex b/content/backmatter.tex index a67acc6f0..be40f3fbd 100644 --- a/content/backmatter.tex +++ b/content/backmatter.tex @@ -32,18 +32,19 @@ \section*{Incorporating OpenSHMEM into Programs}\label{sec:writing_programs} In \openshmem, the order in which lines appear in the output is not deterministic because \acp{PE} execute asynchronously in parallel. -\begin{minipage}{\linewidth} -\vspace{0.1in} -\numberedlisting{caption={``Hello World'' example program in \Cstd},label=openshmem-hello,language=OSH2+C} - {example_code/hello-openshmem.c} -\outputlisting{language=bash,caption={Possible ordering of expected output with 4 \acp{PE} from the program in Listing~\ref{openshmem-hello}}} - {example_code/hello-openshmem-c.output} -\vspace{0.1in} -\end{minipage} +\SourceExample{example_code/hello-openshmem.c}{ + \label{openshmem-hello} + ``Hello World'' example program in \Cstd +} + +\ProgramOutput{example_code/hello-openshmem-c.output}{ + Possible ordering of expected output with 4 \acp{PE} from the + program in Example~\ref{openshmem-hello} +} \clearpage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -The example in Listing~\ref{openshmem-hello-symmetric} shows a more complex +The example in Example~\ref{openshmem-hello-symmetric} shows a more complex \openshmem program that illustrates the use of symmetric data objects. Note the declaration of the \VAR{static short dest} array and its use as the remote destination in \hyperref[subsec:shmem_put]{\FUNC{shmem\_put}}. @@ -61,17 +62,15 @@ \section*{Incorporating OpenSHMEM into Programs}\label{sec:writing_programs} The \source{} object does not need to be symmetric because \PUT{} handles the references to the \VAR{source} array only on the active (local) side. -\begin{minipage}{\linewidth} -\vspace{0.1in} -\numberedlisting{caption={Example program with symmetric data objects},label=openshmem-hello-symmetric,language=OSH2+C} - {example_code/writing_shmem_example.c} -\outputlisting{language=bash,caption={Possible ordering of expected output with 4 \acp{PE} from the program in Listing~\ref{openshmem-hello-symmetric}}} - {example_code/writing_shmem_example.output} -\vspace{0.1in} -\end{minipage} - - +\SourceExample{example_code/writing_shmem_example.c}{ + \label{openshmem-hello-symmetric} + Example program with symmetric data objects +} +\ProgramOutput{example_code/writing_shmem_example.output}{ + Possible ordering of expected output with 4~\acp{PE} from the + program in Example~\ref{openshmem-hello-symmetric} +} \chapter{Compiling and Running Programs}\label{sec:compiling} The \openshmem Specification does not specify how diff --git a/content/interoperability.tex b/content/interoperability.tex index 4cec41b76..c3d3a7fa6 100644 --- a/content/interoperability.tex +++ b/content/interoperability.tex @@ -126,23 +126,22 @@ \subsection{Mapping Process Identification Numbers} \subsubsection*{Examples} \label{subsubsec:interoperability:id:example} -The following example demonstrates how to manage the mapping between \openshmem -\ac{PE} numbers and \ac{MPI} ranks in \VAR{MPI\_COMM\_WORLD} in a hybrid \openshmem -and \ac{MPI} program. - -\lstinputlisting[language={C}, tabsize=2, - basicstyle=\ttfamily\footnotesize] - {example_code/hybrid_mpi_mapping_id.c} - -The following example demonstrates an alternative approach for managing the mapping -of process identification numbers in a hybrid program. The program creates a -new MPI communicator, named \VAR{shmem\_comm}, that contains all -processes in \VAR{MPI\_COMM\_WORLD} and each process has the same \ac{MPI} rank -number as its \openshmem \ac{PE} number. - -\lstinputlisting[language={C}, tabsize=2, - basicstyle=\ttfamily\footnotesize] - {example_code/hybrid_mpi_mapping_id_shmem_comm.c} + +\SourceExample{example_code/hybrid_mpi_mapping_id.c}{ + The following example demonstrates how to manage the mapping between + \openshmem \ac{PE} numbers and \ac{MPI} ranks in + \VAR{MPI\_COMM\_WORLD} in a hybrid \openshmem and \ac{MPI} program. +} + + +\SourceExample{example_code/hybrid_mpi_mapping_id_shmem_comm.c}{ + The following example demonstrates an alternative approach for + managing the mapping of process identification numbers in a hybrid + program. The program creates a new MPI communicator, named + \VAR{shmem\_comm}, that contains all processes in + \VAR{MPI\_COMM\_WORLD} and each process has the same \ac{MPI} rank + number as its \openshmem \ac{PE} number. +} \subsection{RMA Programming Models} \label{subsec:interoperability:rma} diff --git a/content/memory_model.tex b/content/memory_model.tex index 93a41c337..3b8c42d12 100644 --- a/content/memory_model.tex +++ b/content/memory_model.tex @@ -129,37 +129,37 @@ \subsection{Atomicity Guarantees}\label{subsec:amo_guarantees} with non-atomic operations, such as one-sided \OPR{put} or \OPR{get} operations, will invalidate the atomicity guarantees. -\cexample - { - The following \CorCpp example illustrates scenario 1. - In this example, different atomicity domains are used to access - the same location, resulting in undefined behavior. - The undefined behavior can be resolved by using communication - contexts in the same atomicity domain in all concurrent operations. - } {./example_code/amo_scenario_1.c} +\SourceExample{./example_code/amo_scenario_1.c}{ + The following \CorCpp example illustrates scenario 1. + In this example, different atomicity domains are used to access + the same location, resulting in undefined behavior. + The undefined behavior can be resolved by using communication + contexts in the same atomicity domain in all concurrent operations. +} -\cexample - {The following \CorCpp example illustrates scenario 2. In this example, - different datatypes are used to access the same location concurrently, - resulting in undefined behavior. The undefined behavior can be resolved by - using the same datatype in all concurrent operations. For example, the - 32-bit value can be left-shifted and a 64-bit atomic OR operation can be - used.} - {./example_code/amo_scenario_2.c} +\SourceExample{./example_code/amo_scenario_2.c}{ + The following \CorCpp example illustrates scenario 2. In this example, + different datatypes are used to access the same location concurrently, + resulting in undefined behavior. The undefined behavior can be resolved by + using the same datatype in all concurrent operations. For example, the + 32-bit value can be left-shifted and a 64-bit atomic OR operation can be + used. +} -\cexample - {The following \CorCpp example illustrates scenario 3. In this example, - atomic increment operations are concurrent with a non-atomic reduction - operation, resulting in undefined behavior. The undefined behavior can be - resolved by inserting a barrier operation before the reduction. The - barrier ensures that all local and remote AMOs have completed before the - reduction operation accesses $x$.} - {./example_code/amo_scenario_3.c} +\SourceExample{./example_code/amo_scenario_3.c}{ + The following \CorCpp example illustrates scenario 3. In this example, + atomic increment operations are concurrent with a non-atomic reduction + operation, resulting in undefined behavior. The undefined behavior can be + resolved by inserting a barrier operation before the reduction. The + barrier ensures that all local and remote AMOs have completed before the + reduction operation accesses $x$. +} + +\SourceExample{./example_code/amo_scenario_4.c}{ + The following \CorCpp example illustrates scenario 4. In this example, an + \openshmem atomic increment operation is concurrent with a local increment + operation, resulting in undefined behavior. The undefined behavior can be + resolved by replacing the local increment operation with an \openshmem + atomic increment. +} -\cexample - {The following \CorCpp example illustrates scenario 4. In this example, an - \openshmem atomic increment operation is concurrent with a local increment - operation, resulting in undefined behavior. The undefined behavior can be - resolved by replacing the local increment operation with an \openshmem - atomic increment.} - {./example_code/amo_scenario_4.c} diff --git a/utils/defs.tex b/utils/defs.tex index fdfef4bb3..b51304fdb 100644 --- a/utils/defs.tex +++ b/utils/defs.tex @@ -204,146 +204,52 @@ % % This section is for example code listings % -\definecolor{gray}{rgb}{0.92,0.92,0.92} -\lstset{ % set defaults for languages not otherwise defined - breakatwhitespace=true, % sets if automatic breaks should only happen at whitespace +\lstdefinestyle{SourceListingsDefault}{ + language={C}, + escapechar=@, + tabsize=2, basicstyle=\ttfamily\footnotesize, - breaklines=true, % sets automatic line breaking - extendedchars=true, % lets you use non-ASCII characters; for 8-bits - % encodings only, does not work with UTF-8 - keepspaces=true, % keeps spaces in text, useful for keeping indentation of code - % (possibly needs columns=flexible) - morekeywords={*,...}, % if you want to add more keywords to the set - showspaces=false, % show spaces everywhere adding particular underscores; - % it overrides 'showstringspaces' - showstringspaces=false, % underline spaces within strings only - showtabs=false, % show tabs within strings adding particular underscores -} - -\def\StandardListing { - \lstset { - breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace - basicstyle=\ttfamily\footnotesize, - breaklines=true, % sets automatic line breaking - escapeinside={\%*}{*)}, % if you want to add LaTeX within your code - extendedchars=true, % lets you use non-ASCII characters; for 8-bits - % encodings only, does not work with UTF-8 - keepspaces=true, % keeps spaces in text, useful for keeping - % indentation of code (possibly needs columns=flexible) - morekeywords={*,...}, % if you want to add more keywords to the set - showspaces=false, % show spaces everywhere adding particular underscores; - % it overrides 'showstringspaces' - showstringspaces=false, % underline spaces within strings only - showtabs=false, % show tabs within strings adding particular underscores - backgroundcolor=\color{gray}, - } -} - -\def\ProgramNumberedListing { - \StandardListing - \lstset { - numbers=left, - numberstyle=\footnotesize - } -} - -\newcommand{\numberedlisting}[2] { - \ProgramNumberedListing - \lstinputlisting[#1]{#2} - \StandardListing -} - -\newcommand{\outputlisting}[2] { -\begin{minipage}{\linewidth} -\vspace{0.1in} - \lstinputlisting[#1]{#2} - \StandardListing -\vspace{0.1in} -\end{minipage} -} - -\lstdefinelanguage{OSH+C}[]{C}{ - classoffset=1, - morekeywords={ - size_t, ptrdiff_t, - SHMEM_BCAST_SYNC_SIZE, SHMEM_SYNC_VALUE, - start_pes, - my_pe, _my_pe, shmem_my_pe, - num_pes, _num_pes, shmem_n_pes, - shmem_int_p, shmem_short_p, shmem_long_p, - shmem_int_put, shmem_short_put, shmem_long_put, - shmem_barrier_all, shmem_barrier, - shmalloc, shfree, shrealloc, - shmem_broadcast32, shmem_broadcast64, - shmem_short_inc, shmem_int_inc, shmem_long_inc, - shmem_short_add, shmem_int_add, shmem_long_add, - shmem_short_finc, shmem_int_finc, shmem_long_finc, - shmem_short_fadd, shmem_int_fadd, shmem_long_fadd, - shmem_set_lock, shmem_test_lock, shmem_clear_lock, - shmem_long_sum_to_all, - shmem_complexd_sum_to_all - }, - keywordstyle=\color{black}\textbf, + showstringspaces=false, + % Preprocessor directives classoffset=0, - sensitive=true -} - -\lstdefinelanguage{OSH2+C}[]{OSH+C}{ + keywords={\#include, \#pragma, \#if, \#ifdef, \#else, \#endif}, + keywordstyle=\bfseries\color{CadetBlue}, + % Language keywords classoffset=1, - morekeywords={ - shmem_init, - shmem_finalize, - shmem_malloc, - shmem_my_pe, - shmem_error, - shmem_global_exit, - }, - keywordstyle=\color{black}\textbf, + keywords={if, else, for, while, return, break, static, const, volatile, + sizeof}, + keywordstyle=\bfseries\color{Orchid}, + % Types + classoffset=2, + keywords={TYPE, TYPENAME, SIZE, + void, bool, _Bool, unsigned, char, short, int, long, + float, double, _Complex, complex, size_t, ptrdiff_t, + _Thread_local, shmem_ctx_t, shmem_team_t, + int8_t, int16_t, int32_t, int64_t, + uint8_t, uint16_t, uint32_t, uint64_t}, + keywordstyle=\color{OliveGreen}, + % Other elements + classoffset=3, + keywords={NULL}, + keywordstyle=\color{Cyan}, + % Other syntax elements classoffset=0, - sensitive=true + % morecomment=[s]{\<}{\>}, + commentstyle=\itshape\color{BrickRed}, + stringstyle=\color{DarkOrchid}, + backgroundcolor=\color{gray}, } -\lstdefinelanguage{OSH+F}[]{Fortran}{ - classoffset=1, - morekeywords={ - SHMEM_BCAST_SYNC_SIZE, SHMEM_SYNC_VALUE, - start_pes, - my_pe, shmem_my_pe, - num_pes, shmem_n_pes, - shmem_int_p, shmem_short_p, shmem_long_p, - shmem_int_put, shmem_short_put, shmem_long_put, - shmem_barrier_all, shmem_barrier, - shpalloc, shpdeallc, shpclmove, - shmem_broadcast32, shmem_broadcast64, - shmem_broadcast4, shmem_broadcast8, - shmem_short_inc, shmem_int_inc, shmem_long_inc, - shmem_short_add, shmem_int_add, shmem_long_add, - shmem_short_finc, shmem_int_finc, shmem_long_finc, - shmem_short_fadd, shmem_int_fadd, shmem_long_fadd, - shmem_set_lock, shmem_test_lock, shmem_clear_lock, - shmem_long_sum_to_all, - }, - keywordstyle=\color{black}\textbf, - classoffset=0, - sensitive=false -} +\definecolor{gray}{rgb}{0.92,0.92,0.92} -\lstdefinelanguage{OSH2+F}[]{OSH+F}{ - classoffset=1, - morekeywords={ - shmem_init, - shmem_finalize, - shmem_malloc, - shmem_my_pe, - shmem_error, - shmem_global_exit, - }, - keywordstyle=\color{black}\textbf, - classoffset=0, - sensitive=true +\lstdefinestyle{PrototypeListingsDefault}{ + style=SourceListingsDefault, + backgroundcolor=\color{gray}, } +\lstset{style=SourceListingsDefault} + % % End this section is for example code listings % @@ -407,57 +313,34 @@ \lstnewenvironment{Cpp11synopsis} { \textbf{C++11:} - \lstset{language={C++}, backgroundcolor=\color{gray}, lineskip=2pt, - escapechar=@, - morekeywords={size_t, ptrdiff_t, TYPE, noreturn}, - aboveskip=0pt, belowskip=0pt}}{} + \lstset{style=PrototypeListingsDefault} +}{} \lstnewenvironment{C11synopsis} { \textbf{C11:} - \lstset{language={C}, backgroundcolor=\color{gray}, lineskip=2pt, - escapechar=@, - morekeywords={size_t, ptrdiff_t, TYPE, _Noreturn, shmem_ctx_t, - shmem_team_t, shmem_team_config_t, uint64_t}, - aboveskip=0pt, belowskip=0pt}}{} + \lstset{style=PrototypeListingsDefault} +}{} \lstnewenvironment{CsynopsisCol} { - \lstset{language={C}, backgroundcolor=\color{gray}, lineskip=2pt, - escapechar=@, - morekeywords={size_t, ptrdiff_t, TYPE, TYPENAME, SIZE, shmem_ctx_t, - shmem_team_t, shmem_team_config_t, uint64_t}, - aboveskip=0pt, belowskip=0pt}}{} + \lstset{style=PrototypeListingsDefault} +}{} \lstnewenvironment{Csynopsis} { \textbf{C/C++:} - \lstset{language={C}, backgroundcolor=\color{gray}, lineskip=2pt, - escapechar=@, - morekeywords={size_t, ptrdiff_t, TYPE, TYPENAME, SIZE, shmem_ctx_t, - shmem_team_t, shmem_team_config_t, uint64_t}, - aboveskip=0pt, belowskip=0pt}}{} + \lstset{style=PrototypeListingsDefault} +}{} \lstnewenvironment{CsynopsisST} { \textbf{C/C++:} - \color{red} - {\lstset{language={C}, backgroundcolor=\color{gray}, lineskip=2pt, - escapechar=@, - morekeywords={size_t, ptrdiff_t, TYPE, TYPENAME, SIZE, shmem_ctx_t, - shmem_team_t, uint64_t}, - aboveskip=0pt, belowskip=0pt}}}{} - -\lstnewenvironment{Fsynopsis} -{ \deprecationstart \\ - \textbf{FORTRAN:} - \lstset{language={Fortran}, backgroundcolor=\color{gray}, lineskip=3pt, - escapechar=@, - deletekeywords=[2]{STATUS}, - deletekeywords=[3]{LOG}, aboveskip=0pt, - belowskip=0pt}} -{ \deprecationend } + \color{red}{ + \lstset{style=PrototypeListingsDefault} + } +}{} \newenvironment{apiarguments}{ \newcommand{\apiargument}[3]{ @@ -525,61 +408,46 @@ } \theoremstyle{definition} -\newtheorem{example}{Example} +\newtheorem{source_example}{Example} +\newtheorem{program_output}{Output} + \newenvironment{apiexamples}{ \newcommand{\apicexample}[4][]{ - \begin{example} + \begin{source_example} \ifthenelse{\equal{##1}{}}{}{\label{##1}} ##2 - \end{example} - \lstinputlisting[language={C}, tabsize=2, - basicstyle=\ttfamily\footnotesize, - % Preprocessor directives - classoffset=0, - keywords={\#include, \#pragma, \#if, \#ifdef, \#else, \#endif}, - keywordstyle=\bfseries\color{CadetBlue}, - % Language keywords - classoffset=1, - keywords={if, else, for, while, return, break, static, const, volatile, - sizeof}, - keywordstyle=\bfseries\color{Orchid}, - % Types - classoffset=2, - keywords={void, bool, _Bool, unsigned, char, short, int, long, - float, double, _Complex, complex, size_t, ptrdiff_t, - _Thread_local, shmem_ctx_t, shmem_team_t, - int8_t, int16_t, int32_t, int64_t, - uint8_t, uint16_t, uint32_t, uint64_t}, - keywordstyle=\color{OliveGreen}, - % Other elements - classoffset=3, - keywords={NULL}, - keywordstyle=\color{Cyan}, - % Other syntax elements - classoffset=0, - % morecomment=[s]{\<}{\>}, - commentstyle=\itshape\color{BrickRed}, - stringstyle=\color{DarkOrchid}, - ]{##3} - ##4} - \newcommand{\apifexample}[4][]{ - \begin{example} - \ifthenelse{\equal{##1}{}}{}{\label{##1}} - ##2 - \end{example} - \lstinputlisting[language={Fortran}, tabsize=2, - basicstyle=\ttfamily\footnotesize, deletekeywords={TARGET}]{##3} + \end{source_example} + \lstinputlisting[style=SourceListingsDefault]{##3} ##4} \vspace{-2pt} \item[EXAMPLES] \hfill \\ \vspace{-2pt} }{} -\newcommand{\cexample}[2]{ - #1 - \lstinputlisting[language={C}, tabsize=2, - basicstyle=\ttfamily\footnotesize, - morekeywords={size_t, ptrdiff_t, shmem_ctx_t}]{#2}} +\newcommand{\SourceExample}[2]{ + \noindent + \begin{minipage}{\linewidth} + \vspace{0.1in} + \begin{source_example} + #2 \hfill + \lstinputlisting[style=SourceListingsDefault]{#1} + \end{source_example} + \vspace{0.1in} + \end{minipage} +} + +\newcommand{\ProgramOutput}[2]{ + \noindent + \begin{minipage}{\linewidth} + \vspace{0.1in} + \begin{program_output} + #2 \hfill + \lstinputlisting[style=SourceListingsDefault]{#1} + \end{program_output} + \vspace{0.1in} + \end{minipage} +} + % % End library API description template commands % From f578b67b8011522df5bf220d167f2e199881f272 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Tue, 4 Feb 2020 15:14:33 -0600 Subject: [PATCH 13/23] Rename lingering my_pe -> mype occurrences --- example_code/shmem_ctx_invalid.c | 6 +++--- example_code/shmem_team_translate_pe.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/example_code/shmem_ctx_invalid.c b/example_code/shmem_ctx_invalid.c index 843c2a1b3..5e5335140 100644 --- a/example_code/shmem_ctx_invalid.c +++ b/example_code/shmem_ctx_invalid.c @@ -29,7 +29,7 @@ int main() { if (provided != SHMEM_THREAD_MULTIPLE) shmem_global_exit(2); - const int my_pe = shmem_my_pe(); + const int mype = shmem_my_pe(); const int npes = shmem_n_pes(); const int count = 1 << 15; @@ -50,13 +50,13 @@ int main() { #pragma omp for for (int i = 0; i < npes; i++) for (int j = 0; j < count; j++) - src_bufs[i][j] = (my_pe << 10) + my_thrd; + src_bufs[i][j] = (mype << 10) + my_thrd; lib_thread_register(); #pragma omp for for (int i = 0; i < npes; i++) - lib_thread_putmem(dst_bufs[my_pe], src_bufs[i], + lib_thread_putmem(dst_bufs[mype], src_bufs[i], count * sizeof(*src_bufs[i]), i); lib_thread_unregister(); diff --git a/example_code/shmem_team_translate_pe.c b/example_code/shmem_team_translate_pe.c index 4b5adf990..a4704c02c 100644 --- a/example_code/shmem_team_translate_pe.c +++ b/example_code/shmem_team_translate_pe.c @@ -2,7 +2,7 @@ #include int main(void) { - int my_pe; + int mype; int npes; int t_pe; int t_global; @@ -11,7 +11,7 @@ int main(void) { shmem_init(); config = NULL; - my_pe = shmem_my_pe(); + mype = shmem_my_pe(); npes = shmem_n_pes(); shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, (npes + 1) / 2, config, 0, @@ -21,7 +21,7 @@ int main(void) { t_pe = shmem_team_my_pe(new_team); t_global = shmem_team_translate_pe(new_team, t_pe, SHMEM_TEAM_WORLD); - if (t_global != my_pe) { + if (t_global != mype) { shmem_global_exit(1); } } From e81f0876c669605b5b6651622ecf42a3c89e95bc Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Tue, 4 Feb 2020 15:34:11 -0600 Subject: [PATCH 14/23] More example consistency cleanup --- example_code/shmem_team_context.c | 6 +++--- example_code/shmem_team_split_strided.c | 12 +++++------- example_code/shmem_team_translate_pe.c | 15 ++++++--------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/example_code/shmem_team_context.c b/example_code/shmem_team_context.c index 0cb9f09cd..6ab0beb90 100644 --- a/example_code/shmem_team_context.c +++ b/example_code/shmem_team_context.c @@ -38,9 +38,9 @@ void my_send_to_neighbor(shmem_ctx_t ctx, int *val) { shmem_team_t team; shmem_ctx_get_team(ctx, &team); - int pe = shmem_team_my_pe(team); - int npes = shmem_team_n_pes(team); - int rpe = (pe + 1) % npes; + int team_mype = shmem_team_my_pe(team); + int team_npes = shmem_team_n_pes(team); + int rpe = (team_mype + 1) % team_npes; // put my pe number in the buffer on my right hand neighbor shmem_ctx_int_put(ctx, val, &pe, 1, rpe); diff --git a/example_code/shmem_team_split_strided.c b/example_code/shmem_team_split_strided.c index 09e685676..25525cae6 100644 --- a/example_code/shmem_team_split_strided.c +++ b/example_code/shmem_team_split_strided.c @@ -7,24 +7,22 @@ #include int main(int argc, char *argv[]) { - int rank, npes; - int t_pe, t_size; shmem_team_t new_team; shmem_team_config_t *config; shmem_init(); config = NULL; - rank = shmem_my_pe(); - npes = shmem_n_pes(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, npes / 2, config, 0, &new_team); if (new_team != SHMEM_TEAM_INVALID) { - t_size = shmem_team_n_pes(new_team); - t_pe = shmem_team_my_pe(new_team); + int team_npes = shmem_team_n_pes(new_team); + int team_mype = shmem_team_my_pe(new_team); - if ((rank % 2 != 0) || (rank / 2 != t_pe) || (npes / 2 != t_size)) { + if ((mype % 2 != 0) || (mype / 2 != team_mype) || (npes / 2 != team_npes)) { shmem_global_exit(1); } } diff --git a/example_code/shmem_team_translate_pe.c b/example_code/shmem_team_translate_pe.c index a4704c02c..56dc9da19 100644 --- a/example_code/shmem_team_translate_pe.c +++ b/example_code/shmem_team_translate_pe.c @@ -2,26 +2,23 @@ #include int main(void) { - int mype; - int npes; - int t_pe; - int t_global; shmem_team_t new_team; shmem_team_config_t *config; shmem_init(); config = NULL; - mype = shmem_my_pe(); - npes = shmem_n_pes(); + int mype = shmem_my_pe(); + int npes = shmem_n_pes(); shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, (npes + 1) / 2, config, 0, &new_team); if (new_team != SHMEM_TEAM_INVALID) { - t_pe = shmem_team_my_pe(new_team); - t_global = shmem_team_translate_pe(new_team, t_pe, SHMEM_TEAM_WORLD); + int team_mype = shmem_team_my_pe(new_team); + int global_mype = + shmem_team_translate_pe(new_team, team_mype, SHMEM_TEAM_WORLD); - if (t_global != mype) { + if (global_mype != mype) { shmem_global_exit(1); } } From 455bdfd1afca78e003c479fbd68a6ecc673957f0 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Tue, 4 Feb 2020 16:59:27 -0600 Subject: [PATCH 15/23] Update/revise syntax highlighting keywords and styling --- utils/defs.tex | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/utils/defs.tex b/utils/defs.tex index b51304fdb..eff4cfba0 100644 --- a/utils/defs.tex +++ b/utils/defs.tex @@ -84,7 +84,7 @@ %% Specialized declaration/creation and generate reference. \newcommand{\EnvVarDecl}[1]{\EnvVarRef{#1}} \newcommand{\FuncDecl}[1]{{\ListingsCurrentStyle{#1}}\FuncIndex{#1}} -\newcommand{\FuncParam}[1]{<{\ListingsKeywordStyle{#1}}>} +\newcommand{\FuncParam}[1]{{\ListingsParamStyle{#1}}} \newcommand{\LibConstDecl}[2][\CorCpp]{% \parbox[t]{5cm}{~\\[-4pt] #1: \\\hspace*{8mm} \LibConstRef{#2} \\~}} \newcommand{\LibHandleDecl}[2][\CorCpp]{% @@ -126,9 +126,6 @@ \newcommand\ListingsCurrentStyle{} \lst@AddToHook{Output}{\global\let\ListingsCurrentStyle\lst@thestyle} \lst@AddToHook{OutputOther}{\global\let\ListingsCurrentStyle\lst@thestyle} -\newcommand\ListingsKeywordStyle{} -\lst@AddToHook{Output}{\global\let\ListingsKeywordStyle\lst@keywordstyle} -\lst@AddToHook{OutputOther}{\global\let\ListingsKeywordStyle\lst@keywordstyle} \makeatother % @@ -205,6 +202,8 @@ % This section is for example code listings % +\newcommand{\ListingsParamStyle}{\bfseries\itshape\color{CadetBlue}} + \lstdefinestyle{SourceListingsDefault}{ language={C}, escapechar=@, @@ -217,22 +216,30 @@ keywordstyle=\bfseries\color{CadetBlue}, % Language keywords classoffset=1, - keywords={if, else, for, while, return, break, static, const, volatile, - sizeof}, + keywords={ + if, else, for, while, return, break, static, const, volatile, + sizeof, typedef, struct, union, + }, keywordstyle=\bfseries\color{Orchid}, % Types classoffset=2, - keywords={TYPE, TYPENAME, SIZE, + keywords={ + _Thread_local, _Noreturn, void, bool, _Bool, unsigned, char, short, int, long, float, double, _Complex, complex, size_t, ptrdiff_t, - _Thread_local, shmem_ctx_t, shmem_team_t, int8_t, int16_t, int32_t, int64_t, - uint8_t, uint16_t, uint32_t, uint64_t}, + uint8_t, uint16_t, uint32_t, uint64_t, + shmem_ctx_t, shmem_team_t, shmem_team_config_t, + }, keywordstyle=\color{OliveGreen}, % Other elements classoffset=3, keywords={NULL}, keywordstyle=\color{Cyan}, + % Type-generic parameters (see FuncParam) + classoffset=4, + keywords={TYPE, TYPENAME, SIZE}, + keywordstyle=\ListingsParamStyle, % Other syntax elements classoffset=0, % morecomment=[s]{\<}{\>}, From ff8bfcb776f49b9d1b9abbc82c5721274b7c54b6 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Tue, 4 Feb 2020 17:09:41 -0600 Subject: [PATCH 16/23] Remove forced page breaks --- content/shmem_malloc_hints.tex | 1 - main_spec.tex | 1 - 2 files changed, 2 deletions(-) diff --git a/content/shmem_malloc_hints.tex b/content/shmem_malloc_hints.tex index b5a6c0945..165901e06 100644 --- a/content/shmem_malloc_hints.tex +++ b/content/shmem_malloc_hints.tex @@ -86,4 +86,3 @@ load/store operations from the origin \ac{PE} or vice versa. } \end{apidefinition} -\newpage diff --git a/main_spec.tex b/main_spec.tex index d11ab6857..b0eaadc14 100644 --- a/main_spec.tex +++ b/main_spec.tex @@ -100,7 +100,6 @@ \subsection{Memory Management Routines} \subsubsection{\textbf{SHMEM\_MALLOC, SHMEM\_FREE, SHMEM\_REALLOC, SHMEM\_ALIGN}}\label{subsec:shfree} \input{content/shmem_malloc.tex} -\newpage \subsubsection{\textbf{SHMEM\_MALLOC\_WITH\_HINTS}}\label{subsec:shmmallochint} \input{content/shmem_malloc_hints.tex} From 276081a511074892d6639d99dcaaba0f8c81599d Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Tue, 4 Feb 2020 17:16:53 -0600 Subject: [PATCH 17/23] Styling tweak --- utils/defs.tex | 2 -- 1 file changed, 2 deletions(-) diff --git a/utils/defs.tex b/utils/defs.tex index eff4cfba0..819ba8338 100644 --- a/utils/defs.tex +++ b/utils/defs.tex @@ -241,8 +241,6 @@ keywords={TYPE, TYPENAME, SIZE}, keywordstyle=\ListingsParamStyle, % Other syntax elements - classoffset=0, - % morecomment=[s]{\<}{\>}, commentstyle=\itshape\color{BrickRed}, stringstyle=\color{DarkOrchid}, backgroundcolor=\color{gray}, From 2e537b082d731c2947c7b6d0a147a8fb927d94ab Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Tue, 4 Feb 2020 21:42:55 -0600 Subject: [PATCH 18/23] More manual example fixup --- content/backmatter.tex | 6 +++--- content/shmem_get.tex | 2 +- content/shmem_reductions.tex | 2 +- content/shmem_test_some.tex | 2 +- example_code/shmem_sync_example.c | 11 +++++------ example_code/shmem_team_context.c | 4 ++-- example_code/shmem_team_split_strided.c | 7 +------ example_code/shmem_team_translate_pe.c | 6 ++---- utils/defs.tex | 2 ++ 9 files changed, 18 insertions(+), 24 deletions(-) diff --git a/content/backmatter.tex b/content/backmatter.tex index be40f3fbd..961773232 100644 --- a/content/backmatter.tex +++ b/content/backmatter.tex @@ -85,7 +85,7 @@ \subsection*{Programs written in \Cstd} \textbf{oshcc}, to aid in the compilation of \Cstd programs. The wrapper may be called as follows: -\begin{lstlisting}[language=bash] +\begin{lstlisting}[] oshcc -o myprogram myprogram.c \end{lstlisting} Where the $\langle\mbox{compiler options}\rangle$ are options understood by the @@ -98,7 +98,7 @@ \subsection*{Programs written in \Cpp} \textbf{oshc++}, to aid in the compilation of \Cpp programs. The wrapper may be called as follows: -\begin{lstlisting}[language=bash] +\begin{lstlisting}[] oshc++ -o myprogram myprogram.cpp \end{lstlisting} Where the $\langle\mbox{compiler options}\rangle$ are options understood by the @@ -111,7 +111,7 @@ \section{Running Programs} \textbf{oshrun}, to launch \openshmem programs. The wrapper may be called as follows: -\begin{lstlisting}[language=bash] +\begin{lstlisting}[] oshrun -np <#> \end{lstlisting} The arguments for \textbf{oshrun} are: diff --git a/content/shmem_get.tex b/content/shmem_get.tex index 7123457e6..5827598a5 100644 --- a/content/shmem_get.tex +++ b/content/shmem_get.tex @@ -18,7 +18,7 @@ \begin{CsynopsisCol} void @\FuncDecl{shmem\_get\FuncParam{SIZE}}@(void *dest, const void *source, size_t nelems, int pe); -void @\FuncDecl{shmem\_ctx\_get\FuncParam{SIZE}}@(shmem_ctx_t ctx, void *dest, const void *source, size_t nelems, int pe); +void @\FuncDecl{shmem\_ctx\_get\FuncParam{SIZE}}@(shmem_ctx_t ctx, void *dest, const void *source, size_t nelems, int pe); \end{CsynopsisCol} where \SIZE{} is one of \CONST{8, 16, 32, 64, 128}. diff --git a/content/shmem_reductions.tex b/content/shmem_reductions.tex index 02ab0e8d8..7c738a0bb 100644 --- a/content/shmem_reductions.tex +++ b/content/shmem_reductions.tex @@ -315,7 +315,7 @@ \begin{apiexamples} \apicexample - {This \CorCpp reduction example gets integers from an external + {This \Cstd[11] reduction example gets integers from an external source (random generator in this example), tests to see if the \ac{PE} got a valid value, and outputs the sum of values for which all \acp{PE} got a valid value.} diff --git a/content/shmem_test_some.tex b/content/shmem_test_some.tex index ac93f552b..e02b82d14 100644 --- a/content/shmem_test_some.tex +++ b/content/shmem_test_some.tex @@ -93,7 +93,7 @@ \begin{apiexamples} \apicexample {The following \Cstd[11] example demonstrates the use of - \FUNC{shmem\_test\_some} to process a simple all-to-all transfer of N + \FUNC{shmem\_test\_some} to process a simple all-to-all transfer of $N$ data elements via a sum reduction, while potentially overlapping communication with computation. This pattern is similar to the \FUNC{shmem\_test\_any} example above, but each while loop iteration may diff --git a/example_code/shmem_sync_example.c b/example_code/shmem_sync_example.c index afc22794d..891d49087 100644 --- a/example_code/shmem_sync_example.c +++ b/example_code/shmem_sync_example.c @@ -6,10 +6,9 @@ int main(void) { shmem_team_t twos_team = SHMEM_TEAM_INVALID; shmem_team_t threes_team = SHMEM_TEAM_INVALID; - shmem_team_config_t *config; + shmem_team_config_t *config = NULL; shmem_init(); - config = NULL; int mype = shmem_my_pe(); int npes = shmem_n_pes(); @@ -21,15 +20,15 @@ int main(void) { shmem_team_split_strided(SHMEM_TEAM_WORLD, 3, 3, (npes - 1) / 3, config, 0, &threes_team); - int my_pe_twos = shmem_team_my_pe(twos_team); - int my_pe_threes = shmem_team_my_pe(threes_team); + int mype_twos = shmem_team_my_pe(twos_team); + int mype_threes = shmem_team_my_pe(threes_team); int npes_twos = shmem_team_n_pes(twos_team); int npes_threes = shmem_team_n_pes(threes_team); if (twos_team != SHMEM_TEAM_INVALID) { /* put the value 2 to the next team member in a circular fashion */ shmem_p(&x, 2, - shmem_team_translate_pe(twos_team, (my_pe_twos + 1) % npes_twos, + shmem_team_translate_pe(twos_team, (mype_twos + 1) % npes_twos, SHMEM_TEAM_WORLD)); shmem_quiet(); shmem_sync(twos_team); @@ -41,7 +40,7 @@ int main(void) { /* put the value 3 to the next team member in a circular fashion */ shmem_p(&x, 3, shmem_team_translate_pe(threes_team, - (my_pe_threes + 1) % npes_threes, + (mype_threes + 1) % npes_threes, SHMEM_TEAM_WORLD)); shmem_quiet(); shmem_sync(threes_team); diff --git a/example_code/shmem_team_context.c b/example_code/shmem_team_context.c index 6ab0beb90..601927ed8 100644 --- a/example_code/shmem_team_context.c +++ b/example_code/shmem_team_context.c @@ -54,8 +54,7 @@ int main() { shmem_team_t team_2s, team_3s; shmem_ctx_t ctx_2s, ctx_3s; - shmem_team_config_t conf; - conf.num_contexts = 1; + shmem_team_config_t conf = {.num_contexts = 1}; long cmask = SHMEM_TEAM_NUM_CONTEXTS; // Create team with PEs numbered 0, 2, 4, ... @@ -106,4 +105,5 @@ int main() { shmem_team_destroy(team_3s); shmem_finalize(); + return 0; } diff --git a/example_code/shmem_team_split_strided.c b/example_code/shmem_team_split_strided.c index 25525cae6..2fc8f972f 100644 --- a/example_code/shmem_team_split_strided.c +++ b/example_code/shmem_team_split_strided.c @@ -1,12 +1,7 @@ -/* - * OpenSHMEM shmem_team_split_strided example to create a team of all even - * ranked PEs from SHMEM_TEAM_WORLD - */ - #include #include -int main(int argc, char *argv[]) { +int main(void) { shmem_team_t new_team; shmem_team_config_t *config; diff --git a/example_code/shmem_team_translate_pe.c b/example_code/shmem_team_translate_pe.c index 56dc9da19..a3e62887c 100644 --- a/example_code/shmem_team_translate_pe.c +++ b/example_code/shmem_team_translate_pe.c @@ -2,14 +2,12 @@ #include int main(void) { - shmem_team_t new_team; - shmem_team_config_t *config; - shmem_init(); - config = NULL; + shmem_team_config_t *config = NULL; int mype = shmem_my_pe(); int npes = shmem_n_pes(); + shmem_team_t new_team; shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, (npes + 1) / 2, config, 0, &new_team); diff --git a/utils/defs.tex b/utils/defs.tex index 819ba8338..f8e654ebc 100644 --- a/utils/defs.tex +++ b/utils/defs.tex @@ -206,6 +206,8 @@ \lstdefinestyle{SourceListingsDefault}{ language={C}, + breaklines=true, + breakatwhitespace=true, escapechar=@, tabsize=2, basicstyle=\ttfamily\footnotesize, From c20927a2af047662e21adf92a869f33d63e9022e Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Wed, 5 Feb 2020 12:13:29 -0600 Subject: [PATCH 19/23] Set clang-format column width, reformat examples --- .clang-format | 1 + example_code/pshmem_example.c | 11 +++++------ example_code/shmem_alltoall_example.c | 4 ++-- example_code/shmem_alltoalls_example.c | 7 +++---- example_code/shmem_ctx_invalid.c | 3 +-- example_code/shmem_ctx_pipelined_reduce.c | 11 +++++------ example_code/shmem_iput_example.c | 4 ++-- example_code/shmem_quiet_example.c | 3 +-- example_code/shmem_sync_example.c | 3 +-- example_code/shmem_team_context.c | 6 ++---- example_code/shmem_team_split_2D.c | 3 +-- example_code/shmem_team_split_strided.c | 3 +-- example_code/shmem_team_translate_pe.c | 6 ++---- example_code/shmem_test_some_example.c | 3 +-- example_code/shmem_wait_until_any_all2all_sum.c | 3 +-- example_code/shmem_wait_until_any_vector.c | 4 ++-- example_code/shmem_wait_until_some_all2all_sum.c | 4 ++-- 17 files changed, 33 insertions(+), 46 deletions(-) diff --git a/.clang-format b/.clang-format index 46384c277..017ce47f5 100644 --- a/.clang-format +++ b/.clang-format @@ -2,3 +2,4 @@ BasedOnStyle: LLVM BreakBeforeBraces: Custom BraceWrapping: BeforeElse: true +ColumnLimit: 90 diff --git a/example_code/pshmem_example.c b/example_code/pshmem_example.c index 37c7678f8..89b707720 100644 --- a/example_code/pshmem_example.c +++ b/example_code/pshmem_example.c @@ -16,12 +16,11 @@ static inline double get_wtime(void) { } void shmem_long_put(long *dest, const long *source, size_t nelems, int pe) { - double t_start = get_wtime(); /* Start timer */ - pshmem_long_put(dest, source, nelems, pe); /* Name shifted call to put */ - total_put_time += get_wtime() - t_start; /* Calculate total time elapsed */ - put_count += 1; /* Increment put counts */ - avg_put_time = - total_put_time / (double)put_count; /* Calculate average put latency */ + double t_start = get_wtime(); /* Start timer */ + pshmem_long_put(dest, source, nelems, pe); /* Name shifted call to put */ + total_put_time += get_wtime() - t_start; /* Calculate total time elapsed */ + put_count += 1; /* Increment put counts */ + avg_put_time = total_put_time / (double)put_count; /* Calculate average put latency */ return; } diff --git a/example_code/shmem_alltoall_example.c b/example_code/shmem_alltoall_example.c index 5ec199002..5c5ece60a 100644 --- a/example_code/shmem_alltoall_example.c +++ b/example_code/shmem_alltoall_example.c @@ -28,8 +28,8 @@ int main(void) { for (int pe = 0; pe < npes; pe++) { for (int i = 0; i < count; i++) { if (dest[(pe * count) + i] != pe + mype) { - printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", mype, - (pe * count) + i, dest[(pe * count) + i], pe + mype); + printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", mype, (pe * count) + i, + dest[(pe * count) + i], pe + mype); } } } diff --git a/example_code/shmem_alltoalls_example.c b/example_code/shmem_alltoalls_example.c index 24aad9a68..f8adeab16 100644 --- a/example_code/shmem_alltoalls_example.c +++ b/example_code/shmem_alltoalls_example.c @@ -11,8 +11,7 @@ int main(void) { const ptrdiff_t dst = 2; const ptrdiff_t sst = 3; int64_t *dest = (int64_t *)shmem_malloc(count * dst * npes * sizeof(int64_t)); - int64_t *source = - (int64_t *)shmem_malloc(count * sst * npes * sizeof(int64_t)); + int64_t *source = (int64_t *)shmem_malloc(count * sst * npes * sizeof(int64_t)); /* assign source values */ for (int pe = 0; pe < npes; pe++) { @@ -32,8 +31,8 @@ int main(void) { for (int i = 0; i < count; i++) { int j = dst * ((pe * count) + i); if (dest[j] != pe + mype) { - printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", mype, j, - dest[j], pe + mype); + printf("[%d] ERROR: dest[%d]=%" PRId64 ", should be %d\n", mype, j, dest[j], + pe + mype); } } } diff --git a/example_code/shmem_ctx_invalid.c b/example_code/shmem_ctx_invalid.c index 5e5335140..936c28ee2 100644 --- a/example_code/shmem_ctx_invalid.c +++ b/example_code/shmem_ctx_invalid.c @@ -56,8 +56,7 @@ int main() { #pragma omp for for (int i = 0; i < npes; i++) - lib_thread_putmem(dst_bufs[mype], src_bufs[i], - count * sizeof(*src_bufs[i]), i); + lib_thread_putmem(dst_bufs[mype], src_bufs[i], count * sizeof(*src_bufs[i]), i); lib_thread_unregister(); } diff --git a/example_code/shmem_ctx_pipelined_reduce.c b/example_code/shmem_ctx_pipelined_reduce.c index dbf555a2d..c235af059 100644 --- a/example_code/shmem_ctx_pipelined_reduce.c +++ b/example_code/shmem_ctx_pipelined_reduce.c @@ -28,19 +28,18 @@ int main(void) { out_buf[i] = 0; } - int p_idx = 0, - p = 0; /* Index of ctx and pbuf (p_idx) for current pipeline stage (p) */ + int p_idx = 0, p = 0; /* Index of ctx and pbuf (p_idx) for current pipeline stage (p) */ for (i = 1; i <= npes; i++) - shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * mype], &in_buf[PLEN * p], - PLEN, (mype + i) % npes); + shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * mype], &in_buf[PLEN * p], PLEN, + (mype + i) % npes); /* Issue communication for pipeline stage p, then accumulate results for stage * p-1 */ for (p = 1; p < LEN / PLEN; p++) { p_idx ^= 1; for (i = 1; i <= npes; i++) - shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * mype], &in_buf[PLEN * p], - PLEN, (mype + i) % npes); + shmem_put_nbi(ctx[p_idx], &pbuf[p_idx][PLEN * mype], &in_buf[PLEN * p], PLEN, + (mype + i) % npes); shmem_ctx_quiet(ctx[p_idx ^ 1]); shmem_sync_all(); diff --git a/example_code/shmem_iput_example.c b/example_code/shmem_iput_example.c index e73db1867..09f8c69c9 100644 --- a/example_code/shmem_iput_example.c +++ b/example_code/shmem_iput_example.c @@ -10,8 +10,8 @@ int main(void) { shmem_iput(dest, source, 1, 2, 5, 1); shmem_barrier_all(); /* sync sender and receiver */ if (mype == 1) { - printf("dest on PE %d is %hd %hd %hd %hd %hd\n", mype, dest[0], dest[1], - dest[2], dest[3], dest[4]); + printf("dest on PE %d is %hd %hd %hd %hd %hd\n", mype, dest[0], dest[1], dest[2], + dest[3], dest[4]); } shmem_finalize(); return 0; diff --git a/example_code/shmem_quiet_example.c b/example_code/shmem_quiet_example.c index ba75e87e7..719be8eec 100644 --- a/example_code/shmem_quiet_example.c +++ b/example_code/shmem_quiet_example.c @@ -14,8 +14,7 @@ int main(void) { shmem_put(dest, source, 3, 1); /* put1 */ shmem_put(&targ, &src, 1, 2); /* put2 */ shmem_quiet(); - shmem_get(x, dest, 3, - 1); /* gets updated value from dest on PE 1 to local array x */ + shmem_get(x, dest, 3, 1); /* gets updated value from dest on PE 1 to local array x */ shmem_get(&y, &targ, 1, 2); /* gets updated value from targ on PE 2 to local variable y */ printf("x: { %ld, %ld, %ld }\n", x[0], x[1], x[2]); /* x: { 1, 2, 3 } */ diff --git a/example_code/shmem_sync_example.c b/example_code/shmem_sync_example.c index 891d49087..a04f635ed 100644 --- a/example_code/shmem_sync_example.c +++ b/example_code/shmem_sync_example.c @@ -39,8 +39,7 @@ int main(void) { if (threes_team != SHMEM_TEAM_INVALID) { /* put the value 3 to the next team member in a circular fashion */ shmem_p(&x, 3, - shmem_team_translate_pe(threes_team, - (mype_threes + 1) % npes_threes, + shmem_team_translate_pe(threes_team, (mype_threes + 1) % npes_threes, SHMEM_TEAM_WORLD)); shmem_quiet(); shmem_sync(threes_team); diff --git a/example_code/shmem_team_context.c b/example_code/shmem_team_context.c index 601927ed8..0e3559946 100644 --- a/example_code/shmem_team_context.c +++ b/example_code/shmem_team_context.c @@ -58,11 +58,9 @@ int main() { long cmask = SHMEM_TEAM_NUM_CONTEXTS; // Create team with PEs numbered 0, 2, 4, ... - shmem_team_spit_strided(SHMEM_TEAM_WORLD, 0, 2, npes / 2, &conf, cmask, - &team_2s); + shmem_team_spit_strided(SHMEM_TEAM_WORLD, 0, 2, npes / 2, &conf, cmask, &team_2s); // Create team with PEs numbered 0, 3, 6, ... - shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 3, npes / 3, &conf, cmask, - &team_3s); + shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 3, npes / 3, &conf, cmask, &team_3s); ctx_2s = my_team_create_ctx(team_2s); ctx_3s = my_team_create_ctx(team_3s); diff --git a/example_code/shmem_team_split_2D.c b/example_code/shmem_team_split_2D.c index 4a7026fdc..08a77c15d 100644 --- a/example_code/shmem_team_split_2D.c +++ b/example_code/shmem_team_split_2D.c @@ -17,8 +17,7 @@ int main(void) { int zdim = (npes / (xdim * ydim)) + (((npes % (xdim * ydim)) > 0) ? 1 : 0); shmem_team_t xteam, yzteam, yteam, zteam; - shmem_team_split_2d(SHMEM_TEAM_WORLD, xdim, NULL, 0, &xteam, NULL, 0, - &yzteam); + shmem_team_split_2d(SHMEM_TEAM_WORLD, xdim, NULL, 0, &xteam, NULL, 0, &yzteam); // yzteam is immediately ready to be used in collectives shmem_team_split_2d(yzteam, ydim, NULL, 0, &yteam, NULL, 0, &zteam); diff --git a/example_code/shmem_team_split_strided.c b/example_code/shmem_team_split_strided.c index 2fc8f972f..d141cb4ef 100644 --- a/example_code/shmem_team_split_strided.c +++ b/example_code/shmem_team_split_strided.c @@ -10,8 +10,7 @@ int main(void) { int mype = shmem_my_pe(); int npes = shmem_n_pes(); - shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, npes / 2, config, 0, - &new_team); + shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, npes / 2, config, 0, &new_team); if (new_team != SHMEM_TEAM_INVALID) { int team_npes = shmem_team_n_pes(new_team); diff --git a/example_code/shmem_team_translate_pe.c b/example_code/shmem_team_translate_pe.c index a3e62887c..4d30a75eb 100644 --- a/example_code/shmem_team_translate_pe.c +++ b/example_code/shmem_team_translate_pe.c @@ -8,13 +8,11 @@ int main(void) { int npes = shmem_n_pes(); shmem_team_t new_team; - shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, (npes + 1) / 2, config, 0, - &new_team); + shmem_team_split_strided(SHMEM_TEAM_WORLD, 0, 2, (npes + 1) / 2, config, 0, &new_team); if (new_team != SHMEM_TEAM_INVALID) { int team_mype = shmem_team_my_pe(new_team); - int global_mype = - shmem_team_translate_pe(new_team, team_mype, SHMEM_TEAM_WORLD); + int global_mype = shmem_team_translate_pe(new_team, team_mype, SHMEM_TEAM_WORLD); if (global_mype != mype) { shmem_global_exit(1); diff --git a/example_code/shmem_test_some_example.c b/example_code/shmem_test_some_example.c index 260ae945a..7c69c06f3 100644 --- a/example_code/shmem_test_some_example.c +++ b/example_code/shmem_test_some_example.c @@ -31,8 +31,7 @@ int main(void) { int ncompleted = 0; while (ncompleted < npes) { - int ntested = - shmem_test_some(flags, npes, indices, status, SHMEM_CMP_NE, 0); + int ntested = shmem_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++) { diff --git a/example_code/shmem_wait_until_any_all2all_sum.c b/example_code/shmem_wait_until_any_all2all_sum.c index dd7a840ce..ddaee5f5b 100644 --- a/example_code/shmem_wait_until_any_all2all_sum.c +++ b/example_code/shmem_wait_until_any_all2all_sum.c @@ -28,8 +28,7 @@ int main(void) { shmem_atomic_set(&flags[mype], 1, i); for (int i = 0; i < npes; i++) { - size_t completed_idx = - shmem_wait_until_any(flags, npes, status, SHMEM_CMP_NE, 0); + size_t completed_idx = shmem_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]; } diff --git a/example_code/shmem_wait_until_any_vector.c b/example_code/shmem_wait_until_any_vector.c index e01ee5d36..23c77d259 100644 --- a/example_code/shmem_wait_until_any_vector.c +++ b/example_code/shmem_wait_until_any_vector.c @@ -23,8 +23,8 @@ int main(void) { } for (int i = 0; i < npes; i++) { - size_t completed_idx = shmem_wait_until_any_vector( - ivars, npes, status, SHMEM_CMP_EQ, cmp_values); + size_t completed_idx = + shmem_wait_until_any_vector(ivars, npes, status, SHMEM_CMP_EQ, cmp_values); status[completed_idx] = 1; total_sum += ivars[completed_idx]; } diff --git a/example_code/shmem_wait_until_some_all2all_sum.c b/example_code/shmem_wait_until_some_all2all_sum.c index f7d93ece0..732cedd60 100644 --- a/example_code/shmem_wait_until_some_all2all_sum.c +++ b/example_code/shmem_wait_until_some_all2all_sum.c @@ -29,8 +29,8 @@ int main(void) { shmem_atomic_set(&flags[mype], 1, i); size_t ncompleted; - while ((ncompleted = shmem_wait_until_some(flags, npes, indices, status, - SHMEM_CMP_NE, 0))) { + while ((ncompleted = + shmem_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]; From 83fece77c3c734afda90149c7a7fe288f4b020a8 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Wed, 5 Feb 2020 12:36:35 -0600 Subject: [PATCH 20/23] Update clang-format column width, reformat example --- .clang-format | 2 +- example_code/shmem_lock_example.c | 3 +-- example_code/shmem_sync_example.c | 9 ++++----- example_code/shmem_wait_until_some_all2all_sum.c | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.clang-format b/.clang-format index 017ce47f5..b08325b41 100644 --- a/.clang-format +++ b/.clang-format @@ -2,4 +2,4 @@ BasedOnStyle: LLVM BreakBeforeBraces: Custom BraceWrapping: BeforeElse: true -ColumnLimit: 90 +ColumnLimit: 92 diff --git a/example_code/shmem_lock_example.c b/example_code/shmem_lock_example.c index 88d8ca6bb..57624144d 100644 --- a/example_code/shmem_lock_example.c +++ b/example_code/shmem_lock_example.c @@ -11,8 +11,7 @@ int main(void) { printf("%d: count is %d\n", mype, val); val++; /* incrementing and updating count on PE 0 */ shmem_p(&count, val, 0); - shmem_clear_lock( - &lock); /* ensures count update has completed before clearing the lock */ + shmem_clear_lock(&lock); /* ensures count update has completed before clearing the lock */ shmem_finalize(); return 0; } diff --git a/example_code/shmem_sync_example.c b/example_code/shmem_sync_example.c index a04f635ed..f551537a4 100644 --- a/example_code/shmem_sync_example.c +++ b/example_code/shmem_sync_example.c @@ -13,8 +13,7 @@ int main(void) { int npes = shmem_n_pes(); if (npes > 2) - shmem_team_split_strided(SHMEM_TEAM_WORLD, 2, 2, (npes - 1) / 2, config, 0, - &twos_team); + shmem_team_split_strided(SHMEM_TEAM_WORLD, 2, 2, (npes - 1) / 2, config, 0, &twos_team); if (npes > 3) shmem_team_split_strided(SHMEM_TEAM_WORLD, 3, 3, (npes - 1) / 3, config, 0, @@ -27,9 +26,9 @@ int main(void) { if (twos_team != SHMEM_TEAM_INVALID) { /* put the value 2 to the next team member in a circular fashion */ - shmem_p(&x, 2, - shmem_team_translate_pe(twos_team, (mype_twos + 1) % npes_twos, - SHMEM_TEAM_WORLD)); + shmem_p( + &x, 2, + shmem_team_translate_pe(twos_team, (mype_twos + 1) % npes_twos, SHMEM_TEAM_WORLD)); shmem_quiet(); shmem_sync(twos_team); } diff --git a/example_code/shmem_wait_until_some_all2all_sum.c b/example_code/shmem_wait_until_some_all2all_sum.c index 732cedd60..e80e8984b 100644 --- a/example_code/shmem_wait_until_some_all2all_sum.c +++ b/example_code/shmem_wait_until_some_all2all_sum.c @@ -29,8 +29,8 @@ int main(void) { shmem_atomic_set(&flags[mype], 1, i); size_t ncompleted; - while ((ncompleted = - shmem_wait_until_some(flags, npes, indices, status, SHMEM_CMP_NE, 0))) { + while ( + (ncompleted = shmem_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]; From 2bbf80b965fbe783c980fa7209c2cd0037dddc33 Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Wed, 5 Feb 2020 12:57:23 -0600 Subject: [PATCH 21/23] Minor formatting fixup --- .clang-format | 2 +- content/backmatter.tex | 2 +- example_code/shmem_ctx_invalid.c | 3 +-- example_code/shmem_quiet_example.c | 5 ++--- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.clang-format b/.clang-format index b08325b41..263726cd3 100644 --- a/.clang-format +++ b/.clang-format @@ -2,4 +2,4 @@ BasedOnStyle: LLVM BreakBeforeBraces: Custom BraceWrapping: BeforeElse: true -ColumnLimit: 92 +ColumnLimit: 93 diff --git a/content/backmatter.tex b/content/backmatter.tex index 961773232..85c254735 100644 --- a/content/backmatter.tex +++ b/content/backmatter.tex @@ -44,7 +44,7 @@ \section*{Incorporating OpenSHMEM into Programs}\label{sec:writing_programs} \clearpage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -The example in Example~\ref{openshmem-hello-symmetric} shows a more complex +Example~\ref{openshmem-hello-symmetric} shows a more complex \openshmem program that illustrates the use of symmetric data objects. Note the declaration of the \VAR{static short dest} array and its use as the remote destination in \hyperref[subsec:shmem_put]{\FUNC{shmem\_put}}. diff --git a/example_code/shmem_ctx_invalid.c b/example_code/shmem_ctx_invalid.c index 936c28ee2..9e6226135 100644 --- a/example_code/shmem_ctx_invalid.c +++ b/example_code/shmem_ctx_invalid.c @@ -6,8 +6,7 @@ _Thread_local shmem_ctx_t thread_ctx = SHMEM_CTX_INVALID; void lib_thread_register(void) { if (thread_ctx == SHMEM_CTX_INVALID) - if (shmem_ctx_create(SHMEM_CTX_PRIVATE, &thread_ctx) && - shmem_ctx_create(0, &thread_ctx)) + if (shmem_ctx_create(SHMEM_CTX_PRIVATE, &thread_ctx) && shmem_ctx_create(0, &thread_ctx)) thread_ctx = SHMEM_CTX_DEFAULT; } diff --git a/example_code/shmem_quiet_example.c b/example_code/shmem_quiet_example.c index 719be8eec..c414193fe 100644 --- a/example_code/shmem_quiet_example.c +++ b/example_code/shmem_quiet_example.c @@ -14,9 +14,8 @@ int main(void) { shmem_put(dest, source, 3, 1); /* put1 */ shmem_put(&targ, &src, 1, 2); /* put2 */ shmem_quiet(); - shmem_get(x, dest, 3, 1); /* gets updated value from dest on PE 1 to local array x */ - shmem_get(&y, &targ, 1, - 2); /* gets updated value from targ on PE 2 to local variable y */ + shmem_get(x, dest, 3, 1); /* get updated array from dest on PE 1 to local array x */ + shmem_get(&y, &targ, 1, 2); /* get updated value from targ on PE 2 to local variable y */ printf("x: { %ld, %ld, %ld }\n", x[0], x[1], x[2]); /* x: { 1, 2, 3 } */ printf("y: %d\n", y); /* y: 90 */ shmem_put(&targ, &src, 1, 1); /* put3 */ From 50d376e041751a14696aafeb0004cd507c33920e Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Thu, 6 Feb 2020 09:16:14 -0600 Subject: [PATCH 22/23] Final example formatting tweaks --- example_code/writing_shmem_example.c | 12 ++++++------ utils/defs.tex | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/example_code/writing_shmem_example.c b/example_code/writing_shmem_example.c index e25be6fae..96537f3cd 100644 --- a/example_code/writing_shmem_example.c +++ b/example_code/writing_shmem_example.c @@ -1,30 +1,30 @@ #include #include -#define SIZE 16 +#define N 16 int main(void) { - short source[SIZE]; - static short dest[SIZE]; + short source[N]; + static short dest[N]; static long lock = 0; shmem_init(); int mype = shmem_my_pe(); int npes = shmem_n_pes(); if (mype == 0) { /* initialize array */ - for (int i = 0; i < SIZE; i++) + for (int i = 0; i < N; i++) source[i] = i; /* local, not symmetric */ /* static makes it symmetric */ /* put "size" words into dest on each PE */ for (int i = 1; i < npes; i++) - shmem_put(dest, source, SIZE, i); + shmem_put(dest, source, N, i); } shmem_barrier_all(); /* sync sender and receiver */ if (mype != 0) { shmem_set_lock(&lock); printf("dest on PE %d is \t", mype); - for (int i = 0; i < SIZE; i++) + for (int i = 0; i < N; i++) printf("%hd \t", dest[i]); printf("\n"); shmem_clear_lock(&lock); diff --git a/utils/defs.tex b/utils/defs.tex index f8e654ebc..f3ec3f10a 100644 --- a/utils/defs.tex +++ b/utils/defs.tex @@ -219,8 +219,10 @@ % Language keywords classoffset=1, keywords={ - if, else, for, while, return, break, static, const, volatile, + if, else, for, while, do, return, break, continue, + static, const, volatile, sizeof, typedef, struct, union, + switch, case, default, goto, }, keywordstyle=\bfseries\color{Orchid}, % Types From 9c9dbb0093943ec022dd2c0e5db376d25c63ed2e Mon Sep 17 00:00:00 2001 From: "Nicholas S. Park" Date: Thu, 6 Feb 2020 12:47:16 -0600 Subject: [PATCH 23/23] Final-final formatting tweak --- utils/defs.tex | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/defs.tex b/utils/defs.tex index f3ec3f10a..5246c0e93 100644 --- a/utils/defs.tex +++ b/utils/defs.tex @@ -234,6 +234,7 @@ int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, shmem_ctx_t, shmem_team_t, shmem_team_config_t, + FILE, }, keywordstyle=\color{OliveGreen}, % Other elements