Skip to content

Instantly share code, notes, and snippets.


Ivan Pribec ivan-pi

View GitHub Profile
ivan-pi / boyd_bvp_example.f90
Created March 18, 2019 00:59
Code example from book "Chebyshev and Fourier Spectral Methods" by John P. Boyd
View boyd_bvp_example.f90
program boyd_bvp
dimension xi(20),aphi(20),g(20),h(20,20),ugraph(101)
pi = 4.*atan(1.0)
! specify parameters
ivan-pi / cxxfi.hpp
Last active February 23, 2023 08:38
Example of calling Fortran from C++ using the enhanced C/Fortran interoperability
View cxxfi.hpp
#pragma once
#include <complex>
#include <vector>
#include <array>
#include <type_traits>
#include <span> // C++ 20
#include <iostream>
View Makefile
FCFLAGS=-Wall -O2 -fopenmp
.phony: all clean
all: abcd
abcd: abcd.F90
$(FC) $(FCFLAGS) -o $@ $<
ivan-pi / csr_example.cpp
Last active January 31, 2023 09:09
CSR SpMV with oneAPI
View csr_example.cpp
// compile with:
// dpcpp -qmkl csr_example.cpp
#include <algorithm>
#include <oneapi/mkl.hpp>
#include <CL/sycl.hpp>
int main(int argc, char const *argv[])
ivan-pi / test_mmap.f90
Last active January 16, 2023 16:23
Virtual memory array in Fortran based on POSIX system headers
View test_mmap.f90
! 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).
! so far I've only tested this on MacOS
ivan-pi / linspace.f90
Created December 19, 2019 18:54
Linspace in Fortran
View linspace.f90
module linspace_mod
use iso_fortran_env, only: dp => real64
implicit none
! Return evenly spaced numbers over a specified interval.
! Returns `num` evenly spaced samples, calculated over the interval `[start, stop]`.
ivan-pi /
Created January 20, 2022 13:52
Resources on Fortran
ivan-pi / interop.f90
Created September 27, 2022 15:41
Example of using C descriptors to call a routine implemented in Fortran
View interop.f90
module interop
use, intrinsic :: iso_c_binding, only: c_int
implicit none
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 / ghiau.txt
Created April 18, 2019 14:31
Lid-driven cavity flow benchmark u-velocity values from Ghia, U. K. N. G., Ghia, K. N., & Shin, C. T. (1982), Journal of computational physics, 48(3), 387-411.
View ghiau.txt
# Ghia, U. K. N. G., Ghia, K. N., & Shin, C. T. (1982).
# High-Re solutions for incompressible flow using the Navier-Stokes equations and a multigrid method.
# Journal of computational physics, 48(3), 387-411.
# Results for $u$-velocity along Vertical Line through Geometric Center of Cavity
# Re
# -------------------------------------------------------------
# y 100 400 1000 3200 5000 7500 10000
ivan-pi / bisect.cxx
Last active August 25, 2022 07:42
Passing a C Function Callback to the Boost Math Toolkit Root Finding Library
View bisect.cxx
// compile with g++ -o bisect.cxx poly.o -I<path/to/boost>
#include <cmath>
#include <iostream>
#include <boost/math/tools/roots.hpp>
// Functor providing termination condition
// Determines convergence in x based on if the relative or absolute tolerance are satisfied
template<class T>