| <html>
|
| <head>
|
| <title>shmemalign</title>
|
| </head>
|
| <h2 id="top">shmemalign</h2>
|
| <h4>Purpose</h4>
|
|
|
|
|
| <p>Allocates a symmetric, remotely accessible object from the Symmetric heap with specified byte alignment.
|
| </p>
|
|
|
| <h4>C syntax</h4>
|
|
|
| <pre>
|
| #include <shmem.h>
|
|
|
| void *shmemalign(size_t alignment, size_t size);
|
|
|
| </pre>
|
|
|
| <h4>Parameters</h4>
|
|
|
|
|
| <dl>
|
| <dt class="bold">INPUT</dt>
|
| <dd>
|
| </dd>
|
| <dt class="bold ">alignment</dt>
|
| <dd>The desired byte alignment of the symmetric object.
|
| </dd>
|
| <dt class="bold ">size</dt>
|
| <dd>The minimum desired size of the symmetric object.
|
| </dd>
|
| </dl>
|
|
|
| <h4>Description</h4>
|
|
|
| <div class="ledi">
|
| <p>The shmemalign function returns a pointer to a remotely accessible memory block of minimum size bytes with specified byte alignment from the symmetric heap. The allocated object can be used by IBM openshmem communication functions. It returns NULL if the symmetric heap has run out of space.</p>
|
| <p>It is required that all PEs must participate in the memory allocation and with the identical parameter. Internally, shmem_barrier_all is called before returning from the function, thus the allocated object can be used right away on all PEs. User has to ensure the same size parameter is used on all PEs when calling the function; otherwise, subsequent calls to the symmetric object allocation functions may not return the same address.</p>
|
|
|
| <h4>C examples</h4>
|
| <pre>
|
| #include <stdio.h>
|
| #include <string.h>
|
| #include <strings.h>
|
|
|
| #include <shmem.h>
|
|
|
| int main (int argc, char* argv[])
|
| {
|
| int total_tasks = -1;
|
| int my_task = -1;
|
|
|
| start_pes(0);
|
|
|
| total_tasks = _num_pes();
|
|
|
| if (total_tasks <= 0) {
|
| printf("FAILED\n");
|
| return 0;
|
| } else {
|
| printf("number of pes is %d\n", total_tasks);
|
| }
|
|
|
| my_task = _my_pe();
|
|
|
| if (my_task < 0){
|
| printf("FAILED\n");
|
| return 0;
|
| } else {
|
| printf("my pe id is %d\n", my_task);
|
| }
|
|
|
| int *addrs[10];
|
| for (int i=0; i<10; i++) {
|
| addrs[i] = (int *) shmalloc(sizeof(int)*1024);
|
| printf("addrs[%d] is %p after malloc\n", i, addrs[i]);
|
| bzero(addrs[i], sizeof(int)*1024);
|
| for (int j=0; j<1024; j++) {
|
| addrs[i][j] = j;
|
| }
|
| }
|
|
|
| for (int i=0; i<10; i++) {
|
| shfree(addrs[i]);
|
| }
|
|
|
| int *addr = NULL;
|
| addr = (int *) shmalloc(sizeof(int)*1024);
|
| printf("addr is %p after malloc\n", addr);
|
|
|
| addr = (int *) shrealloc(addr, sizeof(int)*1024);
|
| printf("addr is %p after realloc\n", addr);
|
|
|
| shfree(addr);
|
|
|
| for (int i=0; i<10; i++) {
|
| addrs[i] = (int *) shmemalign(0x2000, sizeof(int)*1024);
|
| printf("addrs[%d] is %p after memalign\n", i, addrs[i]);
|
| }
|
|
|
| for (int i=0; i<10; i++) {
|
| shfree(addrs[i]);
|
| }
|
|
|
| printf("PASSED\n");
|
| return 0;
|
| }
|
| </pre>
|
|
|
| <h4>Related information</h4>
|
|
|
| <p>Subroutines: shfree, shmalloc, shrealloc
|
|
|
| </p>
|
| <hr><a href="apiIndex.html">OpenSHMEM API Index</a> |
| </html> |