---
title: "subgroupElect: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점"
description: "선출은 서브그룹에서 정확히 레인 하나, 활성 레인 가운데 id가 가장 작은 레인에서만 true이고 나머지는 false입니다. fold 결과의 atomicAdd 하나처럼, 서브그룹이 공유하는 일을 레인 하나가 맡게 할 때 씁니다."
url: https://typeshade.dev/ko/reference/functions/subgroupElect/
language: ko
---

# `subgroupElect`

함수

선출은 서브그룹에서 정확히 레인 하나, 활성 레인 가운데 id가 가장 작은 레인에서만 true이고 나머지는 false입니다.

## 예제 비교

픽스처에서는 레인 0이 선출됩니다. 레인 하나에서는 선출이 항상 true입니다.

**모델의 전제**`subgroup of 4 lanes; x = [3, 1, 4, 1]; p = [true, false, true, true]`

**예제 1`subgroupElect()`**

**결과**

`[true, false, false, false] by lane`

**예제 2`subgroupElect()`**

**결과**

`one lane (WebGL2, CPU oracle): true`

예제는 설명용 계산 모델이며 GPU를 실행하지 않습니다. 정확한 호출 형식은 아래 컴파일러 참고 자료에서 설명합니다. 소수 결과는 표시할 때 반올림했습니다. 각 예제는 명시한 전제를 따릅니다. 실제 셰이더의 결과는 대상 언어의 정밀도와 실행 규칙에 따릅니다.

## 활용

fold 결과의 `atomicAdd` 하나처럼, 서브그룹이 공유하는 일을 레인 하나가 맡게 할 때 씁니다.

## 입력 범위와 주의사항

모든 레인이 함께 도착해야 합니다. 어느 레인이 선출되는지는 어느 레인이 활성인지에 따릅니다.

셰이더의 입력 규칙과 정밀도는 [WGSL](https://www.w3.org/TR/WGSL/)과 [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf)에서 규정합니다.

## 관련 함수

- [`subgroupAdd`](https://typeshade.dev/ko/reference/functions/subgroupAdd/)
- [`subgroupBallot`](https://typeshade.dev/ko/reference/functions/subgroupBallot/)
- [`subgroupBroadcast`](https://typeshade.dev/ko/reference/functions/subgroupBroadcast/)
- [`subgroupShuffle`](https://typeshade.dev/ko/reference/functions/subgroupShuffle/)

시그니처와 이름 아래 문장, 컴파일러 메시지는 커밋 af54ddad5의 컴파일러가 쓴 영어 원문입니다.

Returns true in the lowest active lane of the subgroup and false in every other.

## 구문

```ts
declare function subgroupElect(): bool
```

## 반환값

`bool`

## 설명

On the CPU oracle and on WebGL2 a subgroup is one invocation ([Rule 11.21](https://typeshade.dev/ko/reference/rules/11-21/)), so it gives the lane's own value.

## 대상별 출력

**WGSL**

`subgroupElect()`

**GLSL ES 3.00**

`subgroupElect` is lowered to one lane before the GLSL writer runs (Rule 11.21)

## 예제

- [`gallery/subgroup-reduce/subgroup-reduce.shade.ts`](https://typeshade.dev/ko/guide/examples/subgroup-reduce/)

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
- [내장 함수 표](https://typeshade.dev/ko/guide/language/builtins/#subgroups)
