Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jwscook's full-sized avatar

James Cook jwscook

View GitHub Profile
@jwscook
jwscook / DistributedHouseholderQR.jl
Last active March 26, 2024 21:08
Julia code to solve square or least-square linear problems Ax=b via householder QR where A can be an AbstractArray or DistributedArrays DArray and b can be a vector or a SharedArray
using Random, Distributed, Test
Random.seed!(0)
addprocs(4, exeflags="-t 2")
@everywhere begin
using LinearAlgebra, Random
using Distributed, DistributedArrays, SharedArrays
LinearAlgebra.BLAS.set_num_threads(Base.Threads.nthreads())
@jwscook
jwscook / HouseholderQR.jl
Last active March 23, 2024 08:23
Solve a square or least square linear system with the QR householder reflector algorithm
using LinearAlgebra, Random, Base.Threads
Random.seed!(0)
alphafactor(x::Real) = -sign(x)
alphafactor(x::Complex) = -exp(im * angle(x))
function householder!(A::Matrix{T}) where T
m, n = size(A)
H = A
α = zeros(T, min(m, n)) # Diagonal of R
@jwscook
jwscook / UnderstandingLAPACK.jl
Last active March 11, 2024 18:45
Understanding non-allocating factorization methods in scalapack
using LinearAlgebra, Test, Random
Random.seed!(0)
@testset "understand raw lapack calls" begin
@show Threads.nthreads()
@show BLAS.get_num_threads()
m = 5
n = 4
A = rand(m, n);
@jwscook
jwscook / TwoStream.md
Last active November 15, 2022 10:37
Linear theory and computational parameters for simulating the two-stream instability with a PIC code in normalised units.

Two stream instability

Electrostatic linear plasma dispersion relation

$$ 1 + \Sigma_s \frac{\Pi_s^2}{\omega}\int_{-\infty}^{\infty} \frac{\partial f_s(v_\parallel)}{\partial v_\parallel}\frac{v_\parallel}{\omega-k_\parallel v_\parallel} dv_\parallel=0 $$

where, in SI units:

@jwscook
jwscook / BesseljComparison.jl
Last active October 17, 2022 20:00
Comparing besselj speed and values between SpecialFunctions.jl and Bessels.jl
using SpecialFunctions, Bessels, LinearAlgebra, Plots
const spj = SpecialFunctions.besselj
const bej = Bessels.besselj
function foo!(A, B, f::T, ns, ms, N) where T
for (j, n) in enumerate(ns)
for (i, m) in enumerate(ms)
A[i, j] = 0
t = @elapsed for _ in 1:N
@jwscook
jwscook / config.log
Created January 21, 2022 19:15
Octave config.log
This file has been truncated, but you can view the full file.
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by GNU Octave configure 6.4.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ ./configure CFLAGS=-O3 -m64 -mavx2 -mfma -march=native -mtune=native -mfpmath=sse -malign-data=cacheline -ftree-vectorize -fno-semantic-interposition -fomit-frame-pointer -I/home/cookj/BUILT/include -L/home/cookj/BUILT/lib -Wl,-rpath=/home/cookj/BUILT/lib -pipe -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -lmimalloc CXXFLAGS=-O3 -m64 -mavx2 -mfma -march=native -mtune=native -mfpmath=sse -malign-data=cacheline -ftree-vectorize -fno-semantic-interposition -fomit-frame-pointer -I/home/cookj/BUILT/include -L/home/cookj/BUILT/lib -Wl,-rpath=/home/cookj/BUILT/lib -pipe -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -lmimalloc FFLAGS=-O3 -m64 -mavx2 -mfma -march=native -mtune=native -mfpmath=sse -malign-dat
@jwscook
jwscook / elixir_maxwell.jl
Created December 13, 2021 13:35
Trixi Discontinuous Galerkin Maxwell
using OrdinaryDiffEq
using LinearAlgebra
using StaticArrays
using Trixi
import Trixi: AbstractEquations, varnames, flux
abstract type AbstractMaxwellEquations{NDIMS, NVARS} <: AbstractEquations{NDIMS, NVARS} end
struct MaxwellEquations2D{RealT<:Real} <: AbstractMaxwellEquations{2, 6}
μ₀::Float64
ϵ₀::Float64
@jwscook
jwscook / CoordinateSystemInversionProblem.jl
Last active June 28, 2021 18:26
Automatic differentiation through inverse of coordinate transforms
using ForwardDiff: Dual, Tag, jacobian, value, tagtype, partials, gradient
using LinearAlgebra
using NLsolve
using Random
using Test
Random.seed!(0)
const jac = jacobian
@jwscook
jwscook / BiComplexes.jl
Created March 2, 2021 20:03
BiComplex numbers in Julia
module BiComplexes
using AutoHashEquals
export BiComplex, derivative
@auto_hash_equals struct BiComplex{T} <: Number
re::Complex{T}
im::Complex{T}
end
using Random
const seed = hash(time())
Random.seed!(seed)
searchstring = "const seed = "
open("$(@__FILE__)" * ".reproducible", "w") do io
for line in readlines(open(@__FILE__))
if length(line) > length(searchstring) && line[1:length(searchstring)] == searchstring