Skip to content

Instantly share code, notes, and snippets.

@plampite
plampite / myreduce2.f90
Created May 9, 2022 21:23
A Fortran example of a reduce step in MPI implemented trough simple mpi_send/recv calls. Useful when using mpi_type_create_struct and mpi_op create might be unconvenient or impossible. This version uses the basic binomial tree algorithm in MPICH.
program myreduce2
!Program to show a simple implementation of mpi_reduce, with only mpi_send/recv
!Useful for cases where one would need mpi_type_create_struct and mpi_op_create to achieve the same result
!This version uses the same MPICH binomial tree algorithm (order from 0 to nproc-1), which allows an easy
!customization of the processing order (just map each process to a different id)
!Here it is tested against the simple MPI intrinsic MPI_SUM on a single real variable
use, intrinsic :: iso_fortran_env, only : int32, real64
use mpi
implicit none
integer(int32) :: i, nstep, ppd, myp, nproc, myid, mpi_err, mpi_stat(mpi_status_size)
@plampite
plampite / myalltoall.f90
Created May 7, 2022 18:29
A Fortran example of a deadlock avoiding MPI loop among all processes, using a single-line round robin algorithm to schedule the order of communications for each process
program myalltoall
!Program to show a simple implementation of a deadlock avoiding mpi loop among all processes which,
!in principle, is similar to an alltoall loop. However, the main purpose of the technique shown here is to
!properly reorder shortest (i.e., each process with just few others) non-blocking communication loops,
!in order to alleviate the burden on the communication side (as each exchange is matched, everything
!is exchanged very quickly). Here, it is tested against the the mpi_allreduce intrinsic with MPI_SUM
!on a single real variable, but IT IS NOT a replacement for allreduce (nor alltoall or any other intrinsic).
use, intrinsic :: iso_fortran_env, only : int32, real64
use mpi
implicit none
@plampite
plampite / myreduce.f90
Created May 7, 2022 18:25
A Fortran example of a reduce step in MPI implemented trough simple mpi_send/recv calls. Useful when using mpi_type_create_struct and mpi_op create might be unconvenient or impossible.
program myreduce
!Program to show a simple implementation of mpi_reduce, with only mpi_send/recv
!Useful for cases where one would need mpi_type_create_struct and mpi_op_create to achieve the same result
!Here it is tested against the simple MPI intrinsic MPI_SUM on a single real variable
use, intrinsic :: iso_fortran_env, only : int32, real64
use mpi
implicit none
integer(int32) :: i, nstep, pp2, ppd, nproc, myid, mpi_err, mpi_stat(mpi_status_size)
real(real64) :: x, xr1, xr2, xr
@plampite
plampite / mod_fint.F90
Last active March 7, 2024 23:23
A simple, multi-dimensional linear interpolation function in Fortran. Roughly inspired by FINT in Cernlib, but hopefully more readable and easy to understand.
!Copyright 2024 Paolo Lampitella
!This code is licensed under the terms of the MIT license
MODULE mod_fint
IMPLICIT NONE
INTEGER, PARAMETER :: IP4 = SELECTED_INT_KIND(9)
INTEGER, PARAMETER :: WP = SELECTED_REAL_KIND(15,307)
CONTAINS