Skip to content

Instantly share code, notes, and snippets.

@dajuno
dajuno / vec_dot.cpp
Created March 7, 2024 11:58
C++ vs Python vs numpy vs Numba JIT speed comparison
/* compile with:
g++ -O3 -std=c++11 vec_dot.cpp -I/usr/include/openblas -fopenmp -lcblas
(or clang++)
NOTE:
- in main, comment either the OpenMP or the BLAS block! using both leads to degraded performance.
- on my TP X13 G3 with Intel i7-1260P, adding -march=native will lead to lower performance!!
- other flags like -funroll-loops -flto -finline-functions did not seem to lead to significant performance increases
*/
@dajuno
dajuno / nvim.conf
Created March 29, 2022 09:20
neovim config
if &compatible
set nocompatible
endif
filetype plugin indent on
" should be set before loading polyglot
let g:polyglot_disabled = ['yaml', 'latex'] " disable vim-polyglot
call plug#begin('~/.config/nvim/plugged')
@dajuno
dajuno / poission_LRC.py
Created July 7, 2021 09:17
Example for PETSc MatCreateLRC using FEniCS and petsc4py
"""
Solve a simple Poisson system with a low rank update using PETSc MatCreateLRC.
The low rank update is defined at 3 boundaries with different weights, Dirichlet
BC is applied to the other boundary.
https://www.mcs.anl.gov/petsc/petsc-3.13/docs/manualpages/Mat/MatCreateLRC.html
some hints:
https://fenicsproject.discourse.group/t/add-matrix-to-assembled-matrix/122/2
https://lists.mcs.anl.gov/pipermail/petsc-users/2020-February/040228.html
$MeshFormat
2.2 0 8
$EndMeshFormat
$Nodes
142
1 0 0 0
2 1 0 0
3 1 1 0
4 0 1 0
5 0.09999999999981467 0 0
@dajuno
dajuno / tmux_local_install.sh
Last active September 29, 2017 18:26 — forked from ryin/tmux_local_install.sh
bash script for installing tmux without root access
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/.local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=2.5
@dajuno
dajuno / print_dict.py
Created June 28, 2016 15:55
print nested dict
# var 1
for key, val in prms.items():
if type(val) is dict:
for key2, val2 in val.items():
print('\t {0}: {1}'.format(key2, val2))
else:
print('{0}: {1}'.format(key, val))
# var 2
import yaml
from dolfin import *
import numpy as np
import mshr
from IPython import embed
from cbcpost.utils.mpi_utils import gather, broadcast
def vec(x): return as_backend_type(x).vec()
def mat(A): return as_backend_type(A).mat()
class NormalRotation(PETScMatrix):
@dajuno
dajuno / build.log
Created January 23, 2016 13:56
cython build log
2016/01/23 09:50:46 - INFO: [package:run_job] running [u'/bin/bash', '_hashdist/build.sh']
2016/01/23 09:50:46 - INFO: [package:run_job] environment:
2016/01/23 09:50:46 - INFO: [package:run_job] {'ARTIFACT': u'/home/dnolte/.hashdist/bld/cython/zb55xazf5kjr',
2016/01/23 09:50:46 - INFO: [package:run_job] 'BASH': u'/bin/bash',
2016/01/23 09:50:46 - INFO: [package:run_job] 'BUILD': u'/home/dnolte/.hashdist/tmp/cython-zb55xazf5kjr',
2016/01/23 09:50:46 - INFO: [package:run_job] 'HASHDIST_CPU_COUNT': '1',
2016/01/23 09:50:46 - INFO: [package:run_job] 'HDIST_CONFIG': '{"gc_roots":"/home/dnolte/.hashdist/gcroots","build_stores":[{"dir":"/home/dnolte/.hashdist/bld"}],"source_caches":[{"dir":"/home/dnolte/.hashdist/src"}],"cache":"/home/dnolte/.hashdist/cache","build_temp":"/home/dnolte/.hashdist/tmp"}',
2016/01/23 09:50:46 - INFO: [package:run_job] 'HDIST_IMPORT': u'patchelf/5ak23gxoswdv2qq7qsm733jx6mpknvlz python/7z56z4cdcuns2ncdbityazni6tpmprte',
2016/01/23 09:50:46 - INFO: [package:run_job] 'H
@dajuno
dajuno / ex_groups_simple.geo
Created January 13, 2016 21:36
GMSH simple example physical groups
L = 1;
dx1 = 0.1*L;
Point(1) = {-0.5*L, -0.5*L, -0.5*L, dx1};
Point(2) = { 0.5*L, -0.5*L, -0.5*L, dx1};
Point(3) = { 0.5*L, -0.5*L, 0.5*L, dx1};
Point(4) = {-0.5*L, -0.5*L, 0.5*L, dx1};
Line(1) = {1, 2};
Line(2) = {2, 3};
@dajuno
dajuno / ex_groups.geo
Created January 13, 2016 21:01
GMSH example physical groups
L = 1;
dx1 = 0.05*L;
R = 0.398942280*L; /* radius for a circle taking half of the unit square
area */
dx2 = dx1*2*R/L;
Point(1) = {-0.5*L, -0.5*L, -0.5*L, dx1};
Point(2) = { 0.5*L, -0.5*L, -0.5*L, dx1};
Point(3) = { 0.5*L, -0.5*L, 0.5*L, dx1};
Point(4) = {-0.5*L, -0.5*L, 0.5*L, dx1};