C++ Data Exchange¶
Location: example/cpp-exchange
This example is a pure C++ producer/consumer pair that exchange scalars and tensors through a radex backend. It is the simplest way to see the C++ client API in isolation.
Variants¶
dragon/— producer and consumer processes exchange data through a DragonDDict. TheDDictdescriptor is passed via theSERIALIZED_DDICTenvironment variable.in-mem/— an in-process backend, useful for exercising the client API without any external service.redis/— exchange through a SmartRedis-backed Redis instance.
Dragon Variant Walkthrough¶
producer.cpp attaches a client to the shared DDict and writes a mix of scalars and tensors:
#include "radex/client.hpp"
int main() {
std::cout << "===========================\n"
<< "Hello World from Producer!!\n"
<< "---------------------------\n";
radex::drg::ddict::Client client{};
client.put_scalar<int32_t>(radex::data::OutgoingHandle{"some-int"}, 123);
client.put_scalar<double>(radex::data::OutgoingHandle{"some-float"}, 1.23);
client.put_tensor<double>(radex::data::OutgoingHandle{"some-float-tensor"},
{4}, {0.12, 3.45, 6.78, 9.123});
client.put_tensor<int32_t>(radex::data::OutgoingHandle{"some-int-tensor"},
{2, 4}, {1, 2, 3, 4, 5, 6, 7, 8});
consumer.cpp attaches to the same DDict and reads back the values written by the producer using the matching get_scalar/get_tensor calls.
Running¶
Binaries are installed under install/bin/examples when built with BUILD_EXAMPLES=ON. See driver.py in the dragon/ variant for how a Python script can start the producer/consumer pair against a shared DDict.