---
title: "dispatchThreadgroups(threadgroupsPerGrid:threadsPerThreadgroup:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtl4computecommandencoder/dispatchthreadgroups(threadgroupspergrid:threadsperthreadgroup:)"
---

# dispatchThreadgroups(threadgroupsPerGrid:threadsPerThreadgroup:)

Encodes a compute dispatch command with a grid that aligns to threadgroup boundaries.

## Declaration

```swift
func dispatchThreadgroups(threadgroupsPerGrid: MTLSize, threadsPerThreadgroup: MTLSize)
```

## Parameters

- `threadgroupsPerGrid`: An doc://com.apple.metal/documentation/Metal/MTLSize instance that represents the number of threadgroups in the grid, in each dimension.
- `threadsPerThreadgroup`: An doc://com.apple.metal/documentation/Metal/MTLSize instance that represents the number of threads in one threadgroup, in each dimension.

## See Also

### Running dispatch commands

- [dispatchThreads(threadsPerGrid:threadsPerThreadgroup:)](metal/mtl4computecommandencoder/dispatchthreads(threadspergrid:threadsperthreadgroup:).md)
- [dispatchThreads(indirectBuffer:)](metal/mtl4computecommandencoder/dispatchthreads(indirectbuffer:).md)
- [dispatchThreadgroups(indirectBuffer:threadsPerThreadgroup:)](metal/mtl4computecommandencoder/dispatchthreadgroups(indirectbuffer:threadsperthreadgroup:).md)
