Margo JSON configuration in Thallium

Just like Margo can take a JSON configuration describing and Argobots and a Mercury environment, a Thallium engine can be initialized with the same kind of JSON configuration, as shown in the code bellow.

#include <iostream>
#include <thallium.hpp>

namespace tl = thallium;

int main(int argc, char** argv) {

    const char* config = R"(
    {
      "argobots": {
        "pools": [
          {
            "name": "__primary__",
            "kind": "fifo_wait",
            "access": "mpmc"
          },
          {
            "name": "my_pool",
            "kind": "prio_wait",
            "access": "mpmc"
          },
          {
            "name": "my_other_pool",
            "kind": "fifo",
            "access": "mpmc"
          }
        ],
        "xstreams": [
          {
            "name": "__primary__",
            "scheduler": {
              "type": "basic_wait",
              "pools": [0]
            }
          },
          {
            "name": "my_es",
            "scheduler": {
              "type": "basic_wait",
              "pools": ["my_pool", 2]
            }
          }
        ]
      }
    }
    )";

    tl::engine myEngine("tcp", THALLIUM_SERVER_MODE, config);

    std::cout << myEngine.get_config() << std::endl;
    std::cout << "--------------------------------" << std::endl;
    std::cout << myEngine.pools().size() << " pools, ";
    std::cout << myEngine.xstreams().size() << " xstreams" << std::endl;
    std::cout << "--------------------------------" << std::endl;

    tl::pool myPool = myEngine.pools()["my_pool"];
    tl::pool myOtherPool = myEngine.pools()[2];
    std::cout << myEngine.pools()[1].name() << std::endl;

    tl::xstream myES = myEngine.xstreams()["my_es"];
    tl::xstream primaryES = myEngine.xstreams()[0];
    std::cout << myEngine.xstreams()[1].name() << std::endl;

    myEngine.finalize();

    return 0;
}

Once initialized this way, one can access the pools and execution streams defined in the configurations via the engine::pools() and engine::xstreams() methods, respectively. These methods return a proxy objects that allows to access pools and xstreams by name or index. The returned objects are also proxies, allowing to access the name and index of the pool/xstream (tl::pool and tl::xstream objects don’t naturally have such attributes).

These functionalities can be useful to externalize the Argobots and Mercury setup into a configuration file instead of hard-coding the creation and management of pools and execution streams.