Skip to content

Instantly share code, notes, and snippets.

@aprell
aprell / wcb.c
Created May 23, 2012 15:24
Updating MPB-allocated objects < cache line size 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 (RCCE_ue() == (i))
static int *fool_wcb;
@aprell
aprell / timer.h
Created June 4, 2012 15:18
Reading the Time Stamp Counter (x86)
#ifndef TIMER_H
#define TIMER_H
#define CYCLES_PER_SEC(t) ((t) * 1e9)
#define CYCLES_PER_MSEC(t) ((t) * 1e6)
#define CYCLES_PER_USEC(t) ((t) * 1e3)
typedef struct timer {
unsigned long long start, end;
unsigned long long elapsed;
@aprell
aprell / average
Created June 15, 2012 15:40
Simple script to calculate the average of a series of numbers
#!/bin/bash
# Calculate the average of a series of numbers
n=0
while read number; do
echo $number
numbers+=$number"+"
n=$((n+1))
done
numbers+="0"
@aprell
aprell / topology.h
Created June 15, 2012 16:37
SCC topology
// SCC
static int topology[48][10] =
{
/* Core 00 */ { 5, 1, 2, 3, 12, 13 },
/* Core 01 */ { 5, 0, 2, 3, 12, 13 },
/* Core 02 */ { 7, 0, 1, 3, 4, 5, 14, 15 },
/* Core 03 */ { 7, 0, 1, 2, 4, 5, 14, 15 },
/* Core 04 */ { 7, 2, 3, 5, 6, 7, 16, 17 },
/* Core 05 */ { 7, 2, 3, 4, 6, 7, 16, 17 },
/* Core 06 */ { 7, 4, 5, 7, 8, 9, 18, 19 },
@aprell
aprell / wtime.h
Created June 15, 2012 17:43
Simpler gettimeofday
#ifndef WTIME_H
#define WTIME_H
#include <sys/time.h>
#include <time.h>
// Seconds, milliseconds, or microseconds since the Epoch
static inline double wtime_sec(void)
{
@aprell
aprell / omp_parallel.txt
Created June 18, 2012 09:56
OpenMP: #pragma omp parallel
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int main(int argc, char *argv[])
{
if (argc != 2) exit(0);
#pragma omp parallel num_threads(4)
printf("Thread %d says %s\n", omp_get_thread_num(), argv[1]);
@aprell
aprell / omp_parallel_nested.txt
Created June 18, 2012 10:01
OpenMP: #pragma omp parallel (nested)
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int main(void)
{
#pragma omp parallel num_threads(4)
{
printf("%d: Hello outer parallel region!\n", omp_get_thread_num());
@aprell
aprell / omp_for_static.txt
Created June 18, 2012 10:03
OpenMP: #pragma omp for (static)
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void do_sth(void) { return; }
int main(void)
{
int i, n = 100;
@aprell
aprell / omp_for_dynamic.txt
Created June 18, 2012 10:06
OpenMP: #pragma omp for (dynamic)
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void do_sth_else(void) { return; }
int main(void)
{
int i, n = 100;
@aprell
aprell / omp_task.txt
Last active October 6, 2015 05:58
OpenMP: #pragma omp task
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int main(void)
{
int s, a = 4, b = 2;
#pragma omp task shared(s)
s = a + b;