---
title: "Subgroup reduction before an atomic in TypeShade"
description: "Subgroup reduction before an atomic, a TypeShade example. subgroupAdd folds each subgroup's values in one instruction and subgroupElect picks one lane to add…"
url: https://typeshade.dev/guide/examples/subgroup-reduce/
language: en
---

# Subgroup reduction before an atomic

`subgroupAdd` folds each subgroup's values in one instruction and `subgroupElect` picks one lane to add the fold into the bin with `atomicAdd`.

**subgroup-reduce.shade.ts**

`TS`

Diagnostics Ready to compile

Loading the program…

Compile a module with a vertex entry and a fragment entry to see it drawn.

The editor holds this example's own file, and the program is that file and any file it imports. An edit recompiles it in your browser, and the tabs beside the editor follow.

[File on GitHub](https://github.com/typeshade/typeshade/blob/af54ddad5/examples/gallery/subgroup-reduce/subgroup-reduce.shade.ts)
