Skip to content

Instantly share code, notes, and snippets.

@aprell
Created January 14, 2012 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aprell/1612177 to your computer and use it in GitHub Desktop.
Save aprell/1612177 to your computer and use it in GitHub Desktop.
One-sided communication in RCCE
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include "RCCE.h"
#include "RCCE_lib.h"
#define PRINT(...) { printf(__VA_ARGS__); fflush(stdout); }
int RCCE_APP(int argc, char *argv[])
{
int ID, nprocs, next, prev;
int buf[8];
t_vcharp p;
dup2(STDOUT_FILENO, STDERR_FILENO);
RCCE_init(&argc, &argv);
ID = RCCE_ue();
nprocs = RCCE_num_ues();
next = (ID + 1) % nprocs;
prev = (ID - 1 + nprocs) % nprocs;
p = RCCE_malloc(RCCE_LINE_SIZE);
// RCCE_put() and RCCE_get() copy data in cache line chunks
buf[0] = 0;
RCCE_put(p, (t_vcharp)buf, sizeof(buf), ID);
RCCE_barrier(&RCCE_COMM_WORLD);
buf[0] = ID;
RCCE_put(p, (t_vcharp)buf, sizeof(buf), next);
RCCE_barrier(&RCCE_COMM_WORLD);
RCCE_get((t_vcharp)buf, p, sizeof(buf), ID);
assert(buf[0] == prev);
PRINT("Core %d reads a value of %d\n", ID, buf[0]);
// Alternatively, with explicit MPBT cache line invalidations
//RC_cache_invalidate();
//assert(*(int *)p == prev);
//PRINT("Core %d reads a value of %d\n", ID, *(int *)p);
RCCE_finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment