---
title: "subgroupElect: shader function examples and input limits"
description: "An election is true in exactly one lane of the subgroup, the active lane with the lowest id, and false in the others."
url: https://typeshade.dev/reference/functions/subgroupElect/
language: en
---

# `subgroupElect`

Function

An election is true in exactly one lane of the subgroup, the active lane with the lowest id, and false in the others.

## Compare examples

Lane 0 is elected in the fixture. On one lane the election is always true.

**Model assumptions**`subgroup of 4 lanes; x = [3, 1, 4, 1]; p = [true, false, true, true]`

**Example 1`subgroupElect()`**

**Result**

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

**Example 2`subgroupElect()`**

**Result**

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

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it to let one lane do a subgroup's shared work, such as one `atomicAdd` of a fold.

## Inputs and limits

Every lane must reach the call together. Which lane is elected depends on which lanes are active.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

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

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

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

## Syntax

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

## Return value

`bool`

## Description

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

## Targets

**WGSL**

`subgroupElect()`

**GLSL ES 3.00**

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

## Examples

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

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#subgroups)
