Skip to content

Instantly share code, notes, and snippets.

View jgreitemann's full-sized avatar

Jonas Greitemann jgreitemann

View GitHub Profile
@jgreitemann
jgreitemann / integer_sequence.cpp
Created September 15, 2018 11:03
Variadic expansion for aggregate initialization
#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>
struct foo {
foo(int i) : data(i) {}
friend std::ostream& operator<<(std::ostream& os, foo const& f) {
1.139094106868506 1.906912332044604 1.155279971572842 1.816240119921928
1.968538028170452 1.705944581231948 1.918194220532118 1.812205985231770
1.118324298619098 1.725613776800635 1.384799205428535 1.866053809172827
1.737349609441751 1.606855600174225 1.015329937740098 1.753721504578023
1.940862584344073 1.808855307356398 1.202632643688191 1.957539399728702
1.859908234819278 1.530527429322220 1.619837819772417 1.742353445157978
1.740218780123652 1.412897280275937 1.699645694977586 1.287551553928310
1.886571871186663 1.945403843665351 1.720919068945055 1.615504507618511
1.609826281455626 1.443930696540812 1.418713470467047 1.504665550385818
1.201470173935238 1.741604588352925 1.783894411407497 1.373038600912394
@jgreitemann
jgreitemann / basic.cpp
Last active May 3, 2017 08:23
Exercise 2
#include <cstdio>
int square(int x) {
return x*x;
}
int main() {
int a = 5;
int b = 2;
int c = a + b;
@jgreitemann
jgreitemann / wrong.cpp
Last active April 27, 2017 13:50
wrong.cpp
#include <iostream>
#include <vector>
double average(const std::vector<int>& v) {
double a;
size_t N = v.size();
for (size_t i = 0; i <= N; i++) {
int b = v[i];
a += b / N;
}
@jgreitemann
jgreitemann / merge.cpp
Created March 6, 2017 12:33
Demonstration of measurement duplication after repeated collective merge
#include <iostream>
#include <string>
#include <alps/accumulators.hpp>
#include <alps/utilities/mpi.hpp>
#include <alps/hdf5/archive.hpp>
int main (int argc, char *argv[]) {
alps::mpi::environment env(argc, argv, false);
alps::mpi::communicator c;
@jgreitemann
jgreitemann / array.cpp
Created June 22, 2016 08:39
Ways to map cmd line args to function pointers
#include <iostream>
#include <cstdlib>
double f_one(double x) {
return x;
}
double f_two(double x) {
return x*x;
}
#include <iostream>
#include <type_traits>
using namespace std;
template <typename...> using void_t = void;
template <typename T, typename = void>
struct has_foo : false_type {};
@jgreitemann
jgreitemann / benchmark.md
Last active May 6, 2016 12:27
Benchmark of vec class vs. valarray
N (dimension) vec runtime [s] valarray runtime [s]
3 1.82 14.7
10 1.82 14.7
15 1.82 14.7
20 13.8 14.7
25 17.2 14.7
50 40.5 14.7
100 78.4 14.7
@jgreitemann
jgreitemann / Makefile
Created March 24, 2016 12:32
CBLAS / LAPACKE test program
LDLIBS += -lcblas -llapacke
.PHONY: clean
test: test.o
clean:
$(RM) test.o test
@jgreitemann
jgreitemann / .gitignore
Last active February 25, 2016 13:22
LaTeX Templates
*.tex.backup
*.pdf
*.aux
*.log
*.toc
*.fls
*.fdb_latexmk
*.bbl
*.blg
*.out