Skip to content

Instantly share code, notes, and snippets.

// hash_bench2.cc (compute std::hash once per key)
// based on https://github.com/greg7mdp/parallel-hashmap/blob/master/examples/hash_bench.cc
//
// clang++ -o hash_bench2 -std=c++20 -Wall -O3 hash_bench2.cc -I./parallel-hashmap
#include <iostream>
#include <string>
#include <array>
#include <cstdint>
#include <limits>
@marioroy
marioroy / README.md
Last active June 20, 2023 22:10
C++ parallel chunking demonstrations

C++ parallel chunking demonstrations

I came across Parallel Hashmap for C++. It provides a parallel demonstration to count the number of occurrences of each word in a large text file using multiple threads. This gist includes complimentary chunking variants for comparison. Results were captured on Clear Linux and Fedora 38.

Preparation

# Download Jane Austin "Pride and Prejudice".
@marioroy
marioroy / grep-count-pcre2.cc
Last active July 17, 2023 02:55
Grep Count C++ OpenMP demonstrations for website
// Grep PCRE2 C++ OpenMP demonstration for website:
// https://cpufun.substack.com/p/processing-a-file-with-openmp
//
// By Mario Roy - May 19, 2023
// License: GNU General Public License.
// See http://www.gnu.org/licenses/ for license information.
// SPDX-License-Identifier: GPL-3.0-or-later
// Based on rtoa-pgatram-allinone2b.cpp:
// https://perlmonks.org/?node_id=11152225
//
@marioroy
marioroy / fedora-config.diff
Last active October 18, 2023 07:29
My custom kernel-xanmod for personal usage.
29a30
> CONFIG_UAPI_HEADER_TEST=y
6187d6187
< # CONFIG_VIDEO_PCI_SKELETON is not set
10496c10496
< CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y
---
> # CONFIG_FS_VERITY_BUILTIN_SIGNATURES is not set
10849c10849
< CONFIG_LSM_MMAP_MIN_ADDR=0
@marioroy
marioroy / GCC_12.x_on_Fedora_38.README.txt
Last active April 7, 2024 18:16
Notes for GCC 12.x installation on Fedora 38
#################################################################
# Install minimum dependencies.
#################################################################
# On "Fedora"-based systems, install minimum dependencies.
# sudo dnf install binutils libgcc glibc-devel libstdc++ patchelf wget
# On "Clear Linux" 40690+, install minimum dependencies.
# sudo swupd bundle-add c-basic patchelf wget
# Fetch gcc-12 packages from Debian:
@marioroy
marioroy / mcesort
Last active March 21, 2023 06:27
mcesort using mini-Perl-MCE (a parsort variant) with working -j, --parallel
#!/usr/bin/env perl
=pod
=head1 NAME
mcesort - Sort files or standard input in parallel
=head1 SYNOPSIS
@marioroy
marioroy / update_version.pl
Created November 24, 2021 03:14
Author script for updating mce-perl and mce-shared versions.
#!/usr/bin/env perl
# cd $HOME/git/mce-perl or mce-shared
# ../update_version.pl README.md `find lib -name "*.p*"`
use strict;
use warnings;
use File::Inplace;
my $old = '1.874';
@marioroy
marioroy / clr-5.10.19-1032.native-3.txt
Created March 17, 2021 07:46
Clear Linux (34370) latency testing on AMD 3970X - Part Three
Terminal 1: mce-sort2 --maxworkers=40 --bm --check --no-output -e tr-radix random.txt
Terminal 2: [rootuser] cyclictest --smp -p98 -m -D 50 -q
Linux clr-linux 5.10.19-1032.native #1 SMP
mce-sort2 : 26.0 seconds (memory bound, sort 32GiB file under /dev/shm)
# /dev/cpu_dma_latency set to 0us
T: 0 ( 1889) P:98 I:1000 C: 49989 Min: 1 Act: 4 Avg: 7 Max: 7626
T: 1 ( 1890) P:98 I:1500 C: 33329 Min: 1 Act: 4 Avg: 9 Max: 4429
@marioroy
marioroy / clr-5.10.19-1032.native-2.txt
Last active March 17, 2021 00:28
Clear Linux (34370) latency testing on AMD 3970X - Part Two
Terminal 1: numactl -C 0-31 time hackbench -T -f 4 -g 8 -l 3000000 # 64 tasks
Terminal 2: numactl -C 32-63 time hackbench -T -f 4 -g 8 -l 3000000 # 64 tasks
Terminal 3: [rootuser] cyclictest --smp -p98 -m -D 120 -q
Terminal 4: [rootuser] sync; echo 3 > /proc/sys/vm/drop_caches; time ls -R /usr
Linux clr-linux 5.10.19-1032.native #1 SMP
echo 10000000 >/proc/sys/kernel/sched_min_granularity_ns
echo 5000000 >/proc/sys/kernel/sched_migration_cost_ns
@marioroy
marioroy / clr-5.10.19-1032.native-1.txt
Last active March 17, 2021 00:28
Clear Linux (34370) latency testing on AMD 3970X - Part One
Terminal 1: numactl -C 0-31 time hackbench -T -f 4 -g 8 -l 3000000 # 64 tasks
Terminal 2: numactl -C 32-63 time hackbench -T -f 4 -g 8 -l 3000000 # 64 tasks
Terminal 3: [rootuser] cyclictest --smp -p98 -m -D 120 -q
Terminal 4: [rootuser] sync; echo 3 > /proc/sys/vm/drop_caches; time ls -R /usr
Linux clr-linux 5.10.19-1032.native #1 SMP
hackbench 1 : 54 seconds
hackbench 2 : 53 seconds
ls -R /usr : 8.5 seconds avg (repeated sync/echo/ls 4 times)