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 / abstraction_penalty.F90
Last active March 4, 2025 22:18
Abstraction Penalty of procedure overloading and type composition in Fortran
! abstraction_penalty.F90 --
! A Fortran version of the Stepanov Abstraction Penalty Benchmark
!
! The aim of this benchmark is to verify how efficiently
! compilers can deal with Fortran array semantics and data abstraction.
!
! The structure of the benchmark is quite simple. It adds 2000
! doubles in an array 25000 times. Since arrays are first-class citizens
! in Fortran, it is expected that a compiler can simply create the
! an array descriptor without the creation of temporary array copies
C BERECHNUNG EINER QUADRATWURZEL
1 READ(*,100) Z
100 FORMAT(F9.3)
WRITE(*,101)
101 FORMAT(6X,13HQUADRATWURZEL)
WRITE(*,102)
102 FORMAT(//6X,1HZ,11X,1HW)
2 WN=1.0
3 WN1=0.5*(WN + Z/WN)
WRITE(*,300) WN1
@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 January 23, 2025 12:00
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[])
{