Skip to content

Instantly share code, notes, and snippets.

View ivan-pi's full-sized avatar

Ivan Pribec ivan-pi

View GitHub Profile
@ivan-pi
ivan-pi / Makefile
Last active February 14, 2024 15:23
Lattice Boltzmann in 2D on a periodic domain
CXX=icpx
CXXFLAGS=-Wall -g -O2 -march=native
.PHONY: all
all: example
example: example.cpp
$(CXX) -o $@ $(CXXFLAGS) -fsycl -fsycl-targets=spir64_x86_64 $<
.PHONY: clean
@ivan-pi
ivan-pi / axpy.fypp
Created February 1, 2024 08:26
axpy.fypp
#:block parallel_for(d=1,name="axpy")
#:contains args
a, x, y
#:contains range
n
#:contains params
real, value :: a
real, intent(in) :: x(n)
real, intent(inout) :: y(n)
integer :: i
@ivan-pi
ivan-pi / cylinder_diffusion.py
Last active October 29, 2023 11:50
Diffusion in a shrinking cylinder using FEM
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
from math import sqrt
from scipy.integrate import solve_ivp
def l1kw(a,b):
"""Lobatto quadrature using 2 knots (trapezoid-like)"""
@ivan-pi
ivan-pi / analysis.py
Created September 15, 2023 14:13
Cylindrical diffusion solver with uncertainty quantification campaign
from easyvvuq.actions import CreateRunDirectory, Encode, Decode
from easyvvuq.actions import CleanUp, ExecuteLocal, Actions
params = {
"max_time": {"type": "float", "default": 1.5 },
"alpha": {"type": "float"},
"outfile": {"type": "string", "default": "output.json"}
}
@ivan-pi
ivan-pi / LC-3.asm
Last active July 15, 2023 20:50
LC-3 Assembly Language definition for customasm
#once
; LC3 Instruction Set Assembly for customasm (https://github.com/hlorenzi/customasm)
;
; References:
; Patt, Yale N.; Patel, Sanjay (2003). Introduction to Computing Systems:
; From Bits and Gates to C and Beyond. New York, NY: McGraw-Hill Higher
; Education. ISBN 0-07-246750-9.
#bankdef lc3_bank
FC=gfortran
FCFLAGS=-Wall -O2 -fopenmp
.phony: all clean
all: abcd
abcd: abcd.F90
$(FC) $(FCFLAGS) -o $@ $<
@ivan-pi
ivan-pi / cxxfi.hpp
Last active February 23, 2023 08:38
Example of calling Fortran from C++ using the enhanced C/Fortran interoperability
#pragma once
#include <complex>
#include <vector>
#include <array>
#include <type_traits>
#include <span> // C++ 20
#include <iostream>
@ivan-pi
ivan-pi / csr_example.cpp
Last active June 18, 2023 22:38
CSR SpMV with oneAPI
// compile with:
// icpx -fsycl csr_example.cpp
//
#include <algorithm>
#include <oneapi/mkl.hpp>
#include <CL/sycl.hpp>
int main(int argc, char const *argv[])
{
@ivan-pi
ivan-pi / interop.f90
Created September 27, 2022 15:41
Example of using C descriptors to call a routine implemented in Fortran
module interop
use, intrinsic :: iso_c_binding, only: c_int
implicit none
contains
subroutine fillint(arr) bind(c)
integer(c_int), intent(inout) :: arr(:)
integer :: i
arr = [(i**2,i=1,size(arr))]
end subroutine
end module
@ivan-pi
ivan-pi / test_mmap.f90
Last active January 16, 2023 16:23
Virtual memory array in Fortran based on POSIX system headers
! test_mmap.f90
!
! compile with:
! gfortran -Wall -O2 -o test_mmap test_mmap.f90
!
! inspired by the work:
! Rojc, B., & Depolli, M. (2021). A Resizable C++ Container using Virtual Memory. In ICSOFT (pp. 481-488).
! https://www.scitepress.org/Papers/2021/105571/105571.pdf
!
! so far I've only tested this on MacOS