---
title: "dispatchThreads(threadsPerGrid:threadsPerThreadgroup:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtl4computecommandencoder/dispatchthreads(threadspergrid:threadsperthreadgroup:)"
---

# dispatchThreads(threadsPerGrid:threadsPerThreadgroup:)

Encodes a compute dispatch command using an arbitrarily-sized grid.

## Declaration

```swift
func dispatchThreads(threadsPerGrid: MTLSize, threadsPerThreadgroup: MTLSize)
```

## Parameters

- `threadsPerGrid`: An doc://com.apple.metal/documentation/Metal/MTLSize instance that represents the number of threads 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(indirectBuffer:)](metal/mtl4computecommandencoder/dispatchthreads(indirectbuffer:).md)
- [dispatchThreadgroups(threadgroupsPerGrid:threadsPerThreadgroup:)](metal/mtl4computecommandencoder/dispatchthreadgroups(threadgroupspergrid:threadsperthreadgroup:).md)
- [dispatchThreadgroups(indirectBuffer:threadsPerThreadgroup:)](metal/mtl4computecommandencoder/dispatchthreadgroups(indirectbuffer:threadsperthreadgroup:).md)
