Skip to content

Instantly share code, notes, and snippets.

View jmbr's full-sized avatar

Juan M. Bello-Rivas jmbr

View GitHub Profile
@jmbr
jmbr / build-mpisbcl.sh
Created June 15, 2019 17:20
Create an MPI-enabled SBCL executable
#!/bin/sh
sbcl --eval "(ql:quickload '(:swank :cl-mpi))" \
--eval "(defun toplevel () \
(push #'mpi:mpi-finalize *exit-hooks*) \
(mpi:mpi-init) \
(let ((port (+ swank::default-server-port (mpi:mpi-comm-rank)))) \
(swank:create-server :port port :dont-close t)) \
(sb-impl::toplevel-init))" \
--eval "(save-lisp-and-die \"mpisbcl\" :executable t :toplevel #'toplevel)"
.text
.align 4,0x90
.globl __Z21matrix_vector_productPKdPd
__Z21matrix_vector_productPKdPd:
LFB18:
vmovsd 8(%rdi), %xmm2
vmovsd (%rdi), %xmm1
vmulsd %xmm2, %xmm2, %xmm3
vmovsd 16(%rdi), %xmm0
vmovsd 32(%rdi), %xmm6
.text
.align 4,0x90
.globl __Z21matrix_vector_productPKdPd
__Z21matrix_vector_productPKdPd:
LFB18:
movsd (%rdi), %xmm0
movsd 8(%rdi), %xmm4
movapd %xmm0, %xmm5
movsd 16(%rdi), %xmm3
mulsd %xmm0, %xmm5
@jmbr
jmbr / gnome-flashback-stumpwm
Last active May 22, 2020 00:48
StumpWM with Gnome Flashback: all the amenities of Gnome plus the slick features of StumpWM.
This file goes in /usr/lib/gnome-flashback/
#! /bin/sh
exec gnome-session --session=gnome-flashback-stumpwm --disable-acceleration-check "$@"
@jmbr
jmbr / test-cholmod.cpp
Last active November 19, 2023 05:09
Simple example of how to use SuiteSparse's SPQR by creating a matrix of triplets.
#include <cstdlib>
#include <iostream>
#include <SuiteSparseQR.hpp>
int main(int argc, char* argv[]) {
cholmod_common common;
cholmod_sparse *A;
cholmod_dense *x, *b, *residual;
/*
* Example: spy("foobar.ppm", A);
*/
int spy(std::string const& ppmfile, arma::mat const& M) {
ofstream ofs(ppmfile);
if (!ofs.is_open())
return -1;
ofs << "P3\n" << M.n_rows << " " << M.n_cols << "\n1\n";
@jmbr
jmbr / double2.h
Created March 29, 2014 16:32
Simple example of the RATTLE algorithm
#ifndef DOUBLE2_H
#define DOUBLE2_H
#include <cmath>
#include <ostream>
#include <initializer_list>
struct double2 {
union {
@jmbr
jmbr / abort_unless.h
Created August 30, 2013 17:56
Unlike the assert() macro, abort_unless() is not disabled by defining the preprocessor macro NDEBUG.
#define abort_unless(expr) do { \
if (!(expr)) { \
fprintf(stderr, "%s:%u (%s): Assertion `%s' failed.\n", \
__FILE__, __LINE__, __func__, __STRING(expr)); \
fflush(stderr); \
abort(); \
} \
} while (0)
@jmbr
jmbr / gist:3090021
Created July 11, 2012 12:19
Next power of two
#include <cmath>
inline unsigned next_power_of_two(unsigned x) {
return unsigned(exp2f(ceilf(log2f(float(x)))));
}
@jmbr
jmbr / linspace.cpp
Created April 13, 2012 09:00
MATLAB's linspace in C++
template <typename T = double>
vector<T> linspace(T a, T b, size_t N) {
T h = (b - a) / static_cast<T>(N-1);
vector<T> xs(N);
typename vector<T>::iterator x;
T val;
for (x = xs.begin(), val = a; x != xs.end(); ++x, val += h)
*x = val;
return xs;
}