| <h2>The <code>upc_all_scatter</code> function</h2> |
| |
| <h4>Synopsis</h4> |
| <pre> |
| #include <upc.h> |
| #include <upc_collective.h> |
| void upc_all_scatter(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_scatter </code> function |
| copies the ith block of an area of shared |
| memory with affinity to a single thread to a block of shared memory with |
| affinity to the ith thread. The number of bytes in each block is <code>nbytes</code>. |
| <p><code>nbytes</code> must be strictly greater than 0. |
| <p>The <code>upc_all_scatter </code> function treats the <code>src</code> pointer as if it pointed to a |
| shared memory area with the type: |
| <pre> |
| shared [] char[nbytes * THREADS] |
| </pre> |
| <p>and it treats the <code>dst</code> pointer as if it pointed to a shared memory area with |
| the type: |
| <pre> |
| shared [nbytes] char[nbytes * THREADS] |
| </pre> |
| <p>The target of the <code>dst</code> pointer must have affinity to thread 0. |
| <p>The <code>dst</code> pointer is treated as if it has phase 0. |
| <p>For each thread i, the effect is equivalent to copying the ith block of <code>nbytes</code> |
| bytes pointed to by <code>src</code> to the block of <code>nbytes</code> bytes pointed to by |
| <code>dst</code> that |
| has affinity to thread i. |
| <ul> |
| <li>EXAMPLE 1: <code>upc_all_scatter</code> for the dynamic THREADS translation environment. |
| <pre> |
| #include <upc.h> |
| #include <upc_collective.h> |
| #define NUMELEMS 10 |
| #define SRC_THREAD 1 |
| shared int *A; |
| shared [] int *myA, *srcA; |
| shared [NUMELEMS] int B[NUMELEMS*THREADS]; |
| // allocate and initialize an array distributed across all threads |
| A = upc_all_alloc(THREADS, THREADS*NUMELEMS*sizeof(int)); |
| myA = (shared [] int *) &A[MYTHREAD]; |
| for (i=0; i<NUMELEMS*THREADS; i++) |
| myA[i] = i + NUMELEMS*THREADS*MYTHREAD; // (for example) |
| // scatter the SRC_THREADÕs row of the array |
| srcA = (shared [] int *) &A[SRC_THREAD]; |
| upc_barrier; |
| upc_all_scatter( B, srcA, sizeof(int)*NUMELEMS, |
| UPC_IN_NOSYNC | UPC_OUT_NOSYNC); |
| upc_barrier; |
| </pre> |
| <li>EXAMPLE 2: <code>upc_all_scatter</code> for the static THREADS translation environment. |
| <pre> |
| #include <upc.h> |
| #include <upc_collective.h> |
| #define NELEMS 10 |
| shared [] int A[NELEMS*THREADS]; |
| shared [NELEMS] int B[NELEMS*THREADS]; |
| |
| // Initialize A. |
| upc_all_scatter( B, A, sizeof(int)*NELEMS, |
| UPC_IN_ALLSYNC | UPC_OUT_ALLSYNC ); |
| </pre> |
| |
| </ul> |
| <p>  |
| <p>  |
| <p><a href="terms.html">Terms, definitions, and symbols</a><br> |
| <p><a href="index.html">Back to index of all UPC functions</a> |