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 / aoc_day4.f90
Created December 4, 2020 23:20
Advent of Code - Day 4
module day4
use fortran202x_split, only: split
!! The `fortran202x_split` module can be downloaded from:
!! https://github.com/milancurcic/fortran202x_split
implicit none
private
public :: count_passports
@ivan-pi
ivan-pi / qtree_example.f90
Created December 8, 2020 12:56
Quadtree example in Fortran with gnuplot output
module quadtree
! Adapted from the tutorial at https://scipython.com/blog/quadtrees-2-implementation-in-python/
implicit none
integer, parameter :: wp = kind(1.0d0)
type :: qtnode
real(wp) :: c(2)
@ivan-pi
ivan-pi / btree_mod.f90
Created December 8, 2020 13:04
Ball tree in Fortran following the one by Jake Vanderplas (see https://gist.github.com/jakevdp/5216193). Construction appears to work, querying is broken!
module nheap_mod
implicit none
private
public :: nheap
integer, parameter :: wp = kind(1.0d0)
@ivan-pi
ivan-pi / test_spblas.f90
Last active December 25, 2020 23:36
Intel MKL Sparse BLAS matrix-vector product example
! Sparse BLAS matrix-vector product example
!
! The following code demonstrates the creation of
! a CSR matrix, and the sparse matrix-vector product
! using the sparse BLAS functions in Intel MKL.
!
! For linking options for your specific platform see
! the Intel MKL link line advisor located at:
! https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onemkl/link-line-advisor.html
!
@ivan-pi
ivan-pi / pcg32.f90
Last active July 12, 2022 10:21
Attempt of porting the PCG random number generator by Melissa O'Neill to Fortran. The code is not tested. Signed integers are used for the state.
!
! PCG Random Number Generation for Fortran
! Ported from the minimal C version by Melissa O'Neill
!
! Copyright 2020 Ivan Pribec <ivan.pribec@gmail.com>
!
!
! Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
!
@ivan-pi
ivan-pi / chkend.f90
Created February 16, 2021 09:43
Check processor endianess in Fortran
!> Check Endianess
!>
!> Inspect the endianess of the platform.
!>
!> Based on a program posted by @urbanjost (urbanjost@comcast.net)
!> posted at https://github.com/fortran-lang/stdlib/issues/323. The original
!> program was based on ideas from the Code Tuning co-guide, 1998 Lahey Fortran
!> Users' Conference.
!>
!> Author: Ivan Pribec (ivan.pribec@gmail.com)
@ivan-pi
ivan-pi / integer_list_mod.f90
Created March 5, 2021 18:11
Fortran experiment with a fixed-size integer list
module integer_list_mod
implicit none
private
public :: integer_list
type :: index_t
private
integer :: idx
module pad_mod
implicit none
interface padl
module procedure padl_blank
module procedure padl_char
end interface
interface padr
@ivan-pi
ivan-pi / template_ideas.md
Last active September 30, 2021 14:36
Some ideas for documenting Fortran procedures in (GitHub-Flavored) Markdown documents

Ideas for Fortran documentation in Markdown

Version 1 (f90doc-inspired)

Pros:

  • Terse, reuses actual procedure declaration
  • All argument attributes are visible

Cons:

@ivan-pi
ivan-pi / lapack_interface.f90
Last active March 22, 2022 21:36
Example of LU factorization using Fortran parameterized derived types
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