I am new to scientific computing. I am looking for a Fortran ( preferably f90) implementation of an Octree.

My problem requires an Octree which divides my domain until there aren't more than some N particles(or sources where I know the density value which can be plugged in an integral equation method to solve an equation like the Laplace equation) in any box.

All I could find was this C++ implementation . I want to know if there are already existing Fortran libraries that I can use.

Also, good paper recommendations on Octree implementations in Fortran that can be used so that applying fast integral equation methods on the computational box becomes easy, will be appreciated!


2 Answers 2


I don't have experience with Octrees, but whenever there is some nice C++ library that I want to use in Fortran, I simply write a simple C driver --- typically a few C functions that do exactly what I need. Then I call them from Fortran using the iso_c_binding module. This has the great advantage that you reuse a well tested library with a community around it.

For information how to use iso_c_binding, I wrote up some information here:


this particular info is for calling Fortran from C. I can see that I should update it. Here is my code where I call C++ library from Fortran, the first link is the simple C driver, the second link is a Fortran interface, and then I just call it like any other Fortran subroutine:




You seem to be very set on using Fortran. Octrees, when implemented efficiently, are rather complex data structures and, as such, better suited to programming languages that have more support for this, such as C/C++. There are a number of very high quality implementations in C/C++ that you could use.

  • $\begingroup$ Thanks for your answer! But, the fast integral methods that I am to use are written in Fortran. It would be natural to write the Octree code in Fortran as well. $\endgroup$
    – rivendell
    May 25, 2013 at 22:37
  • $\begingroup$ Which fast integral methods? They are mostly all wrapped in higher level languages, which also notably wrap octrees as well . . . $\endgroup$
    – meawoppl
    Jun 17, 2013 at 18:35
  • $\begingroup$ What support for efficient octree implementations is missing in (modern) Fortran compared to C? The only real downside I know is that unsigned integers are missing, so that you have to write some bitwise operations explicitly. $\endgroup$ Apr 17, 2016 at 22:01
  • $\begingroup$ @JannisTeunissen -- it's not that Fortran 200x doesn't have ways to create complex data structures, it's more about how easy it is (or not). C++, for example, has std::map, std::multimap, std::vector, std::sort, and so on and so forth, all generically avaiable independent of the underlying data type being stored. There's no argument that you can do all of this in Fortran as well today, but it requires days and weeks of work that you could productively use to actually work on your application, rather than on the underlying data structures. $\endgroup$ Apr 19, 2016 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.