---
title: BlasSetNumThreads
description: "支持运行时设置线程数。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0194.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0194.html
indexId: a7f9c0126c950ce6276fb82bc0be5ecca42c4f28297d8c87eea767c7b8673ed874
---
# BlasSetNumThreads

支持运行时设置线程数。

#### 接口定义

void BlasSetNumThreads(int numThreads)


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| numThreads | 整型数 | 设置的线程数，要求numThreads>0。 | 输入 |


#### 依赖

#include "kblas.h"


#### 示例

```
BlasSetNumThreads(4); // 设置运行线程数为4
```

支持通过设置环境变量设置线程数，如下所示：

export BLAS_NUM_THREADS=4

export OMP_NUM_TRHREADS=4

单独使用时，均可以设置运行线程数为4。当两个环境变量同时存在时，BLAS_NUM_THREADS的优先级更高。
