GithubHelp home page GithubHelp logo

dvallesp / fortran-kdtree Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dongli/fortran-kdtree

0.0 0.0 0.0 36 KB

A Fortran implementation of KD-Tree searching

License: MIT License

Fortran 91.01% CMake 3.29% NCL 5.70%

fortran-kdtree's Introduction

Introduction

KD-Tree is a standard data structure for indexing data, especially in 3D space. It is an extension of Binary-Space Partition (BSP) to more than one dimension. For more information on KD-Tree, please refer Wiki.

This repository is a Fortran implementation of KD-Tree. We need KD-Tree in scientific HPC scenarios, so Fortran is still the right language, and also we need more modern library interfaces.

This repository is a fork from Li Dong's one. Trees are built with real(4) data, as opposed to the initial repository.

Compilation

To get and compile the library,

  1. Clone the repository:
git clone https://github.com/dvallesp/fortran-kdtree
  1. Move to the repository folder and compile the library:
cd fortran-kdtree
cmake CMakeLists.txt
make
  1. Move the libfortran_kdtree.a and kdree.mod file to the folder where you want to use the library.

  2. Compile your code yourcode.f including the library:

    gfortran -O3 -fomit-frame-pointer (-whatever-option-you-might-add) yourcode.f libfortran_kdtree.a -o your_program.x

Usage

  use kdtree

  real(4), allocatable :: x(:,:)       ! num_dim, num_point
  integer, allocatable :: ngb_idx(:) ! num_ngb
  type(kdtree_type) tree
  integer i,j
  real(4) a(num_dim)

c   BUILDING A TREE
  ! Some random data
  do i=1,num_point
  do j=1,num_dim
    call random_number(a)
    arr(j,i)=a
  end do
  end do

  ! Tree built
  call tree%build(x)

c   SEARCH IN THE TREE
  ! Some random point
  call random_number(a)
  num_neigh=32
  allocate(ngb_idx(num_neigh))
  call tree%search(a, ngb_idx)
  ! Now ngb_idx contains the indices of the num_neigh first neighbours.

Note that the calls to tree%search() can be in principle OMP parallelised. In my tests, there is an almost-linear performance improvement from 1 to 4 threads, but not much beyond it.

Contributors

  • Li Dong (original repository)
  • David Vallés-Pérez (this fork, which just changes building data to real(4) and adds a bit of information).

fortran-kdtree's People

Contributors

dongli avatar dvallesp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.