HcommChannelDestroy
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
Function
Destroys a communication channel created by HcommChannelCreate, along with the system resources occupied by the communication channel, including network connections, synchronization signals, and communication queues.
This API supports batch destruction. Multiple channels can be destroyed in a single call, improving resource deallocation efficiency.
Prototype
1 | HcommResult HcommChannelDestroy(const ChannelHandle *channels, uint32_t channelNum); |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
channels |
Input |
Handle array of channels whose status is to be destroyed. Each element identifies a created communication channel. For details, see ChannelHandle. This parameter cannot be a null pointer. Each channel handle in the array must be a valid handle (not destroyed) created by HcommChannelCreate. |
channelNum |
Input |
Number of channels to be destroyed. Value range: [1, 1048576]. The value of this parameter must be greater than 0 and equal to the number of valid handles in the channels array. |
Returns
HcommResult: 0 on success; else, failure.
Restrictions
- The length of the channels array must be the same as that of the channelNum parameter.
- Channels created by different engines can be destroyed in batches.
- The destruction operation is atomic. Either all channels are successfully destroyed, or an error is returned when the first invalid handle is encountered.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | EndpointHandle endpointHandle = nullptr; //... Create endpoints (code omitted). // Create multiple channels. const uint32_t CHANNEL_NUM = 4; HcommChannelDesc channelDescs[CHANNEL_NUM] = {0}; ChannelHandle channels[CHANNEL_NUM] = {0}; // Prepare the channel descriptors and create channels. for (uint32_t i = 0; i < CHANNEL_NUM; i++) { //... Fill in channelDescs[i]. } HcommResult ret = HcommChannelCreate(endpointHandle, COMM_ENGINE_CPU, channelDescs, CHANNEL_NUM, channels); if (ret != 0) { printf("Failed to create channels, ret = %d\n", ret); HcommEndpointDestroy(endpointHandle); return ret; } printf("%u channels created successfully\n", CHANNEL_NUM); // Use channels for communication. // ... // Destroy all channels in batches. ret = HcommChannelDestroy(channels, CHANNEL_NUM); if (ret != 0) { printf("Failed to destroy channels, ret = %d\n", ret); } else { printf("All channels destroyed successfully\n"); } // Destroy endpoints. HcommEndpointDestroy(endpointHandle); |