Skip to content

Instantly share code, notes, and snippets.

@stelleg
stelleg / Dockerfile
Created October 17, 2018 04:37
centos tapir Dockerfile
FROM centos
ADD tapir.tgz /usr/
ADD hello /tapir/hello
RUN yum update -y && yum install -y libcilkrts libedit gcc make
RUN ln -s /usr/lib64/libcilkrts.so.5 /usr/lib/libcilkrts.so
CMD [ "/bin/bash" ]
@stelleg
stelleg / withConstArray.hs
Created July 29, 2018 15:56
alpha-equivalence example
import Foreign.Ptr
import Foreign.Storable
import Foreign.Marshal.Array
{-@ type PtrLen a n = {v:Ptr a | plen v = n && 0 <= pbase v && 0 <= plen v} @-}
{-@ withArray :: Storable a => x:[a] -> (PtrLen a (len x) -> IO b) -> IO b @-}
{-@ withConstArray :: Storable a => a -> n:Nat -> (PtrLen a n -> IO b) -> IO b @-}
withConstArray x n = withArray (replicate n x)
@stelleg
stelleg / sinc.c
Created June 5, 2018 21:46
sinc example
#include <qthread/qthread.h>
#include <qthread/sinc.h>
typedef struct args {
int i;
qt_sinc_t* sinc;
} args;
aligned_t hello(void* arg){
args a = *(args*)arg;
@stelleg
stelleg / branch_detach.c
Last active May 30, 2018 14:43
detach marker issue
bool detach();
void reattach(atomic_int* arg);
int f(){
atomic_int* a = alloca(sizeof(int));
a[0] = 0;
if(detach()){
a[0]++;
reattach(a);
}
@stelleg
stelleg / simplefor.c
Created January 18, 2018 18:10
simple cilk_for loop
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <cilk/cilk.h>
int main(int argc, char** argv){
int n = argc > 1 ? atoi(argv[1]) : 100000000;
int *a=malloc(n*sizeof(int));
cilk_for(int i=0; i<n; i++){
a[i] = i;
@stelleg
stelleg / gist:ec7dbd9c672d12542427ea82cb289693
Last active January 18, 2018 18:11
simple cilk_for error
clang-5.0: /ram/mnt/local/ssd1/parallel-ir/lib/Analysis/ScalarEvolution.cpp:3671: const llvm::SCEV* llvm::ScalarEvolution::getSCEV(llvm::Value*): Assertion `isSCEVable(V->getType()) && "Value is not SCEVable!"' failed.
#0 0x0000000003aa7438 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /ram/mnt/local/ssd1/parallel-ir/lib/Support/Unix/Signals.inc:398:0
#1 0x0000000003aa74cb PrintStackTraceSignalHandler(void*) /ram/mnt/local/ssd1/parallel-ir/lib/Support/Unix/Signals.inc:462:0
#2 0x0000000003aa59ce llvm::sys::RunSignalHandlers() /ram/mnt/local/ssd1/parallel-ir/lib/Support/Signals.cpp:49:0
#3 0x0000000003aa6dad SignalHandler(int) /ram/mnt/local/ssd1/parallel-ir/lib/Support/Unix/Signals.inc:252:0
#4 0x000014e62abeb5e0 __restore_rt (/lib64/libpthread.so.0+0xf5e0)
#5 0x000014e6297681f7 __GI_raise (/lib64/libc.so.6+0x351f7)
#6 0x000014e6297698e8 __GI_abort (/lib64/libc.so.6+0x368e8)
#7 0x000014e629761266 __assert_fail_base (/lib64/libc.so.6+0x2e266)
#8 0x000014e629761312 (/lib64/libc.so.6+0x2e312)
This file has been truncated, but you can view the full file.
; ModuleID = 'main.cpp'
source_filename = "main.cpp"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"class.std::ios_base::Init" = type { i8 }
%"class.std::basic_ostream" = type { i32 (...)**, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", %"class.std::basic_ostream"*, i8, i8, %"class.std::basic_streambuf"*, %"class.std::ctype"*, %"class.std::num_put"*, %"class.std::num_get"* }
%"class.std::ios_base" = type { i32 (...)**, i64, i64, i32, i32, i32, %"struct.std::ios_base::_Callback_list"*, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, %"struct.std::ios_base::_Words"*, %"class.std::locale" }
%"struct.std::ios_base::_Callback_list" = type { %"struct.std::ios_base::_Callback_list"*, void (i32, %"class.std::ios_base"*, i32)*, i32, i32 }
../../build/bin/clang -ftapir=openmp -fopenmp -O3 -g -o nqueens_tapir nqueens.c
#0 0x0000000003e9dd59 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /dev/shm/parallel-ir/lib/Support/Unix/Signals.inc:398:0
#1 0x0000000003e9ddea PrintStackTraceSignalHandler(void*) /dev/shm/parallel-ir/lib/Support/Unix/Signals.inc:462:0
#2 0x0000000003e9c32e llvm::sys::RunSignalHandlers() /dev/shm/parallel-ir/lib/Support/Signals.cpp:49:0
#3 0x0000000003e9d6f1 SignalHandler(int) /dev/shm/parallel-ir/lib/Support/Unix/Signals.inc:252:0
#4 0x00002ace8572b370 __restore_rt (/lib64/libpthread.so.0+0xf370)
#5 0x0000000001f8d278 llvm::Value::getSubclassDataFromValue() const /dev/shm/parallel-ir/include/llvm/IR/Value.h:655:0
#6 0x00000000020725ca llvm::Function::hasLazyArguments() const /dev/shm/parallel-ir/include/llvm/IR/Function.h:103:0
#7 0x00000000020725f0 llvm::Function::CheckLazyArguments() const /dev/shm/parallel-ir/include/llvm/IR/Function.h:108:0
#8 0x00000000023b5dd0 llvm::Function::arg_end() /dev/shm/parallel-ir/include/llvm/I
@stelleg
stelleg / test.c
Created August 11, 2016 14:36
qthreads test case
#include <qthread.h>
#include <qthread/sinc.h>
volatile int j = 0;
aligned_t task(void* arg){
j ++;
}
int main(){
@stelleg
stelleg / hm_scott.lhs
Last active July 4, 2016 10:42
Hindley Milner + Scott Encoding Musings
Sometimes it would be nice if a type system could automatically "do it's best"
to restrict what a value will be. For example, the type `Bool` is the compiler
saying the value will either be `True` or `False`, but it doesn't know which.
What we want is the compiler to be able to be precise when possible, so instead
of always saying `Bool` (or "I don't know"), it could say `True`, `False`, or
`Bool`. This gist shows how Hindley Milner already has this capability that can
be exercised by using Church or Scott encodings of simple data types.
> {-# LANGUAGE RankNTypes #-}
> import qualified Data.Maybe as M