suzuyuyuyu/fortran-introsort
Introsort, a hybrid sorting algorithm combining quicksort, heapsort, and insertion sort.
Fortran Intro Sort
A Fortran library that implements the introspective sort (introsort).
Requirements
- Fortran Compiler (ifx, gfortran, etc.)
- CMake (>= 3.14)
Build & Install
This project uses CMake for building. We provide CMake Presets for convenient configuration.
Using CMake Presets (Recommended)
You can list available presets with:
cmake --list-presetsCommon presets:
ifx-release: Intel Fortran Compiler (ifx), Release build (-O3)gfortran-release: GNU Fortran Compiler (gfortran), Release build (-O3)gfortran-debug: GNU Fortran Compiler (gfortran), Debug build with checks
1. Configure and Build
# Example: Using ifx (Release)
cmake --preset ifx-release
cmake --build --preset ifx-release2. Install (Optional)
# Install to system directories (requires sudo)
sudo cmake --install build/ifx-releaseYou can change the installation directory using -DCMAKE_INSTALL_PREFIX at the configuration step:
cmake --preset ifx-release -DCMAKE_INSTALL_PREFIX=./local_install
cmake --build --preset ifx-release
cmake --install build/ifx-releaseOr override it at the install step:
cmake --install build/ifx-release --prefix ./local_installYou can also customize the subdirectory structure (e.g., lib, include) by setting standard CMake variables or the project-specific INSTALL_MODULE_DIR:
cmake --preset ifx-release \
-DCMAKE_INSTALL_PREFIX=./local_install \
-DCMAKE_INSTALL_LIBDIR=my_lib \
-DINSTALL_MODULE_DIR=modulesThis will install artifacts to:
./local_install/my_lib/(Libraries)./local_install/modules/(Fortran Modules)
Build Examples
To build the example programs, set BUILD_EXAMPLES=ON.
cmake --preset ifx-release -DBUILD_EXAMPLES=ON
cmake --build --preset ifx-release
# Run the example
./build/ifx-release/example/example_sortUsage in your code
Fortran Code
program main
use intro_sort_mod
implicit none
! ...
! Sort array
call sort(array)
! Sort with options
! call sort(array, reverse=.true.)
end programTo avoid the conflict of subroutine name sort or others, you can rename as follows:
program main
use intro_sort_mod, only: introsort => sort
implicit none
! ...Link and Compile
You can compile and link your Fortran code with the installed library as follows:
ifx -I<install-path>/include -L<install-path>/lib <src-files> -o <output-executables> -lintrosortDirectory Structure (Build Artifacts)
After building, the artifacts are located in the build directory (e.g., build/ifx-release/):
include/: Module files (.mod)lib/: Static libraries (.a)example/: Example executables
License
This software is released under the MIT License.