Skip to content

Instantly share code, notes, and snippets.

View enfiskutensykkel's full-sized avatar

Jonas Markussen enfiskutensykkel

View GitHub Profile
@enfiskutensykkel
enfiskutensykkel / thread_pool.c
Created December 5, 2023 19:48
Thread pool example
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#define NUM_WORKERS 8
#define NUM_JOBS 400
@enfiskutensykkel
enfiskutensykkel / ping-pong.cu
Last active April 3, 2023 15:06
Simple CUDA program for measuring the ping-pong latency between two GPUs
#include <cuda.h>
#include <stdexcept>
#include <string>
#include <vector>
#include <memory>
#include <cstdint>
#include <cstdio>
#include <unistd.h>
using error = std::runtime_error;
@enfiskutensykkel
enfiskutensykkel / Makefile
Last active October 17, 2019 11:17
Faster Sieve of Eratosthenes in Make
eq = $(filter $1,$2)
# List operations
slice = $(wordlist 2,$(words $1),$1)
map = $(if $2,$(call map,$1,$(call slice,$2),$3,$4 $(call $1,$(firstword $2),$3,$4)),$4)
rotate = $(call slice,$1) $(firstword $1)
zip = $(if $2,$(call zip,$1,$(call slice,$2),$(call rotate,$3),$4 $(call $1,$(firstword $2),$(firstword $3))),$4)
fold = $(if $2,$(call fold,$1,$(call slice,$2),$(call $1,$3,$(firstword $2),$2)),$3)
explode = $(if $(call eq,$(words $4),$1),$3,$(call explode,$1,$2,$3 $2,$(words $4) $4))
@enfiskutensykkel
enfiskutensykkel / Stream.java
Created August 28, 2019 08:01
Java 8 streams
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import java.util.function.Function;
import java.util.Arrays;
class Stream
{
@enfiskutensykkel
enfiskutensykkel / obscure.c
Created July 9, 2019 21:23
Dijkstra would not approve...
#include <stddef.h>
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
#include <stdlib.h>
static jmp_buf env;
static const char* shc =
"\x55\x48\x89\xe5\x48\x89\x7d\xe8\x48\x8b\x45\xe8"
@enfiskutensykkel
enfiskutensykkel / Makefile
Last active June 20, 2019 09:58
Makefile Sieve of Eratosthenes
### List operators
slice = $(wordlist 2,$(words $1),$1)
replicate = $(if $(call eq,$(words $4),$1),$3,$(call replicate,$1,$2,$3 $2,$(words $4) $4))
rotate = $(call slice,$1) $(firstword $1)
map = $(if $2,$(call map,$1,$(call slice,$2),$3,$4 $(call $1,$3,$(firstword $2),$4)),$4)
fold = $(if $2,$(call fold,$1,$(call slice,$2),$(call $1,$3,$(firstword $2))),$3)
zip = $(if $2,$(call zip,$1,$(call slice,$2),$(call rotate,$3),$4 $(call $1,$(firstword $2),$(firstword $3))),$4)
### Arithmetic operators
inc = $(words $(call replicate,$1,_) _)
@enfiskutensykkel
enfiskutensykkel / bandwidth.cu
Created May 24, 2019 16:17
Simple program for measuring GPU bandwidth
#include <cuda.h>
#include <stdexcept>
#include <string>
#include <vector>
#include <memory>
#include <cstdint>
#include <cstdio>
#include <unistd.h>
using error = std::runtime_error;
#include <type_traits>
template <typename T, typename = std::enable_if_t<std::is_compound_v<T>>>
constexpr T sum(const T& v) noexcept
{
return v;
}
@enfiskutensykkel
enfiskutensykkel / Fizzbuzz.js
Last active December 31, 2017 14:07
Functional FizzBuzz in JavaScript
Array.prototype.append = function (element) {
this.push(element);
return this;
};
range = (length) => {
return (function range() {
if (this.length < length) {
this.push(this.length);
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
struct __attribute__((packed)) class_object
{
// TODO* handle
void *super;
void (*destructor)(void*, void*);