Created
January 14, 2012 17:31
-
-
Save aprell/1612198 to your computer and use it in GitHub Desktop.
Playing with byte flags in RCCE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <unistd.h> | |
#include "RCCE.h" | |
#include "RCCE_lib.h" | |
#define WORKER(i) if (ID == (i)) | |
#define PRINT(...) { printf(__VA_ARGS__); fflush(stdout); } | |
#define NFLAGS 32 | |
extern RCCE_FLAG_LINE RCCE_flags; | |
int RCCE_APP(int argc, char *argv[]) | |
{ | |
int ID, i; | |
RCCE_FLAG flags[NFLAGS]; | |
dup2(STDOUT_FILENO, STDERR_FILENO); | |
RCCE_init(&argc, &argv); | |
// RCCE_comm_split() in RCCE_init() allocates two synchronization flags! | |
assert(RCCE_flags.members == 2); | |
ID = RCCE_ue(); | |
if (RCCE_num_ues() < 3) { | |
WORKER(0) PRINT("Run with 3 or more cores!\n"); | |
goto exit; | |
} | |
for (i = 0; i < NFLAGS-2; i++) { | |
RCCE_flag_alloc(&flags[i]); | |
} | |
// Now we have a full cache line of flags | |
// The first two flags are internal flags, don't touch! | |
assert(RCCE_flags.members == NFLAGS); | |
// Set user flags 1, 2, 5, and 29 on core 2 | |
WORKER(0) { | |
RCCE_flag_write(&flags[1], RCCE_FLAG_SET, 2); | |
RCCE_flag_write(&flags[2], RCCE_FLAG_SET, 2); | |
RCCE_flag_write(&flags[5], RCCE_FLAG_SET, 2); | |
RCCE_flag_write(&flags[29], RCCE_FLAG_SET, 2); | |
} | |
RCCE_barrier(&RCCE_COMM_WORLD); | |
WORKER(1) { | |
unsigned char f[NFLAGS]; | |
// Get all 32 flags | |
RCCE_get(f, flags[0].line_address, NFLAGS, 2); | |
// Print only user flags | |
for (i = 2; i < NFLAGS; i++) { | |
PRINT("Flag %2d: %d\n", i-2, f[i]); | |
} | |
} | |
for (i = 0; i < NFLAGS-2; i++) { | |
RCCE_flag_free(&flags[i]); | |
} | |
exit: | |
RCCE_finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment