---
title: 示例代码
description: "HCCL提供了不同场景下使用通信库API实现集合通信功能的代码示例，开发者可根据实际需求选择参考。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/hcclug/hcclug_000011.html
sourcePath: /source/zh/canncommercial/900/API/hcclug/hcclug_000011.html
indexId: d107c1be4acb4a713a3d0502e38ea95832d415320f9804d14ab9216d037f74c459
---
# 示例代码

HCCL提供了不同场景下使用通信库API实现集合通信功能的代码示例，开发者可根据实际需求选择参考。

#### 通信域管理

-   每个进程管理一个NPU设备（基于root节点信息初始化通信域）(https://gitcode.com/cann/hcomm/tree/master/examples/01_communicators/01_one_device_per_process/)

-   每个进程管理一个NPU设备（基于rank table初始化通信域）(https://gitcode.com/cann/hcomm/tree/master/examples/01_communicators/02_one_device_per_process_rank_table/)

-   每个线程管理一个NPU设备(https://gitcode.com/cann/hcomm/tree/master/examples/01_communicators/03_one_device_per_pthread/)


#### 点对点通信

-   HcclSend/HcclRecv（基础收发功能）(https://gitcode.com/cann/hccl/tree/master/examples/01_point_to_point/01_send_recv/)

-   HcclBatchSendRecv（实现Ring环状通信）(https://gitcode.com/cann/hccl/tree/master/examples/01_point_to_point/02_batch_send_recv_ring)


#### 集合通信

-   AllReduce(https://gitcode.com/cann/hccl/tree/master/examples/02_collectives/01_allreduce)

-   Broadcast(https://gitcode.com/cann/hccl/tree/master/examples/02_collectives/02_broadcast)

-   AllGather(https://gitcode.com/cann/hccl/tree/master/examples/02_collectives/03_allgather)

-   ReduceScatter(https://gitcode.com/cann/hccl/tree/master/examples/02_collectives/04_reduce_scatter)

-   Reduce(https://gitcode.com/cann/hccl/tree/master/examples/02_collectives/05_reduce)

-   AlltoAll(https://gitcode.com/cann/hccl/tree/master/examples/02_collectives/06_alltoall)

-   AlltoAllV(https://gitcode.com/cann/hccl/tree/master/examples/02_collectives/07_alltoallv)

-   AlltoAllVC(https://gitcode.com/cann/hccl/tree/master/examples/02_collectives/08_alltoallvc)

-   Scatter(https://gitcode.com/cann/hccl/tree/master/examples/02_collectives/09_scatter)
