blob: ac503381eae7ab457d11556c144174bb33f6cfeb [file] [log] [blame]
<h2>The <code>upc_all_exchange</code> function </h2>
<h4>Synopsis</h4>
<pre>
#include &lt;upc.h&gt;
#include &lt;upc_collective.h&gt;
void upc_all_exchange(shared void * restrict dst,
shared const void * restrict src,
size_t nbytes, upc_flag_t flags);
</pre>
<p>
<h4>Description</h4>
<p>
The <code>upc_all_exchange </code> 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
<code>nbytes</code>.
<p><code>nbytes</code> must be strictly greater than 0.
<p>
<p>The <code>upc_all_exchange </code> function treats the <code>src</code> pointer and the <code>dst</code> pointer
as if each pointed to a shared memory area of <code>nbytes * THREADS</code> bytes on each
thread and therefore had type:
<pre>
shared [nbytes * THREADS] char[nbytes * THREADS * THREADS]
</pre>
<p>The targets of the <code>src</code> and <code>dst</code> pointers must have affinity to thread 0.
<p>The <code>src</code> and <code>dst</code> pointers are treated as if they have phase 0.
<p>For each pair of threads i and j, the effect is equivalent to copying the ith
block of <code>nbytes</code> bytes that has affinity to thread j pointed to by <code>src</code> to the
jth block of <code>nbytes</code> bytes that has affinity to thread i pointed to by <code>dst</code>.
<ul>
<li>EXAMPLE 1 <code>upc_all_exchange </code> for the static THREADS translation environment.
<pre>
#include &lt;upc.h&gt;
#include &lt;upc_collective.h&gt;
#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;
</pre>
<li>EXAMPLE 2 <code>upc_all_exchange </code> for the dynamic THREADS translation environment.
<pre>
#include &lt;upc.h&gt;
#include &lt;upc_collective.h&gt;
#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&lt;NELEMS*THREADS; i++)
myA[i] = MYTHREAD*10 + i;
upc_all_exchange( Bdata, Adata, NELEMS*sizeof(int),
UPC_IN_ALLSYNC | UPC_OUT_ALLSYNC );
</pre>
</ul>
<p>&nbsp
<p>&nbsp
<p><a href="terms.html">Terms, definitions, and symbols</a><br>
<p><a href="index.html">Back to index of all UPC functions</a>