Skip to content

Instantly share code, notes, and snippets.

Avatar

Ivan Pribec ivan-pi

View GitHub Profile
@ivan-pi
ivan-pi / cxxfi.hpp
Last active Nov 23, 2022
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>
@ivan-pi
ivan-pi / csr_example.cpp
Created Oct 24, 2022
CSR SpMV with oneAPI
View csr_example.cpp
// compile with:
// dpcpp -qmkl csr_example.f90
//
#include <algorithm>
#include <oneapi/mkl.hpp>
#include <CL/sycl.hpp>
int main(int argc, char const *argv[])
{
@ivan-pi
ivan-pi / interop.f90
Created Sep 27, 2022
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
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
Created Sep 13, 2022
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).
! https://www.scitepress.org/Papers/2021/105571/105571.pdf
!
! so far I've only tested this on MacOS
@ivan-pi
ivan-pi / bisect.cxx
Last active Aug 25, 2022
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>
@ivan-pi
ivan-pi / fortran_links.md
Created Jan 20, 2022
Resources on Fortran
View fortran_links.md
@ivan-pi
ivan-pi / fortran_namelist.xml
Created Dec 27, 2021
Fortran namelist configuration file for Notepad++
View fortran_namelist.xml
<NotepadPlus>
<UserLang name="Fortran Namelist" ext="nml" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00! 01 02 03 04</Keywords>
<Keywords name="Numbers, prefix1">.</Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
@ivan-pi
ivan-pi / fypp.sublime-build
Created Dec 9, 2021
Sublime build system command for fypp (https://fypp.readthedocs.io)
View fypp.sublime-build
{
"file_patterns": ["*.fypp", "*.fy90"],
"working_dir": "${file_path}",
"cmd": ["fypp", "${file}", "${file_base_name}.f90"]
}
@ivan-pi
ivan-pi / test_optval.fypp
Created Nov 24, 2021
fypp macros for dealing with Fortran optional arguments
View test_optval.fypp
#! Can be used currently
#:def optval(lhs,opt,default)
${lhs}$ = ${default}$
if (present(${opt}$)) ${lhs}$ = ${opt}$
#:enddef
#! This is the F202X conditional expression syntax
#:def optval2(opt,default)
present(${opt}$)) ? ${opt}$ : ${default}$
#:enddef
@ivan-pi
ivan-pi / lapack_interface.f90
Last active Mar 22, 2022
Example of LU factorization using Fortran parameterized derived types
View lapack_interface.f90
module lapack
implicit none
interface
subroutine sgetrf(m,n,a,lda,ipiv,info)
integer, intent(in) :: m, n, lda
real, intent(inout) :: a(lda,*)
integer, intent(out) :: ipiv(*)
integer, intent(out) :: info