Active Message Request#

2026-03-31

6 min read time

Applies to Linux

The ucxx::RequestAm class implements non-blocking active message (AM) send and receive operations. Active messages allow user-defined callbacks to be invoked on the receiver side when a message arrives, enabling RPC-style communication patterns.

#include <ucxx/request_am.h>

namespace ucxx

class RequestAm : public ucxx::Request#

Send or receive a message with the UCX Active Message API.

Send or receive a message with the UCX Active Message API, using non-blocking UCP calls ucp_am_send_nbx or ucp_am_recv_data_nbx.

Public Functions

virtual void cancel(
) override#

Cancel the request.

Cancel the request. Often called by the error handler or parent’s object destructor but may be called by the user to cancel the request as well.

virtual void populateDelayedSubmission(
) override#

Populate the internal submission dispatcher.

The ucxx::Request utilizes ucxx::DelayedSubmission to manage when the request will be dispatched. This method is registered as a callback in the worker, that may choose to either execute (submit) it immediately or delay for the next iteration of its progress loop, depending on the progress mode in use by the worker.

See ucxx::DelayedSubmission::DelayedSubmission() for more details.

void request(
)#

Create and submit an active message send request.

This is the method that should be called to actually submit an active message send request. It is meant to be called from populateDelayedSubmission(), which is decided at the discretion of std::shared_ptr<ucxx::Worker>. See populateDelayedSubmission() for more details.

virtual std::shared_ptr<Buffer> getRecvBuffer(
) override#

Get the received buffer.

This method is used to get the received buffer for applicable derived classes (e.g., RequestAm receive operations), in all other cases this will return nullptr. Before getting the received buffer it’s necessary to check that the request completed successfully either by validating getStatus() == UCS_OK or by checking the request completed with isCompleted() == true and that it did not error with checkError(), if any of those is unsuccessful this call returns nullptr.

Returns:

The received buffer (if applicable) or nullptr.

Public Static Functions

static ucs_status_t recvCallback(
void *arg,
const void *header,
size_t header_length,
void *data,
size_t length,
const ucp_am_recv_param_t *param
)#

Receive callback registered by ucxx::Worker.

This is the receive callback registered by the ucxx::Worker to handle incoming active messages. For each incoming active message, a proper buffer will be allocated based on the header sent by the remote endpoint using the default allocator or one registered by the user via ucxx::Worker::registerAmAllocator(). Following that, the message is immediately received onto the buffer and a UCS_OK or the proper error status is set onto the RequestAm that is returned to the user, or will be later handled by another callback when the message is ready. If the callback is executed when a user has already requested received of the active message, the buffer and status will be set on the earliest request, otherwise a new request is created and saved in a pool that will be already populated and ready for consumption or waiting for the internal callback when requested.

This is always called by ucp_worker_progress(), and thus will happen in the same thread that is called from, when using the worker progress thread, this is called from the progress thread.

param[in,out] arg pointer to the AmData object held by the ucxx::Worker who registered this callback. param[in] header pointer to the header containing the sender buffer’s memory type. param[in] header_length length in bytes of the receive header. param[in] data pointer to the buffer containing the remote endpoint’s send data. param[in] length the length in bytes of the message to be received. param[in] param UCP parameters of the active message being received.

Friends

friend std::shared_ptr<RequestAm> createRequestAm(
std::shared_ptr<Endpoint> endpoint,
const std::variant<data::AmSend, data::AmReceive> requestData,
const bool enablePythonFuture,
RequestCallbackUserFunction callbackFunction,
RequestCallbackUserData callbackData
)#

Constructor for std::shared_ptr<ucxx::RequestAm>.

The constructor for a std::shared_ptr<ucxx::RequestAm> object, creating an active message request, returning a pointer to a request object that can be later awaited and checked for errors. This is a non-blocking operation, and the status of the transfer must be verified from the resulting request object before the data can be released if this is a send operation, or consumed if this is a receive operation. Received data is available via the getRecvBuffer() method if the receive transfer request completed successfully.

Note

If a callbackFunction is specified, the lifetime of callbackData and of any other objects used in the scope of callbackFunction must be guaranteed by the caller until it executes or isCompleted() becomes true. The callbackFunction executes in the thread progressing the ucxx::Worker, unless the request completes immediately, in which case the callback will also execute immediately within the calling thread and before the method returns.

Throws:

ucxx::Error – if endpoint is not a valid std::shared_ptr<ucxx::Endpoint>.

Parameters:
  • endpoint[in] the parent endpoint.

  • requestData[in] container of the specified message type, including all type-specific data.

  • enablePythonFuture[in] whether a python future should be created and subsequently notified.

  • callbackFunction[in] user-defined callback function to call upon completion.

  • callbackData[in] user-defined data to pass to the callbackFunction.

Returns:

The shared_ptr<ucxx::RequestAm> object

Factory Functions#

#include <ucxx/constructors.h>

std::shared_ptr<RequestAm> ucxx::createRequestAm(
std::shared_ptr<Endpoint> endpoint,
const std::variant<data::AmSend, data::AmReceive> requestData,
const bool enablePythonFuture,
RequestCallbackUserFunction callbackFunction,
RequestCallbackUserData callbackData
)#

The constructor for a std::shared_ptr<ucxx::RequestAm> object, creating an active message request, returning a pointer to a request object that can be later awaited and checked for errors. This is a non-blocking operation, and the status of the transfer must be verified from the resulting request object before the data can be released if this is a send operation, or consumed if this is a receive operation. Received data is available via the getRecvBuffer() method if the receive transfer request completed successfully.

Note

If a callbackFunction is specified, the lifetime of callbackData and of any other objects used in the scope of callbackFunction must be guaranteed by the caller until it executes or isCompleted() becomes true. The callbackFunction executes in the thread progressing the ucxx::Worker, unless the request completes immediately, in which case the callback will also execute immediately within the calling thread and before the method returns.

Throws:

ucxx::Error – if endpoint is not a valid std::shared_ptr<ucxx::Endpoint>.

Parameters:
  • endpoint[in] the parent endpoint.

  • requestData[in] container of the specified message type, including all type-specific data.

  • enablePythonFuture[in] whether a python future should be created and subsequently notified.

  • callbackFunction[in] user-defined callback function to call upon completion.

  • callbackData[in] user-defined data to pass to the callbackFunction.

Returns:

The shared_ptr<ucxx::RequestAm> object