Skip to content

Use procedure pointers to support callbacks more robustly

Alberto Garcia requested to merge garalb/siesta:master-handlers into master

As discovered when using shared libraries in the CMake build process, the callbacks (e.g. psml_die) pose problems, not only for external libraries but for internal ones as well. Besides, the handling routines for the callback events were hard to manage, particularly for the utilities.

A new lightweight library "libsys" has been created to provide a thin layer of handlers-as-procedure-pointers, which by default point to simple handlers appropriate for most programs, but that can be redefined by larger programs (see siesta_handlers_m.F90, tbt_handlers_m.F90, unfold_handlers_m.F90, etc) to provide the needed functionality.

Currently libsys contains just "die, message, and bye", the most common event handlers. The psml and libgridxc external libraries have been updated (currently in side branches) to offer also handlers based on procedure pointers. See siesta_handlers_m.F90 for an example of the use of the interface. The submodule references in External have been updated accordingly.

It can be argued that timing events are in the same class. In fact, mpi_siesta now offers a 'timer_mpi' procedure pointer, for exactly the same reasons. For backward compatibility, and for added flexibility, 'external' versions of the handlers are also present in libsys (see 'external_entries.f90').

To do:

  • Integrate the changes to create an 'i8b' allocation event handler, as discussed in !80.
  • Further refactoring (but probably better left for later, as we gather more experience).
  • Fix most utility makefiles to adapt to LIBSYS. (This can more easily be done after the merge of !30 (merged), as the changes are similar). Perhaps it is not worth it... I have put a sentence in INSTALL further discouraging the use of the makefile build system, and a message appears when trying to do 'make utils'.

Merge request reports