Skip to content

Instantly share code, notes, and snippets.

@aprell
aprell / mpi_win_create_test.c
Created December 16, 2011 12:41
MPI window creation must be collective
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#define WORKER(id) if (ID == (id))
#define MASTER WORKER(0)
int main(int argc, char *argv[])
{
int numprocs, ID;
@aprell
aprell / mpi_mutex.c
Created December 16, 2011 14:17
Simple mutex implementation based on MPI-2 RMA
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <mpi.h>
#include "mpi_mutex.h"
#include "utest.h"
#define MPI_MUTEX_MSG_TAG_BASE 1023
@aprell
aprell / rcce_put.c
Created January 14, 2012 17:25
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[])
@aprell
aprell / rcce_mpb.c
Created January 14, 2012 17:30
Writing single bytes to MPBs in RCCE
#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); }
@aprell
aprell / rcce_flags.c
Created January 14, 2012 17:31
Playing with byte flags in RCCE
#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
@aprell
aprell / affinity.c
Created February 6, 2012 14:34
Processor affinity: binding threads to cores
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sched.h>
#define MAX_NUM_THREADS 16
static void set_thread_affinity(pthread_t t, int cpu)
@aprell
aprell / jmp.c
Created March 1, 2012 17:34
Switching between coroutines/tasks: setjmp/longjmp (single stack)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <setjmp.h>
#include <assert.h>
#include <unistd.h>
#include <time.h>
#include "list.h"
@aprell
aprell / pth.c
Created March 1, 2012 17:39
Switching between coroutines/tasks: GNU Pth (separate stacks)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <unistd.h>
#include <time.h>
#include <pth.h>
#include "list.h"
struct task {
@aprell
aprell / findfn
Created March 2, 2012 11:39
Looks for a given function in a number of files. Glorified wrapper for ctags.
#!/bin/bash
print_usage()
{
echo "Usage: findfn [OPTION]... [FUNCTION] [FILE]..."
echo "Example 1: findfn foo main.c"
echo "Example 2: findfn foo main.c foo.c"
}
check_usage()
@aprell
aprell / volatile.c
Created March 7, 2012 15:33
When "volatile" becomes necessary
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
static int shared;
static void *thread_func(void *args)
{
int ID = *(int *)args;