Docsity

Octopus Software Development: Best Practices and Overview, Essays (high school) of Life Sciences

Partial preview of the text

Download Octopus Software Development: Best Practices and Overview and more Essays (high school) Life Sciences in PDF only on Docsity!

Developing Octopus:

an Introduction

Micael Oliveira

Octopus Course 2021, MPSD Hamburg

Scientific Software Development

Unique challenges: Translating science into code Need to understand the science Scientist are often not trained in software engineering Software performance is often important Many codes need to be enabled for high-performance computing: Parallelism (MPI, OpenMP, etc) GPU’s Complex hardware Unusual architectures

Some best practices

Code is the enemy: it can have bugs and it needs maintenance Do not reinvent the wheel: reuse code Write code that is easy to read and that is mostly self-documented Comments about why the code does something are very important Test your code “Premature optimization is the root of all evil”

Electronic structure “monolithic” and modular coding

paradigms

M. J. T. Oliveira, N. Papior, Y. Pouillon, V. Blum, E. Artacho et al, J. Chem. Phys. 153 , 024117 (2020)

Octopus: Dissecting the Animal

Project formaly started in 2001 Free-software (GPL) Writen mainly in Fortran 2003 Fortran sources are preprocessed with cpp Some C, C++, perl and Bison (use the right tool for the job!) CUDA/OpenCL for GPU support Currently over 250,000 lines of code

Octopus: Dissecting the Animal

octopus-code.org

Wiki based website A new website is under construction octopus-code.org/new-site/develop Ressources for users: Code download Compilation instructions (partially outdated) Manual (outdated) Tutorials Input variable reference ... Dedicated section for developers

octopus-code.org/wiki/Developers

“Starting to develop” guide (must read!) Workflow guide (must read!) Coding standards Input variable reference (development version) Some code documentation (partially outdated) ...

Regression test suite and the Buildbot

Octopus includes a large collection of regression tests Test suite covers ∼ 65% of the code Continuous integration (CI) using Buildbot Buildbot is interfaced with GitLab

Build system

Compilation and configuration is based on autotools Configure script is generated from configure.ac Makefiles are generated from Makefile.am files in each directory To generate the configure scripts run autoreconf -i VPATH builds are supported and suggested.

Coding style

Set of rules and guidelines for writing code Deals with indentation, white spaces, naming conventions, etc Makes the code easier to read and understand Ideally the code should read like plain English

Bad

i f ( s p a c e%p e r i o d i c d i m > 0 ) t h e n

... end i f

Good

i f ( s p a c e%i s p e r i o d i c ( ) ) t h e n

... end i f

Helps avoiding some errors

Octopus coding standards

https://octopus-code.org/wiki/Developers:Coding_standards

Preprocessor

Changes the source before compilation We use the C preprocessor: Standard Widely available Requires some tricks to work with Fortran code Imposes (few) limitations on Fortran code Several macros generated when running configure script Conditional compilation: #i f d e f HAVE MPI

... #e l s e ... #e n d i f

Templating to generate same subroutine with different data types (float/complex/integers, scalar/array, etc)

Preprocessor: some useful Octopus specific macros

SAFE ALLOCATE()

Calls allocate Returns error on failure Counts allocated memory for profiling PUSH SUB() / POP SUB() Generates a call stack used for debugging MAX DIM Maximum dimension the code can run Deprecated FLOAT, CMPLX Allow to change the real and complex types at compile time Was introduced to allow compilation in single precision Not really useful anymore; will likely be removed