Skip to content

Instantly share code, notes, and snippets.

@s417-lama
s417-lama / reduce.cpp
Last active August 22, 2023 12:10
C++ generic reduction using reducer and monoid (for more flexible parallel STL)
#include <iostream>
#include <algorithm>
#include <functional>
#include <limits>
#include <utility>
#include <vector>
#include <string>
#include <random>
#include <cassert>
@s417-lama
s417-lama / put_ieee_copyright_notice.bash
Created February 22, 2023 07:52
A shell script to put an IEEE copyright notice at the bottom of the front page of the paper
@s417-lama
s417-lama / avx_fma_checker.c
Created January 31, 2023 13:37
C program to measure actual throughput of AVX-512 FMA instructions and frequency
/*
* Usage:
* $ gcc -march=native -O3 -fopenmp avx_fma_checker.c
* $ ./a.out <n_threads> <n_iterations> <n_repeats>
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
@s417-lama
s417-lama / inset_plotly.py
Created May 6, 2022 10:21
Zoom-in (inset) plot example in plotly.py
import math
import numpy as np
import plotly.graph_objects as go
import plotly.io as pio
# plotly figure
pio.templates.default = "plotly_white"
fig = go.Figure()
# damped oscillation
@s417-lama
s417-lama / LICENSE
Created November 12, 2021 01:21
This license is applied to all of my gist snippets.
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@s417-lama
s417-lama / trun.bash
Last active April 25, 2021 13:42
Running commands as child processes on new tmux panes
#!/bin/bash
set -euo pipefail
export LC_ALL=C
export LANG=C
if !(type reptyr > /dev/null 2>&1); then
echo "Please install 'reptyr' command." >&2
exit 1
fi
@s417-lama
s417-lama / svg2pdf.bash
Created April 29, 2020 07:18
Reliable way to convert an SVG file to a PDF file using headless Chrome
#!/bin/bash
#
# Convert an SVG file to a PDF file by using headless Chrome.
#
if [ $# -ne 2 ]; then
echo "Usage: ./svg2pdf.bash input.svg output.pdf" 1>&2
exit 1
fi
@s417-lama
s417-lama / debug_segfaults_that_only_happen_outside_of_gdb.md
Last active January 7, 2020 02:50
Debug segfaults that only happen outside of gdb

Debug segfaults that only happen outside of gdb

In some rare cases, you may encounter bugs that happen only in normal execution, but not with GDB. It's really annoying; if you try to investigate it, it just disappears. Such bugs are called Haisenbug, and you can debug it with GDB by using a trick described here.

The idea is using signal handlers in programs. When SIGSEGV is caught, a signal handler is called. You can sleep for a long time in the signal handler, and then attach the program by using gdb attach.

@s417-lama
s417-lama / dekker.cpp
Created July 4, 2019 06:02
experiments on memory consistency (x86)
// compile: g++ dekker.cpp -lpthread
#include <stdio.h>
#include <thread>
#include <unistd.h>
#include <pthread.h>
#include <sys/syscall.h>
#define N 100000
#define USE_MEMFENCE 1