User`s guide

Cray XMT Programming Environment Users Guide
Use the following functions to call rememd from a program.
persist_remember
Causes the rememd daemon to call mmap to map the shared memory
into its virtual address space and write a record of it to disk. If
rememd has already mapped this segment, its reference count is
incremented instead. This function returns 0 on success, and
errno
on failure.
persist_mmap_size
Causes the rememd daemon to return the size of the shared memory
mapped into its virtual address space. This function returns the size,
in bytes, of the memory region on success, and 0 if the region is not
found. When an error occurs, errno is set and -1 is returned.
persist_forget
Causes the rememd daemon to decrement the specified segment's
reference count. If the reference count is zero, the rememd daemon
calls munmap to unmap the shared memory from its virtual address
space and remove the record of it from disk. This function returns 0
on success, and the errno on failure.
The following example shows how to persist memory in your program.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/file.h>
#include <remem/persistmem.h>
const char *remember_path = "/tmp/my_data_handle";
void run_computation(caddr_t addr, size_t len, int ret);
int main(int argc, char **argv) {
caddr_t mmap_addr = 0;
size_t mmap_len = 4096;
int fd = -1;
// find out if memory is mapped
ssize_t ret = persist_mmap_size(remember_path);
if (-1 == ret) { // -1 indicates there was an error
printf("Unexpected error from libremem: %s\n", strerror(errno));
exit(1);
} else if (0 == ret) { // 0 indicates the memory has not been mapped yet
fd = open(remember_path, O_CREAT | O_RDWR, 0600);
if (-1 == fd) {
printf("Unexpected error opening remember_path: %s\n", strerror(errno));
exit(1);
50 S247920