Go to the first, previous, next, last section, table of contents.


SHMEM example code

#include <shmem.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Declare storage to be shared across nodes globally so that virtual */
/* addresses are identical on each node.                              */
long srcBuf[] = {
  0xb1ffd1da,
  0xb00b00b1,
  0xfffedf1d,
  0x0badbeef,
  0xf1d0d1ed
};
long targetBuf[sizeof(srcBuf) / sizeof(long)];

int main(int argc, char *argv[])
{
  int thisPeId;
  int numNodes;

  /* Pass argc and argv by reference to allow shmem_initialize() to */
  /* remove the -np and -key arguments from argv.                   */
  shmem_initialize(&argc, &argv);
  thisPeId = my_pe();
  numNodes = num_pes();
  printf("PE number %d\n", thisPeId);
  barrier();                    /* Let everyone get synchronized. */
  if (!thisPeId) {
    shmem_put (targetBuf, srcBuf,  sizeof(srcBuf) / sizeof(long), 1);
    shmem_get (targetBuf, targetBuf, sizeof(srcBuf) / sizeof(long), 1);
    if (!memcmp(srcBuf, targetBuf, sizeof(srcBuf)))
      printf("shmem_put() and shmem_get() to node 1 succeeded.\n");
    else
      printf("shmem_put() and shmem_get() to node 1 failed.\n");
  }

  /* barrier() prevents node 1 from exiting before it serves the  */
  /* put and get for node 0.                                      */
  barrier();
  shmem_finalize();
  return (0);
}


Go to the first, previous, next, last section, table of contents.