upc_all_exchange
function #include <upc.h> #include <upc_collective.h> void upc_all_exchange(shared void * restrict dst, shared const void * restrict src, size_t nbytes, upc_flag_t flags);
The upc_all_exchange
function copies the ith block of memory from a shared
memory area that has affinity to thread j to the jth block of a shared memory
area that has affinity to thread i. The number of bytes in each block is
nbytes
.
nbytes
must be strictly greater than 0.
The upc_all_exchange
function treats the src
pointer and the dst
pointer
as if each pointed to a shared memory area of nbytes * THREADS
bytes on each
thread and therefore had type:
shared [nbytes * THREADS] char[nbytes * THREADS * THREADS]
The targets of the src
and dst
pointers must have affinity to thread 0.
The src
and dst
pointers are treated as if they have phase 0.
For each pair of threads i and j, the effect is equivalent to copying the ith
block of nbytes
bytes that has affinity to thread j pointed to by src
to the
jth block of nbytes
bytes that has affinity to thread i pointed to by dst
.
upc_all_exchange
for the static THREADS translation environment.
#include <upc.h> #include <upc_collective.h> #define NELEMS 10 shared [NELEMS*THREADS] int A[THREADS][NELEMS*THREADS]; shared [NELEMS*THREADS] int B[THREADS][NELEMS*THREADS]; // Initialize A. upc_barrier; upc_all_exchange( B, A, NELEMS*sizeof(int), UPC_IN_NOSYNC | UPC_OUT_NOSYNC ); upc_barrier;
upc_all_exchange
for the dynamic THREADS translation environment.
#include <upc.h> #include <upc_collective.h> #define NELEMS 10 shared int *Adata, *Bdata; shared [] int *myA, *myB; int i; Adata = upc_all_alloc(THREADS*THREADS, NELEMS*sizeof(int)); myA = (shared [] int *)&Adata[MYTHREAD]; Bdata = upc_all_alloc(THREADS*THREADS, NELEMS*sizeof(int)); myB = (shared [] int *)&Bdata[MYTHREAD]; // Adata and Bdata contain THREADS*THREADS*NELEMS elements. // myA and myB are MYTHREAD's rows of Adata and Bdata, resp. // Initialize MYTHREAD's row of A. For example, for (i=0; i<NELEMS*THREADS; i++) myA[i] = MYTHREAD*10 + i; upc_all_exchange( Bdata, Adata, NELEMS*sizeof(int), UPC_IN_ALLSYNC | UPC_OUT_ALLSYNC );