Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Summer of Code 2016 Final Submission

Google Summer of Code 2016 Final Project Submission

Project - Plugin mechanism for thread schedulers in HPX

Mentor - Hartmut Kaiser

Schedulers in HPX were statically linked and had to be specified when HPX was built. This project aims to make these dynamically loaded instead. Schedulers can be added as plugins. This has several benefits. It provides a layer of abstraction and follows the open/closed principle of software design (software entities should be open to extension but closed to modification). It also allows developers to use their own custom schedulers if they wish to, while conforming to a uniform API (provided by scheduler_base).
This task is accomplished in two phases -

  1. Generation of the plugin modules (.so files) which are recognized and registered by HPX
  2. Loading of the plugin modules, for subsequent use

List of commits on the scheduler_plugin branch used for the purpose of this project.

A brief description of the commits is provided below.

Phase 1

The first phase involves the creation of the plugin modules which will be loaded by HPX in the second phase. At first, I worked on a sample standalone plugin for schedulers to get an idea of the process. This work was done taking guidance from a sample HPX plugin, implemented by my mentor. The default scheduler used by HPX is local priority queue scheduler. Everything I have implemented, I have done using this scheduler. After I got the code for the default scheduler to work, making the appropriate changes for the other schedulers was trivial.

Commit 1, Commit 2, Commit 3

Implement the plugin module for local priority queue scheduler

Commit 4

Extend same functionality to local queue scheduler

Commit 5

Extend same functionality to static queue scheduler and static priority queue scheduler

Commit 6

Extend same functionality to periodic priority queue scheduler and hierarchy scheduler

Commit 7

Final touches for help in scheduler plugin registration

Phase 2

The second phase involves the dynamic loading of scheduler-plugins, using the mechanism already present in HPX (which is used for components, binary filters, message handlers etc.).

Commit 1, Commit 2

Add the function which creates and returns an instance of specified scheduler plugin

Commit 3, Commit 4, Commit 5

Added interim classes for runtime_impl, threadmanager and thread_pool to be used with the newly created function

Commit 6

Modify existing code to use the newly added functionality

Commit 7

Added basic documentation, to be improved on, this week

Community Bonding Experience

Google Summer of Code was a great learning experience, due to a variety of factors like a good project, good mentor and great community. What I liked most was the community. Not only my mentor, but everyone is willing to lend a hand if you are stuck. During these three months, I did not feel any need to mail or converse privately with my mentor. All communication happened on the public IRC channel and involved the whole community. All this made me more eager to complete my work and become involved with other projects of STE||AR Group. Apart from this project, I had liked quite a few other ones too on their Project Ideas page, and I want to continue to contribute, both to HPX and some other libraries like libgeodecomp.

Further work

  1. The documentation is currently very basic. I will be working on making it more detailed and user-friendly.
  2. The scheduler_base class, which provides the blueprint for writing custom schedulers, will be made fully virtual, to extend more freedom to developers while developing their own schedulers.

How to write your own scheduler

Apart from the inbuilt ones, HPX also provides developers the freedom to write their own custom schedulers following a specific blueprint. First implement your own scheduler (similar to this) by extending class scheduler_base. Write the plugin factory, similar to this and register it, like this. There are two repositories which illustrate the entire process of creating plugins for HPX, this and this. The former one is a generic example of how to create plugin modules using factories and the latter uses the same principle for creating scheduler plugin modules, which was used initially by me to get the scheduler plugins to work as a standalone unit before integrating them with HPX.
You can use the plugin module for your custom scheduler by getting an instance from hpx::create_scheduler() using the appropriate plugin name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment