https://github.com/ramiawar/boids-multithreaded
Golang multithreaded implementation of boids
https://github.com/ramiawar/boids-multithreaded
Last synced: 2 months ago
JSON representation
Golang multithreaded implementation of boids
- Host: GitHub
- URL: https://github.com/ramiawar/boids-multithreaded
- Owner: RamiAwar
- Created: 2022-01-17T18:15:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-22T11:12:35.000Z (over 3 years ago)
- Last Synced: 2025-03-23T18:51:51.603Z (7 months ago)
- Language: Go
- Size: 15.3 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Multithreaded Boids Simulation in Go
This is an exercise in goroutines and memory sharing with RWMutexes. Each boid updates itself on a separate goroutine, that runs every 5ms. In the run below, 1000 different goroutines are running concurrently and then the boid positions and headings are rendered once a frame.
The way neighbors are looked up here is by checking all other boids, which is very inefficient. This caps out at a maximum boid count of 1500 (90% CPU utilization reached at this point). For a better implementation, keep reading.

In the implementation below, a spatial hash grid was used to find the nearest boids. This works by hashing boids into cells in a grid, based on their position. The position vector {x, y} would be the key in this hash map, and the hashmap is updated accordingly with correct locking/unlocking. This implementation caps out at 2000 (80% CPU utilization). Pushing any further makes it lag, which might be due to memory limitations. To be explored.

## Running
```
go mod download
go run ./main
```