traitecoevo / plant

Trait-Driven Models of Ecology and Evolution :evergreen_tree:
https://traitecoevo.github.io/plant
53 stars 20 forks source link

[openmp] OpenMP for multicore speedup #390

Open dfalster opened 1 month ago

dfalster commented 1 month ago

I've just discovered the OpenMP framework from Wikipedia: "OpenMP (Open Multi-Processing) is an application programming interface (API) that supports multi-platform shared-memory multiprocessing programming in C, C++, and Fortran,[3] on many platforms, instruction-set architectures and operating systems, including Solaris, AIX, FreeBSD, HP-UX, Linux, macOS, and Windows. It consists of a set of compiler directives, library routines, and environment variables that influence run-time behavior."

It offers exciting possibility of parellelisation within execution of a single run, which could greatly speed up model runs. By far the slowest part of FF16 is creation of the environment, which involves calculating light a sequence of points. This could be parallelised. Any panelisation would come at expense of running multiple instances, i.e. if a single run is using four cores, you can't run 4 instances simultaneously. But single instances are most common in development at least.

Importantly, there's little code required. Just insert few lines at the relevant places in the C++. See this for presentation for a nice intro https://www.bu.edu/tech/files/2017/09/OpenMP_2017Fall.pdf

A limitation is that OpenMp has shaky support on Mac. So we'd be looking at using this on linux/windows: https://mac.r-project.org/openmp/

For an example, see stringiest package: https://github.com/markvanderloo/stringdist/tree/master